From e6f8e1f777a75ac33d8380dcbea2226950af39c3 Mon Sep 17 00:00:00 2001 From: Mike Metcalfe Date: Fri, 6 Dec 2024 11:56:40 +0200 Subject: [PATCH] Fixed #LIMS-1209 - Ensure the overriden folderitems set the categories as a sideaffect --- .../browser/overrides/analysisrequest.py | 9 +++++++-- .../browser/overrides/sampleanalyses.py | 6 +++--- src/senaite/timeseries/browser/results.py | 15 ++++++++++++--- 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/src/senaite/timeseries/browser/overrides/analysisrequest.py b/src/senaite/timeseries/browser/overrides/analysisrequest.py index e35022d..81ccd11 100644 --- a/src/senaite/timeseries/browser/overrides/analysisrequest.py +++ b/src/senaite/timeseries/browser/overrides/analysisrequest.py @@ -122,12 +122,17 @@ def folderitems(self): # Note we call AnalysesView's base class! items = super(AnalysesView, self).folderitems() newitems = [] + cats = [] for item in items: - if not item.get("time_series_columns"): + if item.get("result_type") != "timeseries": newitems.append(item) + cats.append(item["category"]) logger.info( - "AnalysisRequestOverride::folderitems: found {} items".format(len(newitems)) + "AnalysisRequestOverride::folderitems: found {} items with no timeseries items".format( + len(newitems) + ) ) + self.categories = cats return newitems diff --git a/src/senaite/timeseries/browser/overrides/sampleanalyses.py b/src/senaite/timeseries/browser/overrides/sampleanalyses.py index 6421cac..438c7bb 100644 --- a/src/senaite/timeseries/browser/overrides/sampleanalyses.py +++ b/src/senaite/timeseries/browser/overrides/sampleanalyses.py @@ -7,9 +7,9 @@ class LabAnalysesViewlet(LAV): def available(self): """Returns a boolean if the len(sample analyses) by point of capture - is equal to len(timeseries_analyses), meaning there are only - timeseries analyses. + is equal to len(timeseries_analyses), meaning there are only + timeseries analyses. """ analyses = self.sample.getAnalyses(getPointOfCapture=self.capture) timeseries_analyses = get_timeseries_analyses(self.sample) - return len(analyses) != len(timeseries_analyses) + return len(analyses) - len(timeseries_analyses) > 0 diff --git a/src/senaite/timeseries/browser/results.py b/src/senaite/timeseries/browser/results.py index f94f8e7..5d8f082 100644 --- a/src/senaite/timeseries/browser/results.py +++ b/src/senaite/timeseries/browser/results.py @@ -20,10 +20,11 @@ from bika.lims import api from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile +from senaite.core import logger +from senaite.core.browser.viewlets.sampleanalyses import LabAnalysesViewlet from senaite.timeseries.config import is_installed from senaite.timeseries.config import _ from senaite.timeseries.browser.overrides.analysisrequest import AnalysesView -from senaite.core.browser.viewlets.sampleanalyses import LabAnalysesViewlet class TimeSeriesAnalysesViewlet(LabAnalysesViewlet): @@ -98,9 +99,17 @@ def folderitems(self): # Note we call AnalysesView's base class! items = super(AnalysesView, self).folderitems() newitems = [] + cats = [] for item in items: - if item.get("time_series_columns"): + if item.get("result_type") == "timeseries": newitems.append(item) + cats.append(item["category"]) + logger.info( + "AnalysisRequestOverride::folderitems: found {} items with timeseries items".format( + len(newitems) + ) + ) + self.categories = cats return newitems @@ -118,5 +127,5 @@ def get_timeseries_analyses(sample, short_title=None, skip_invalid=True): # Skip invalid analyses skip = skip_invalid and ["cancelled", "retracted", "rejected"] or [] analyses = filter(lambda a: api.get_review_status(a) not in skip, analyses) - analyses = filter(lambda a: a.TimeSeriesColumns, analyses) + analyses = filter(lambda a: a.getResultType() == "timeseries", analyses) return analyses