mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-08-11 02:02:22 +00:00
Fix calculating cost item resource value ignoring resource inheritance
Mentioned in #5744
This commit is contained in:
@@ -139,22 +139,18 @@ def get_nested_resources(resource: ifcopenshell.entity_instance) -> list[ifcopen
|
||||
return [object for rel in resource.IsNestedBy or [] for object in rel.RelatedObjects]
|
||||
|
||||
|
||||
def get_cost(resource: ifcopenshell.entity_instance) -> tuple[float, Union[str, None]]:
|
||||
base_costs = getattr(resource, "BaseCosts", [])
|
||||
costs = (
|
||||
[ifcopenshell.util.cost.calculate_applied_value(resource, cost_value) for cost_value in base_costs]
|
||||
if base_costs
|
||||
else []
|
||||
)
|
||||
cost = sum(costs)
|
||||
unit_basis = (
|
||||
next((cost_value.UnitBasis for cost_value in base_costs if cost_value.UnitBasis), None) if base_costs else None
|
||||
)
|
||||
unit = (
|
||||
unit_basis.UnitComponent.Name
|
||||
if unit_basis and unit_basis.UnitComponent.is_a("IfcConversionBasedUnit")
|
||||
else None
|
||||
)
|
||||
def get_cost(resource: ifcopenshell.entity_instance) -> tuple[Union[float, None], Union[str, None]]:
|
||||
"""Get cost data for IfcConstructionResource.
|
||||
|
||||
:return: a tuple of cost and unit.
|
||||
"""
|
||||
cost, unit = None, None
|
||||
if base_costs := resource.BaseCosts:
|
||||
costs = [ifcopenshell.util.cost.calculate_applied_value(resource, cost_value) for cost_value in base_costs]
|
||||
cost = sum(costs)
|
||||
unit_basis = next((unit_basis for cost_value in base_costs if (unit_basis := cost_value.UnitBasis)), None)
|
||||
if unit_basis and (unit_component := unit_basis.UnitComponent).is_a("IfcConversionBasedUnit"):
|
||||
unit = unit_component.Name
|
||||
return cost, unit
|
||||
|
||||
|
||||
@@ -167,7 +163,7 @@ def get_quantity(resource: ifcopenshell.entity_instance) -> float:
|
||||
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]:
|
||||
def get_parent_cost(resource: ifcopenshell.entity_instance) -> Union[tuple[Union[float, None], Union[str, None]], None]:
|
||||
if not (nests := resource.Nests):
|
||||
return
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user