Skip to content

Commit

Permalink
Fix multi-valued interim fields are not displayed correctly (#2433)
Browse files Browse the repository at this point in the history
* Fix multiresult interim fields are not displayed correctly

* Changelog
  • Loading branch information
xispa authored Nov 23, 2023
1 parent b694ce2 commit ca4f30e
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 11 deletions.
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)
------------------

- #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
Expand Down
46 changes: 35 additions & 11 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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 = "<br/>".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 "<br/>".join(values)

def _folder_item_unit(self, analysis_brain, item):
"""Fills the analysis' unit to the item passed in.
Expand Down

0 comments on commit ca4f30e

Please sign in to comment.