See #7716. Fix util get_cost_item_for_product

Before there was an error if there weren't assignments now it should be fixed. Add also tests.
This commit is contained in:
Massimo Fabbro
2026-03-07 22:01:31 +01:00
committed by Massimo Fabbro
parent 6b2d25a5e5
commit 5febbc1391
2 changed files with 58 additions and 3 deletions
@@ -196,9 +196,12 @@ def get_cost_items_for_product(product: ifcopenshell.entity_instance) -> list[if
:return: A list of IfcCostItem objects representing the cost items related to the product.
"""
cost_items = []
for assignment in product.HasAssignments:
if assignment.is_a("IfcRelAssignsToControl") and assignment.RelatingControl.is_a("IfcCostItem"):
cost_items.append(assignment.RelatingControl)
for assignment in product.HasAssignments or []:
if assignment.is_a("IfcRelAssignsToControl"):
control = assignment.RelatingControl
if control and control.is_a("IfcCostItem"):
cost_items.append(control)
return cost_items