fix the bug fix #07b5c49 - where counting objects controlled by a cost item stopped working

This commit is contained in:
Sigma Dimensions (Yass)
2023-08-13 12:16:29 +01:00
parent e8437a9c54
commit eb94c16465
@@ -88,28 +88,31 @@ class Usecase:
self.quantities = set(self.settings["cost_item"].CostQuantities or [])
print(self.settings["cost_item"].CostQuantities)
for product in self.settings["products"]:
self.assign_cost_control(
related_object=product, cost_item=self.settings["cost_item"]
)
if self.settings["prop_name"]:
if (
self.settings["cost_item"].CostQuantities
and self.settings["cost_item"].CostQuantities[0].Name.lower()
!= self.settings["prop_name"].lower()
):
) or not product.is_a("IfcObject"):
continue
ifcopenshell.api.run(
"control.assign_control",
self.file,
related_object=product,
relating_control=self.settings["cost_item"],
)
self.add_quantity_from_related_object(product)
if self.settings["prop_name"]:
self.settings["cost_item"].CostQuantities = list(self.quantities)
else:
self.update_cost_item_count()
def assign_cost_control(self, related_object, cost_item):
return ifcopenshell.api.run(
"control.assign_control",
self.file,
related_object=related_object,
relating_control=cost_item,
)
def add_quantity_from_related_object(self, element):
if not element.is_a("IfcObject"):
return
for relationship in element.IsDefinedBy:
if relationship.is_a("IfcRelDefinesByProperties"):
self.add_quantity_from_qto(relationship.RelatingPropertyDefinition)
@@ -128,7 +131,7 @@ class Usecase:
# This is a bold assumption
# https://forums.buildingsmart.org/t/how-does-a-cost-item-know-that-it-is-counting-a-controlled-product/3564
if not self.settings["cost_item"].CostQuantities:
return ifcopenshell.api.run(
ifcopenshell.api.run(
"cost.add_cost_item_quantity",
self.file,
cost_item=self.settings["cost_item"],