Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix display of orphan method instruments #2392

Merged
merged 3 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.5.0 (unreleased)
------------------

- #2392 Fix display of orphan method instruments
- #2388 Fix QC sample IDs are the same accross worksheets
- #2387 Improve memory usage when rebuilding a catalog
- #2389 Added i18n.translate function with multiple domains support
Expand Down
24 changes: 19 additions & 5 deletions src/bika/lims/content/method.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
from bika.lims import bikaMessageFactory as _
from bika.lims.browser.fields import UIDReferenceField
from bika.lims.browser.fields.uidreferencefield import get_backreferences
from senaite.core.browser.widgets.referencewidget import ReferenceWidget
from bika.lims.catalog import SETUP_CATALOG
from bika.lims.config import PROJECTNAME
from bika.lims.content.bikaschema import BikaSchema
Expand All @@ -43,6 +42,7 @@
from Products.Archetypes.public import registerType
from Products.Archetypes.utils import DisplayList
from Products.Archetypes.Widget import RichWidget
from senaite.core.browser.widgets.referencewidget import ReferenceWidget
from zope.interface import implements

schema = BikaSchema.copy() + Schema((
Expand Down Expand Up @@ -180,14 +180,28 @@ def _renameAfterCreation(self, check_auto_id=False):
def getInstruments(self):
"""Instruments capable to perform this method
"""
uc = api.get_tool("uid_catalog")
uids = self.getRawInstruments()
return [api.get_object(brain) for brain in uc(UID=uids)]
instruments = map(api.get_object, self.getRawInstruments())
return list(instruments)

def getRawInstruments(self):
"""List of Instrument UIDs capable to perform this method
"""
return get_backreferences(self, "InstrumentMethods")
backrefs = get_backreferences(self, "InstrumentMethods")
# XXX: The backrefs might contain UIDs of deactivated instruments,
# which will show up in the UI as just their UID.
active_instrument_uids = filter(
lambda uid: api.get_review_status(uid) == "active", backrefs)
# TODO: Actually, this should to be corrected in a transition event
# for instruments to remove the backreference of each method
# with a reference to the specific instrument.
#
# However, this would happen silently and the user would not be
# notified about this "side-effect".
#
# Therefore, we leave the linked object in the backrefs, but
# filter it out for now, until we have a better approach how to
# handle this with user notification!
return active_instrument_uids

def setInstruments(self, value):
"""Set the method on the selected instruments
Expand Down