From aac6e0c343955155e6ff6449ca357412710c2092 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Sat, 13 Sep 2025 14:20:01 +0200 Subject: ✨ Imports - documents - post importer action: set_container_by_code, set_container_ref_by_code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ishtar_common/models.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ishtar_common/models.py b/ishtar_common/models.py index 063a42522..a5fcc1a91 100644 --- a/ishtar_common/models.py +++ b/ishtar_common/models.py @@ -5904,6 +5904,27 @@ class Document( info.append(("rft.language", self.language.iso_code)) return ''.format(urlencode(info)) + def _set_container_by_code(self, code, target='container_id'): + Container = apps.get_model("archaeological_warehouse", "Container") + try: + container = Container.objects.get(code=code) + except DoesNotExist: + raise ImportError( + str(_("Container with code {} not found.")).format(code)) + except MultipleObjectsReturned: + raise ImportError( + str(_("Multiple containers with code {} found.")).format(code)) + self.__class__.objects.filter(pk=self.id).update( + **{target: container.pk}) + + @post_importer_action + def set_container_by_code(self, context, value): + return self._set_container_by_code(value) + + @post_importer_action + def set_container_ref_by_code(self, context, value): + return self._set_container_by_code(value, "container_ref_id") + def save(self, *args, **kwargs): no_path_change = "no_path_change" in kwargs and kwargs.pop("no_path_change") self.set_index() -- cgit v1.2.3