From ca4f30e17d5c6647bd60598c9a2305717adbd13e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jordi=20Puiggen=C3=A9?= Date: Thu, 23 Nov 2023 11:48:44 +0100 Subject: [PATCH] Fix multi-valued interim fields are not displayed correctly (#2433) * Fix multiresult interim fields are not displayed correctly * Changelog --- CHANGES.rst | 1 + src/bika/lims/browser/analyses/view.py | 46 ++++++++++++++++++++------ 2 files changed, 36 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1e6ecf9e81..540b4ef827 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,7 @@ Changelog 2.5.0 (unreleased) ------------------ +- #2433 Fix multi-valued interim fields are not displayed correctly - #2429 Fix recipients column in report listing to show those recipients to whom the report was also sent to - #2432 Fix results import files are always rendered for each analysis in report - #2427 Fix precision is not calculated from the rounded uncertainty diff --git a/src/bika/lims/browser/analyses/view.py b/src/bika/lims/browser/analyses/view.py index 3400067877..9f6ccba85b 100644 --- a/src/bika/lims/browser/analyses/view.py +++ b/src/bika/lims/browser/analyses/view.py @@ -1071,8 +1071,12 @@ def _folder_item_calculation(self, analysis_brain, item): interim_value = interim_field.get("value", "") interim_allow_empty = interim_field.get("allow_empty") == "on" interim_unit = interim_field.get("unit", "") - interim_formatted = formatDecimalMark(interim_value, self.dmk) + + # Get the interim's formatted value + interim_formatted = self.get_formatted_interim(interim_field) interim_field["formatted_value"] = interim_formatted + + # Update the item with the interim item[interim_keyword] = interim_field item["class"][interim_keyword] = "interim" @@ -1104,7 +1108,6 @@ def _folder_item_calculation(self, analysis_brain, item): # Ensure empty option is available if no default value is set if not interim_value and not multi: # allow empty selection and flush default value - interim_value = "" interim_allow_empty = True # Generate the display list @@ -1119,20 +1122,41 @@ def _folder_item_calculation(self, analysis_brain, item): item.setdefault("choices", {})[interim_keyword] = dl - # Set the text as the formatted value - texts = [choices.get(v, "") for v in api.to_list(interim_value)] - text = "
".join(filter(None, texts)) - interim_field["formatted_value"] = text - - if not is_editable: - # Display the text instead of the value - interim_field["value"] = text + if not is_editable: + # Display the text instead of the value + interim_field["value"] = interim_formatted - item[interim_keyword] = interim_field + item[interim_keyword] = interim_field item["interimfields"] = interim_fields self.interim_fields[analysis_brain.UID] = interim_fields + def get_formatted_interim(self, interim): + """Returns the formatted value of the interim + """ + # get the 'raw' value stored for this interim + raw_value = interim.get("value") + + if self.is_multi_interim(interim): + # value is a jsonified list of values + values = api.to_list(raw_value) + else: + values = [raw_value] + + # remove empties + values = filter(None, values) + + choices = self.get_interim_choices(interim) + if choices: + # values are predefined options for selection + values = [choices.get(v) for v in values] + else: + # values are captured directly by the user + values = [formatDecimalMark(value, self.dmk) for value in values] + + # return the values as a single string + return "
".join(values) + def _folder_item_unit(self, analysis_brain, item): """Fills the analysis' unit to the item passed in.