Skip to content

Commit 95472cd

Browse files
ramonskixispa
andauthored
Allow to enable/disable analysis categories for samples (#2140)
* Added senaite setup schema field * Added proxy for bika setup * Enable/Disable analyses categories for samples * Changelog updated * spelling * Do not automatically expand on every update * Check if the context is a sample Co-authored-by: Jordi Puiggené <[email protected]>
1 parent 5c04635 commit 95472cd

File tree

4 files changed

+67
-0
lines changed

4 files changed

+67
-0
lines changed

CHANGES.rst

+1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
2.3.0 (unreleased)
66
------------------
77

8+
- #2140 Allow to enable/disable analysis categories for samples
89
- #2137 Dynamic Workflow Menu
910
- #2139 Fix LabClerk cannot create partitions from received samples
1011
- #2130 Catalog mapping for Samples and Analyses

src/bika/lims/browser/analyses/view.py

+13
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ def __init__(self, context, request, **kwargs):
102102
self.dmk = context.bika_setup.getResultsDecimalMark()
103103
self.scinot = context.bika_setup.getScientificNotationResults()
104104
self.categories = []
105+
self.expand_all_categories = True
105106

106107
# each editable item needs it's own allow_edit
107108
# which is a list of field names.
@@ -239,6 +240,8 @@ def update(self):
239240
super(AnalysesView, self).update()
240241
self.load_analysis_categories()
241242
self.append_partition_filters()
243+
if self.analysis_categories_enabled():
244+
self.show_categories = True
242245

243246
def before_render(self):
244247
"""Before render hook
@@ -269,6 +272,16 @@ def analysis_remarks_enabled(self):
269272
"""
270273
return self.context.bika_setup.getEnableAnalysisRemarks()
271274

275+
@viewcache.memoize
276+
def analysis_categories_enabled(self):
277+
"""Check if analyses should be grouped by category
278+
"""
279+
# setting applies only for samples
280+
if not IAnalysisRequest.providedBy(self.context):
281+
return False
282+
setup = api.get_senaite_setup()
283+
return setup.getCategorizeSampleAnalyses()
284+
272285
@viewcache.memoize
273286
def has_permission(self, permission, obj=None):
274287
"""Returns if the current user has rights for the permission passed in

src/bika/lims/content/bikasetup.py

+28
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,17 @@ def getCounterTypes(self, instance=None):
313313
description=_("Group analysis services by category in the LIMS tables, helpful when the list is long")
314314
),
315315
),
316+
BooleanField(
317+
"CategorizeSampleAnalyses",
318+
schemata="Analyses",
319+
default=False,
320+
widget=BooleanWidget(
321+
label=_("label_bikasetup_categorizesampleanalyses",
322+
default="Categorize sample analyses"),
323+
description=_("description_bikasetup_categorizesampleanalyses",
324+
"Group analyses by category for samples")
325+
),
326+
),
316327
BooleanField(
317328
'EnableARSpecs',
318329
schemata="Analyses",
@@ -1065,5 +1076,22 @@ def setImmediateResultsEntry(self, value):
10651076
if setup:
10661077
setup.setImmediateResultsEntry(value)
10671078

1079+
def getCategorizeSampleAnalyses(self):
1080+
"""Get the value from the senaite setup
1081+
"""
1082+
setup = api.get_senaite_setup()
1083+
# setup is `None` during initial site content structure installation
1084+
if setup:
1085+
return setup.getCategorizeSampleAnalyses()
1086+
return False
1087+
1088+
def setCategorizeSampleAnalyses(self, value):
1089+
"""Set the value in the senaite setup
1090+
"""
1091+
setup = api.get_senaite_setup()
1092+
# setup is `None` during initial site content structure installation
1093+
if setup:
1094+
setup.setCategorizeSampleAnalyses(value)
1095+
10681096

10691097
registerType(BikaSetup, PROJECTNAME)

src/senaite/core/content/senaitesetup.py

+25
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,16 @@ class ISetupSchema(model.Schema):
8888
),
8989
)
9090

91+
categorize_sample_analyses = schema.Bool(
92+
title=_("title_senaitesetup_categorizesampleanalyses",
93+
default=u"Categorize sample analyses"),
94+
description=_(
95+
"description_senaitesetup_categorizesampleanalyses",
96+
default=u"Group analyses by category for samples"
97+
),
98+
default=False,
99+
)
100+
91101
###
92102
# Fieldsets
93103
###
@@ -96,6 +106,7 @@ class ISetupSchema(model.Schema):
96106
label=_("label_senaitesetup_fieldset_analyses", default=u"Analyses"),
97107
fields=[
98108
"immediate_results_entry",
109+
"categorize_sample_analyses",
99110
]
100111
)
101112

@@ -203,3 +214,17 @@ def setImmediateResultsEntry(self, value):
203214
"""
204215
mutator = self.mutator("immediate_results_entry")
205216
return mutator(self, value)
217+
218+
@security.protected(permissions.View)
219+
def getCategorizeSampleAnalyses(self):
220+
"""Returns if analyses should be grouped by category for samples
221+
"""
222+
accessor = self.accessor("categorize_sample_analyses")
223+
return accessor(self)
224+
225+
@security.protected(permissions.ModifyPortalContent)
226+
def setCategorizeSampleAnalyses(self, value):
227+
"""Enable/Disable grouping of analyses by category for samples
228+
"""
229+
mutator = self.mutator("categorize_sample_analyses")
230+
return mutator(self, value)

0 commit comments

Comments
 (0)