mirror of
https://github.com/IfcOpenShell/IfcOpenShell.git
synced 2026-09-27 02:31:09 +00:00
Prevent removing rel when is still valid after IfcCostItem removal #6769
This commit is contained in:
@@ -51,6 +51,8 @@ def remove_cost_item(file: ifcopenshell.file, cost_item: ifcopenshell.entity_ins
|
|||||||
if history:
|
if history:
|
||||||
ifcopenshell.util.element.remove_deep2(file, history)
|
ifcopenshell.util.element.remove_deep2(file, history)
|
||||||
elif inverse.is_a("IfcRelAssignsToControl"):
|
elif inverse.is_a("IfcRelAssignsToControl"):
|
||||||
|
if len(inverse.RelatedObjects) >= 2 or inverse.RelatingControl == cost_item:
|
||||||
|
continue
|
||||||
history = inverse.OwnerHistory
|
history = inverse.OwnerHistory
|
||||||
file.remove(inverse)
|
file.remove(inverse)
|
||||||
if history:
|
if history:
|
||||||
|
|||||||
@@ -46,6 +46,16 @@ class TestRemoveCostItem(test.bootstrap.IFC4):
|
|||||||
assert not self.file.by_type("IfcRelAssignsToControl")
|
assert not self.file.by_type("IfcRelAssignsToControl")
|
||||||
assert not self.file.by_type("IfcRelNests")
|
assert not self.file.by_type("IfcRelNests")
|
||||||
|
|
||||||
|
def test_remove_cost_item_keep_rel_for_other_cost_items(self):
|
||||||
|
schedule = ifcopenshell.api.cost.add_cost_schedule(self.file, name="Foo", predefined_type="BUDGET")
|
||||||
|
item1 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
|
||||||
|
item2 = ifcopenshell.api.cost.add_cost_item(self.file, cost_schedule=schedule)
|
||||||
|
ifcopenshell.api.cost.remove_cost_item(self.file, cost_item=item1)
|
||||||
|
assert self.file.by_type("IfcCostItem") == [item2]
|
||||||
|
rel = next(iter(self.file.by_type("IfcRelAssignsToControl")), None)
|
||||||
|
assert rel
|
||||||
|
assert rel.RelatedObjects == (item2,)
|
||||||
|
|
||||||
|
|
||||||
class TestRemoveCostItemIFC2X3(test.bootstrap.IFC2X3, TestRemoveCostItem):
|
class TestRemoveCostItemIFC2X3(test.bootstrap.IFC2X3, TestRemoveCostItem):
|
||||||
pass
|
pass
|
||||||
|
|||||||
Reference in New Issue
Block a user