From c409258ff3e3f54fcb4ab440543b6ee183a0001d Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 11 Nov 2024 17:43:44 +0500 Subject: [PATCH] calculate_cost_item_resource_value not to skip resources without quantities Noticed the discrepancies for total cost value for resources in Resource UI and in Cost Schedule UI when the same resources assigned to the item. In Resource UI it was considering omitted quantity as 1.0 (https://github.com/IfcOpenShell/IfcOpenShell/blob/c61e3670a8cf248aa5a229bae2dc29eef041fe47/src/ifcopenshell-python/ifcopenshell/util/cost.py#L53-L55) and in Cost Schedule UI it was skipping those resources completely. For cost items it is documented in ifc that if quantity is omitted then costs are considered to be total. Perhaps it's just not documented for the resources? Anyway, not sure if this way is completly correct but making sure resource quantity to be treated similarly in different parts of the codebase. Related to - https://github.com/buildingSMART/IFC4.3.x-development/issues/910 cc @myoualid --- src/ifcopenshell-python/ifcopenshell/util/resource.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/util/resource.py b/src/ifcopenshell-python/ifcopenshell/util/resource.py index 8a444e6371..2df15e7a63 100644 --- a/src/ifcopenshell-python/ifcopenshell/util/resource.py +++ b/src/ifcopenshell-python/ifcopenshell/util/resource.py @@ -159,11 +159,12 @@ def get_cost(resource: ifcopenshell.entity_instance) -> tuple[float, Union[str, def get_quantity(resource: ifcopenshell.entity_instance) -> float: - if resource.BaseQuantity: - return resource.BaseQuantity[3] if resource.Usage and resource.Usage.ScheduleWork: duration = ifcopenshell.util.date.ifc2datetime(resource.Usage.ScheduleWork) return duration.total_seconds() / 3600 + # TODO: is it safe to assume None quantity should be treated as 1.0? See #910 in ifc4x3dev. + quantity = resource.BaseQuantity + return 1.0 if quantity is None else quantity[3] def get_parent_cost(resource: ifcopenshell.entity_instance) -> Union[tuple[float, Union[str, None]], None]: