Skip to content
This repository was archived by the owner on Nov 24, 2024. It is now read-only.

Commit 2f554db

Browse files
committed
owner.remove_person to remove IfcInventory in ifc2x3
1 parent 54b4cef commit 2f554db

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ def remove_person(file, person=None) -> None:
2424
2525
All roles and addresses assigned to the person will also be
2626
removed.
27+
In IFC2X3 will also remove related inventories if `person` was
28+
the only responsile person for them.
2729
2830
:param person: The IfcPerson to remove
2931
:type person: ifcopenshell.entity_instance
@@ -52,7 +54,9 @@ def remove_person(file, person=None) -> None:
5254
inverse.Creators = None
5355
elif inverse.is_a("IfcInventory"):
5456
if inverse.ResponsiblePersons == (settings["person"],):
55-
inverse.ResponsiblePersons = None
57+
# in IFC2X3 ResponsiblePersons is not optional and without it IfcInventory is not valid
58+
if file.schema == "IFC2X3":
59+
ifcopenshell.api.run("root.remove_product", file, product=inverse)
5660
elif inverse.is_a("IfcDocumentInformation"):
5761
if inverse.Editors == (settings["person"],):
5862
inverse.Editors = None

src/ifcopenshell-python/test/api/owner/test_remove_person.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,13 @@ def test_ensuring_work_controls_should_not_be_left_in_an_invalid_set_cardinality
6161
def test_ensuring_inventory_should_not_be_left_in_an_invalid_set_cardinality(self):
6262
person = self.file.createIfcPerson()
6363
inventory = self.file.createIfcInventory(ResponsiblePersons=[person])
64+
inventory_id = inventory.id()
6465
ifcopenshell.api.run("owner.remove_person", self.file, person=person)
65-
assert inventory.ResponsiblePersons is None
66+
if self.file.schema != "IFC2X3":
67+
assert inventory.ResponsiblePersons is None
68+
else:
69+
with pytest.raises(RuntimeError):
70+
self.file.by_id(inventory_id)
6671

6772
def test_deleting_person_and_organisations(self):
6873
person = self.file.createIfcPerson()

0 commit comments

Comments
 (0)