From 9aacafd575bdb050d12f036d721239975d9663fa Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Tue, 21 May 2024 16:27:56 +0500 Subject: [PATCH] fix bug with cost schedules confusing 0 quantity with no quantities a bit related to #4704 1) fixed util.cost.get_total_quantity 2) fixed similar issue in cost.data that calculates the final value that user will see in UI 3) changed UI, "-" is shown when there are no quantities and "0" is when quantities are there but they just equal to zero. Before - https://i.imgur.com/EO53DhM.png After - https://i.imgur.com/H6rK4sP.png fyi @myoualid --- src/blenderbim/blenderbim/bim/module/cost/data.py | 2 +- src/blenderbim/blenderbim/bim/module/cost/ui.py | 2 +- src/ifcopenshell-python/ifcopenshell/util/cost.py | 7 ++++++- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/blenderbim/blenderbim/bim/module/cost/data.py b/src/blenderbim/blenderbim/bim/module/cost/data.py index 61bf88ddc3..dfc937c2a0 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/data.py +++ b/src/blenderbim/blenderbim/bim/module/cost/data.py @@ -140,7 +140,7 @@ class CostSchedulesData: data["UnitBasisUnitSymbol"] = "U" if cost_value.Category == "*": is_sum = True - cost_quantity = data["TotalCostQuantity"] or 1 + cost_quantity = 1 if data["TotalCostQuantity"] is None else data["TotalCostQuantity"] if has_unit_basis: data["TotalCost"] = data["TotalAppliedValue"] * cost_quantity / data["UnitBasisValueComponent"] else: diff --git a/src/blenderbim/blenderbim/bim/module/cost/ui.py b/src/blenderbim/blenderbim/bim/module/cost/ui.py index a5f4d973a9..7e77b016e1 100644 --- a/src/blenderbim/blenderbim/bim/module/cost/ui.py +++ b/src/blenderbim/blenderbim/bim/module/cost/ui.py @@ -634,7 +634,7 @@ class BIM_UL_cost_items_trait: layout.label(text=cost_item["UnitBasisUnitSymbol"]) def draw_total_quantity_column(self, layout, cost_item): - if cost_item["TotalCostQuantity"]: + if cost_item["TotalCostQuantity"] is not None: label = "{0:.2f}".format(cost_item["TotalCostQuantity"]) + f" {cost_item['UnitSymbol'] or '-'}" layout.label(text=label) else: diff --git a/src/ifcopenshell-python/ifcopenshell/util/cost.py b/src/ifcopenshell-python/ifcopenshell/util/cost.py index 90b140f0c1..910fb9f38d 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/cost.py +++ b/src/ifcopenshell-python/ifcopenshell/util/cost.py @@ -40,7 +40,12 @@ def get_primitive_applied_value(applied_value: Union[ifcopenshell.entity_instanc def get_total_quantity(root_element: ifcopenshell.entity_instance) -> Union[float, None]: # 3 IfcPhysicalQuantity Value if root_element.is_a("IfcCostItem"): - return sum([q[3] for q in root_element.CostQuantities or []]) or None + # Different output for no quantities and zero quantites + # as they have different meaning in IFC. + quantities = root_element.CostQuantities + if not quantities: + return None + return sum([q[3] for q in quantities]) elif root_element.is_a("IfcConstructionResource"): quantity = root_element.BaseQuantity return quantity[3] if quantity else 1.0