Skip to content

Commit

Permalink
Fix display of orphan method instruments (#2392)
Browse files Browse the repository at this point in the history
* Fix display of orphan method instruments

* Changelog updated
  • Loading branch information
ramonski authored Sep 26, 2023
1 parent 68363e6 commit 315edf6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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

0 comments on commit 315edf6

Please sign in to comment.