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 analyses from partitions are considered in manage analyses view #2598

Draft
wants to merge 11 commits into
base: 2.x
Choose a base branch
from
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.6.0 (unreleased)
------------------

- #2598 Fix analyses from partitions are considered in manage analyses view
- #2661 Allow to recalculate an analysis result
- #2659 Refactor sample title + decsription into viewlets
- #2660 Add logging if external calculation module import failed
Expand Down
2 changes: 1 addition & 1 deletion src/bika/lims/browser/analysisrequest/manage_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ def update(self):
"""Update hook
"""
super(AnalysisRequestAnalysesView, self).update()
analyses = self.context.getAnalyses(full_objects=True)
analyses = self.context.objectValues("Analysis")
self.analyses = dict([(a.getServiceUID(), a) for a in analyses])

@view.memoize
Expand Down
9 changes: 0 additions & 9 deletions src/senaite/core/datamanagers/field/sample_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def set(self, items, prices, specs, hidden, **kw):

# Get all analyses (those from descendants included)
analyses = self.context.objectValues("Analysis")
analyses.extend(self.get_analyses_from_descendants(self.context))

# Bail out those not in services list or submitted
uids = map(api.get_uid, services)
Expand Down Expand Up @@ -328,14 +327,6 @@ def resolve_analyses(self, instance, service):

return analyses

def get_analyses_from_descendants(self, instance):
"""Returns all the analyses from descendants
"""
analyses = []
for descendant in instance.getDescendants(all_descendants=True):
analyses.extend(descendant.objectValues("Analysis"))
return analyses

def get_from_instance(self, instance, service):
"""Returns analyses for the given service from the instance
"""
Expand Down
25 changes: 9 additions & 16 deletions src/senaite/core/tests/doctests/ARAnalysesFieldWithPartitions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -204,17 +204,6 @@ But returns None if I ask to the partition:
>>> dm.get_from_descendant(partition, Cu)
[]

get_analyses_from_descendants
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

It returns the analyses contained by the descendants:

>>> dm.get_analyses_from_descendants(sample)
[<Analysis at /plone/clients/client-1/W-0001-P01/Cu>]

>>> dm.get_analyses_from_descendants(partition)
[]


Resolution of analyses from the Sample lineage
..............................................
Expand Down Expand Up @@ -332,18 +321,22 @@ the partition:
>>> partition.objectValues("Analysis")
[<Analysis at /plone/clients/client-1/W-0001-P01/Cu>, <Analysis at /plone/clients/client-1/W-0001-P01/Fe>, <Analysis at /plone/clients/client-1/W-0001-P01/Au>, <Analysis at /plone/clients/client-1/W-0001-P01/Mg>]

To remove `Mg` analysis, pass the list without `Mg`:
Nothing happens if we try to remove `Mg` analysis from the sample, cause it
belongs to the partition:

>>> field.set(sample, [Cu, Fe, Au])

The analysis `Mg` has been removed, although it belonged to the partition:

>>> sample.objectValues("Analysis")
[]
>>> partition.objectValues("Analysis")
[<Analysis at /plone/clients/client-1/W-0001-P01/Cu>, <Analysis at /plone/clients/client-1/W-0001-P01/Fe>, <Analysis at /plone/clients/client-1/W-0001-P01/Au>, <Analysis at /plone/clients/client-1/W-0001-P01/Mg>]

We have explicitly remove the analysis from the partition instead:

>>> field.set(partition, [Cu, Fe, Au])
>>> partition.objectValues("Analysis")
[<Analysis at /plone/clients/client-1/W-0001-P01/Cu>, <Analysis at /plone/clients/client-1/W-0001-P01/Fe>, <Analysis at /plone/clients/client-1/W-0001-P01/Au>]

But if I add a new analysis to the primary and I try to remove it from the
If I add a new analysis to the primary and I try to remove it from the
partition, nothing will happen:

>>> field.set(sample, [Cu, Fe, Au, Mg])
Expand Down