From 99a6d850f8ca41c99cd106471b48c52ec5f13288 Mon Sep 17 00:00:00 2001 From: Lunga Baliwe Date: Thu, 9 Jan 2025 10:33:54 +0200 Subject: [PATCH 1/3] LIMS-1255 --- src/bika/cement/extenders/fields.py | 28 +++++++++++++++------------- src/bika/cement/utils.py | 14 ++++++++++++++ 2 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 src/bika/cement/utils.py diff --git a/src/bika/cement/extenders/fields.py b/src/bika/cement/extenders/fields.py index 3233f29..9215e1d 100644 --- a/src/bika/cement/extenders/fields.py +++ b/src/bika/cement/extenders/fields.py @@ -29,6 +29,7 @@ from bika.lims import api from bika.lims.browser.fields import UIDReferenceField from senaite.core.catalog import SETUP_CATALOG +from bika.cement.utils import format_number class ExtensionField(object): @@ -197,22 +198,23 @@ def parse_mix_design_data(self, data): def parse_mix_design_concrete_data(self, data): concrete_data = {} - concrete_data["batch_volume"] = data[0][6] + concrete_data["batch_volume"] = format_number(data[0][6]) concrete_data["design_title"] = data[1][2] # design w/cm (title) - concrete_data["replacement"] = data[1][4] - concrete_data["paste_content"] = data[1][6] - concrete_data["total_cm"] = data[2][4] - concrete_data["theoretical_volume"] = data[2][6] + concrete_data["replacement"] = format_number(data[1][4]) + concrete_data["paste_content"] = format_number(data[1][6]) + concrete_data["total_cm"] = format_number(data[2][4]) + concrete_data["theoretical_volume"] = format_number(data[2][6]) concrete_data["super_air_meter"] = data[2][8] - concrete_data["design_air"] = data[3][2] - concrete_data["design_slump"] = data[3][4] - concrete_data["theoretical_unit_weight"] = data[3][6] - concrete_data["measured_air"] = data[4][2] - concrete_data["measured_slump"] = data[4][4] - concrete_data["lab_temperature"] = data[5][4] - concrete_data["concrete_temp"] = data[6][4] + concrete_data["design_air"] = format_number(data[3][2]) + concrete_data["design_slump"] = format_number(data[3][4]) + concrete_data["theoretical_unit_weight"] = format_number(data[3][6]) + concrete_data["measured_air"] = format_number(data[4][2]) + concrete_data["measured_slump"] = format_number(data[4][4]) + import pdb; pdb.set_trace() + concrete_data["lab_temperature"] = format_number(data[5][4]) + concrete_data["concrete_temp"] = format_number(data[6][4]) # Additional Table - concrete_data["trucked_volume"] = data[3][8] + concrete_data["trucked_volume"] = format_number(data[3][8]) concrete_data["trucked_number"] = data[4][8] concrete_data["ticket_number"] = data[5][8] concrete_data["plant_number"] = data[6][8] diff --git a/src/bika/cement/utils.py b/src/bika/cement/utils.py new file mode 100644 index 0000000..3a2403b --- /dev/null +++ b/src/bika/cement/utils.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- + +def format_number(value, decimal_places=2): + if value in (None, ""): + return None + + if isinstance(value, int): + return value # Return as-is if it's an integer + + try: + num = float(value) + return num if num.is_integer() else round(num, decimal_places) + except ValueError: + return None # Handle cases where conversion fails From ae00d4860004b7a7c288690f64bdf27ba32f3683 Mon Sep 17 00:00:00 2001 From: Lunga Baliwe Date: Thu, 9 Jan 2025 11:08:47 +0200 Subject: [PATCH 2/3] Handled long type numbers --- src/bika/cement/utils.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/bika/cement/utils.py b/src/bika/cement/utils.py index 3a2403b..8601cfe 100644 --- a/src/bika/cement/utils.py +++ b/src/bika/cement/utils.py @@ -4,8 +4,11 @@ def format_number(value, decimal_places=2): if value in (None, ""): return None - if isinstance(value, int): - return value # Return as-is if it's an integer + if isinstance(value, (int, long)): + try: + return int(value) # Return as-is if it's an integer + except OverflowError: + return value try: num = float(value) From c65cc2c155b01248340e7fc5aa348b2f0925f070 Mon Sep 17 00:00:00 2001 From: Lunga Baliwe Date: Thu, 9 Jan 2025 12:18:56 +0200 Subject: [PATCH 3/3] Removed pdb --- src/bika/cement/browser/batch/templates/mix_view.pt | 2 +- src/bika/cement/extenders/fields.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/bika/cement/browser/batch/templates/mix_view.pt b/src/bika/cement/browser/batch/templates/mix_view.pt index 4412345..18a7620 100644 --- a/src/bika/cement/browser/batch/templates/mix_view.pt +++ b/src/bika/cement/browser/batch/templates/mix_view.pt @@ -66,7 +66,7 @@ Theoretical Volume - cu ft + cu ft Batch Volume diff --git a/src/bika/cement/extenders/fields.py b/src/bika/cement/extenders/fields.py index 9215e1d..f2ea5af 100644 --- a/src/bika/cement/extenders/fields.py +++ b/src/bika/cement/extenders/fields.py @@ -210,7 +210,6 @@ def parse_mix_design_concrete_data(self, data): concrete_data["theoretical_unit_weight"] = format_number(data[3][6]) concrete_data["measured_air"] = format_number(data[4][2]) concrete_data["measured_slump"] = format_number(data[4][4]) - import pdb; pdb.set_trace() concrete_data["lab_temperature"] = format_number(data[5][4]) concrete_data["concrete_temp"] = format_number(data[6][4]) # Additional Table