diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-22 15:51:43 +0200 | 
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-10-24 18:20:47 +0200 | 
| commit | 0ea8d08ef8fc8c998fea8c3ee42dc9bfd40fc4a7 (patch) | |
| tree | 9df61bf56f925af4b2e72cbf6081e9e154bb3cd1 /archaeological_warehouse/models.py | |
| parent | 71a5bf5cc8fa8061804061e3773ab135aae48474 (diff) | |
| download | Ishtar-0ea8d08ef8fc8c998fea8c3ee42dc9bfd40fc4a7.tar.bz2 Ishtar-0ea8d08ef8fc8c998fea8c3ee42dc9bfd40fc4a7.zip  | |
🐛 fix regenerate cached label of childs on container move (refs #6480)
Diffstat (limited to 'archaeological_warehouse/models.py')
| -rw-r--r-- | archaeological_warehouse/models.py | 41 | 
1 files changed, 41 insertions, 0 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 993ab3362..84e88d1f1 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -2084,9 +2084,46 @@ class Container(          q.update(cached_division="")          return ((self.__class__, q.values_list("id", flat=True)),) +    def _update_childs_divisions(self): +        Find = apps.get_model("archaeological_finds", "Find") +        q = Container.objects.filter(parent_id=self.id) +        for child in q.all(): +            self.update_weight() +            cached_division = child._generate_cached_division() +            cached_label = child._generate_cached_label() +            cached_weight = child._generate_cached_weight() +            Container.objects.filter(pk=child.pk).update( +                cached_division=cached_division, +                cached_label=cached_label, +                cached_weight=cached_weight +            ) + +            # update location of associated find +            full_location = Container.objects.get(pk=child.pk).generate_full_location() +            for find in child.finds_ref.all(): +                value = find.update_ref_full_location(full_location, return_value=True) +                if value is not False: +                    Find.objects.filter(pk=find.pk).update( +                        container_ref_fisrt_full_location=value +                    ) +            for find in child.finds.all(): +                value = find.update_current_full_location(full_location, return_value=True) +                if value is not False: +                    Find.objects.filter(pk=find.pk).update( +                        container_fisrt_full_location=value +                    ) + +            # TODO update last treatment? +            # warning - if a new treatment is created via move container +            # it will be created after this is triggered... not easy to manage... + +            child._update_childs_divisions() +      def save(self, *args, **kwargs): +        self._cached_location, self._cached_parent = None, None          if self.pk:              logger.debug(f"[ishtar] archaeological_warehouse.models.Container.save - {self.pk} - {self.cached_label}") +            self._cached_location, self._cached_parent = Container.objects.filter(pk=self.pk).values_list("location_id", "parent_id").all()[0]          self.pre_save()          super().save(*args, **kwargs)          self.update_find_location() @@ -2097,6 +2134,10 @@ class Container(          updated += self._calculate_weight() +        # update cached_label for childs +        if self._cached_location != self.location_id or self._cached_parent != self.parent_id: +            self._update_childs_divisions() +          if not self.index and not self.container_type.stationary:              self.skip_history_when_saving = True              q = (  | 
