From 2d0ff87bc8952f66af29a40091392999e9f02fc2 Mon Sep 17 00:00:00 2001 From: Junhan Chang Date: Sun, 19 Oct 2025 05:19:19 +0800 Subject: [PATCH] fix itemized_carrier.unassign_child_resource --- unilabos/resources/graphio.py | 12 ++++++------ unilabos/resources/itemized_carrier.py | 5 +++-- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/unilabos/resources/graphio.py b/unilabos/resources/graphio.py index 65837b04..d91a933d 100644 --- a/unilabos/resources/graphio.py +++ b/unilabos/resources/graphio.py @@ -639,6 +639,8 @@ def resource_bioyond_to_plr(bioyond_materials: list[dict], type_mapping: Dict[st # 处理子物料(detail) if material.get("detail") and len(material["detail"]) > 0: + for bottle in reversed(plr_material.children): + plr_material.unassign_child_resource(bottle) child_ids = [] for detail in material["detail"]: number = ( @@ -646,12 +648,10 @@ def resource_bioyond_to_plr(bioyond_materials: list[dict], type_mapping: Dict[st + (detail.get("y", 0) - 1) * plr_material.num_items_y + (detail.get("x", 0) - 1) ) - bottle = plr_material[number] - if detail["typeName"] in type_mapping: - # plr_material.unassign_child_resource(bottle) - plr_material.sites[number] = None - plr_material[number] = initialize_resource( - {"name": f'{detail["name"]}_{number}', "class": type_mapping[detail["typeName"]][0]}, resource_type=ResourcePLR + typeName = detail.get("typeName", detail.get("name", "")) + if typeName in type_mapping: + bottle = plr_material[number] = initialize_resource( + {"name": f'{detail["name"]}_{number}', "class": type_mapping[typeName][0]}, resource_type=ResourcePLR ) else: bottle.tracker.liquids = [ diff --git a/unilabos/resources/itemized_carrier.py b/unilabos/resources/itemized_carrier.py index 5f1a93c9..7607cf4d 100644 --- a/unilabos/resources/itemized_carrier.py +++ b/unilabos/resources/itemized_carrier.py @@ -164,8 +164,9 @@ class ItemizedCarrier(ResourcePLR): break if not found: raise ValueError(f"Resource {resource} is not assigned to this carrier") - if hasattr(resource, "unassign"): - resource.unassign() + super().unassign_child_resource(resource) + # if hasattr(resource, "unassign"): + # resource.unassign() def get_child_identifier(self, child: ResourcePLR): """Get the identifier information for a given child resource.