From 2f554db54b68da9bcbeb2a6f65e46728bd4ad5ab Mon Sep 17 00:00:00 2001 From: Andrej730 Date: Mon, 13 May 2024 14:55:48 +0500 Subject: [PATCH] owner.remove_person to remove IfcInventory in ifc2x3 --- .../ifcopenshell/api/owner/remove_person.py | 6 +++++- .../test/api/owner/test_remove_person.py | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py index aac583b22e..77d297527f 100644 --- a/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py +++ b/src/ifcopenshell-python/ifcopenshell/api/owner/remove_person.py @@ -24,6 +24,8 @@ def remove_person(file, person=None) -> None: All roles and addresses assigned to the person will also be removed. + In IFC2X3 will also remove related inventories if `person` was + the only responsile person for them. :param person: The IfcPerson to remove :type person: ifcopenshell.entity_instance @@ -52,7 +54,9 @@ def remove_person(file, person=None) -> None: inverse.Creators = None elif inverse.is_a("IfcInventory"): if inverse.ResponsiblePersons == (settings["person"],): - inverse.ResponsiblePersons = None + # in IFC2X3 ResponsiblePersons is not optional and without it IfcInventory is not valid + if file.schema == "IFC2X3": + ifcopenshell.api.run("root.remove_product", file, product=inverse) elif inverse.is_a("IfcDocumentInformation"): if inverse.Editors == (settings["person"],): inverse.Editors = None diff --git a/src/ifcopenshell-python/test/api/owner/test_remove_person.py b/src/ifcopenshell-python/test/api/owner/test_remove_person.py index 569b42cd60..76d641a85f 100644 --- a/src/ifcopenshell-python/test/api/owner/test_remove_person.py +++ b/src/ifcopenshell-python/test/api/owner/test_remove_person.py @@ -61,8 +61,13 @@ class TestRemovePerson(test.bootstrap.IFC4): def test_ensuring_inventory_should_not_be_left_in_an_invalid_set_cardinality(self): person = self.file.createIfcPerson() inventory = self.file.createIfcInventory(ResponsiblePersons=[person]) + inventory_id = inventory.id() ifcopenshell.api.run("owner.remove_person", self.file, person=person) - assert inventory.ResponsiblePersons is None + if self.file.schema != "IFC2X3": + assert inventory.ResponsiblePersons is None + else: + with pytest.raises(RuntimeError): + self.file.by_id(inventory_id) def test_deleting_person_and_organisations(self): person = self.file.createIfcPerson()