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

Allow to define the sorting criteria for Result Options #2343

Merged
merged 5 commits into from
Jun 25, 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)
------------------

- #2343 Allow to define the sorting criteria for Result Options
- #2345 Retrieve setup items by object
- #2344 Fix error on sample copy when fields are hidden
- #2334 Remove legacy reports
Expand Down
16 changes: 13 additions & 3 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -967,10 +967,8 @@ def _folder_item_result(self, analysis_brain, item):
item["Result"] = "{} {}".format(operand, result).strip()

# Prepare result options
choices = obj.getResultOptions()
choices = self.get_result_options(obj)
if choices:
# N.B.we copy here the list to avoid persistent changes
choices = copy(choices)
choices_type = obj.getResultOptionsType()
if choices_type == "select":
# By default set empty as the default selected choice
Expand All @@ -994,6 +992,18 @@ def _folder_item_result(self, analysis_brain, item):
sciformat=int(self.scinot), decimalmark=self.dmk)
item["formatted_result"] = formatted_result

def get_result_options(self, analysis):
"""Returns the result options of the analysis to be rendered or empty
"""
options = copy(analysis.getResultOptions())
sort_by = analysis.getResultOptionsSorting()
if not sort_by:
return options

sort_by, sort_order = sort_by.split("-")
reverse = sort_order == "desc"
return sorted(options, key=itemgetter(sort_by), reverse=reverse)

def is_multi_interim(self, interim):
"""Returns whether the interim stores a list of values instead of a
single value
Expand Down
30 changes: 30 additions & 0 deletions src/bika/lims/content/abstractbaseanalysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,6 +619,35 @@
)
)

RESULT_OPTIONS_SORTING = (
("", _("Keep order above")),
("ResultValue-asc", _("By 'Result Value' ascending")),
("ResultValue-desc", _("By 'Result Value' descending")),
("ResultText-asc", _("By 'Display Value' ascending")),
("ResultText-desc", _("By 'Display Value' descending")),
)

ResultOptionsSorting = StringField(
"ResultOptionsSorting",
schemata="Result Options",
default="ResultText-asc",
vocabulary=DisplayList(RESULT_OPTIONS_SORTING),
widget=SelectionWidget(
label=_(
u"label_analysis_results_options_sorting",
default=u"Sorting criteria"
),
description=_(
u"description_analysis_results_options_sorting",
default=u"Criteria to use when result options are displayed for "
u"selection in results entry listings. Note this only "
u"applies to the options displayed in the selection list. "
u"It does not have any effect to the order in which "
u"results are displayed after being submitted"
),
)
)

# Allow/disallow the capture of text as the result of the analysis
StringResult = BooleanField(
"StringResult",
Expand Down Expand Up @@ -753,6 +782,7 @@
AllowManualUncertainty,
ResultOptions,
ResultOptionsType,
ResultOptionsSorting,
Hidden,
SelfVerification,
NumberOfRequiredVerifications,
Expand Down