mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-26 02:07:36 +00:00
Fix calculating cost item resource value ignoring resource inheritance
Mentioned in #5744
This commit is contained in:
@@ -101,12 +101,11 @@ def calculate_cost_item_resource_value(file: ifcopenshell.file, cost_item: ifcop
|
|||||||
|
|
||||||
for resource in resources:
|
for resource in resources:
|
||||||
cost, unit = ifcopenshell.util.resource.get_cost(resource)
|
cost, unit = ifcopenshell.util.resource.get_cost(resource)
|
||||||
# TODO: cost is never None because get_cost always returns a float.
|
|
||||||
if cost is None:
|
if cost is None:
|
||||||
# Concept to standardise - Not defined in schema, but this makes manual scheduling of resources 10x faster and less duplicate data.
|
# Concept to standardise - Not defined in schema, but this makes manual scheduling of resources 10x faster and less duplicate data.
|
||||||
parent_cost = ifcopenshell.util.resource.get_parent_cost(resource)
|
parent_cost = ifcopenshell.util.resource.get_parent_cost(resource)
|
||||||
assert parent_cost
|
if parent_cost:
|
||||||
cost, unit = parent_cost
|
cost, unit = parent_cost
|
||||||
quantity = ifcopenshell.util.resource.get_quantity(resource)
|
quantity = ifcopenshell.util.resource.get_quantity(resource)
|
||||||
if cost is None:
|
if cost is None:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@@ -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]
|
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]]:
|
def get_cost(resource: ifcopenshell.entity_instance) -> tuple[Union[float, None], Union[str, None]]:
|
||||||
base_costs = getattr(resource, "BaseCosts", [])
|
"""Get cost data for IfcConstructionResource.
|
||||||
costs = (
|
|
||||||
[ifcopenshell.util.cost.calculate_applied_value(resource, cost_value) for cost_value in base_costs]
|
:return: a tuple of cost and unit.
|
||||||
if base_costs
|
"""
|
||||||
else []
|
cost, unit = None, None
|
||||||
)
|
if base_costs := resource.BaseCosts:
|
||||||
cost = sum(costs)
|
costs = [ifcopenshell.util.cost.calculate_applied_value(resource, cost_value) for cost_value in base_costs]
|
||||||
unit_basis = (
|
cost = sum(costs)
|
||||||
next((cost_value.UnitBasis for cost_value in base_costs if cost_value.UnitBasis), None) if base_costs else None
|
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 = unit_component.Name
|
||||||
unit_basis.UnitComponent.Name
|
|
||||||
if unit_basis and unit_basis.UnitComponent.is_a("IfcConversionBasedUnit")
|
|
||||||
else None
|
|
||||||
)
|
|
||||||
return cost, unit
|
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]
|
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):
|
if not (nests := resource.Nests):
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user