diff options
| author | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-12-12 08:30:22 +0100 |
|---|---|---|
| committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2025-12-12 15:36:27 +0100 |
| commit | abb31a2cce1ed14abaec5977a0f5b757f3e23699 (patch) | |
| tree | ad04096baba0c4f1c5b7a0708ce98a307a65a694 /archaeological_finds | |
| parent | 56f912402c97b5d26e36073eed2803ef513af639 (diff) | |
| download | Ishtar-abb31a2cce1ed14abaec5977a0f5b757f3e23699.tar.bz2 Ishtar-abb31a2cce1ed14abaec5977a0f5b757f3e23699.zip | |
🐛 treatment container history: fix history on container move (refs #6532)
Diffstat (limited to 'archaeological_finds')
| -rw-r--r-- | archaeological_finds/models_finds.py | 22 | ||||
| -rw-r--r-- | archaeological_finds/models_treatments.py | 17 | ||||
| -rw-r--r-- | archaeological_finds/tests.py | 2 |
3 files changed, 33 insertions, 8 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index b33afb135..f4fd19803 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -2599,7 +2599,7 @@ class Find( @property def has_packaging_for_current_container(self): - return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"]) + return FindTreatment.objects.filter(find=self, location_type__in=["B", "C"]).exists() @staticmethod def _get_upstream_count(upstream_id, idx): @@ -2628,7 +2628,7 @@ class Find( @property def has_packaging_for_reference_container(self): - return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"]) + return FindTreatment.objects.filter(find=self, location_type__in=["B", "R"]).exists() def public_representation(self): dct = super(Find, self).public_representation() @@ -3639,8 +3639,10 @@ class Find( :param full_location: provided if update is triggered from container """ if getattr(self, "_container_fisrt_full_location", False) \ + or not self.pk \ or self.has_packaging_for_current_container: return False + self._container_fisrt_full_location = True if self.container: if not full_location: @@ -3656,6 +3658,9 @@ class Find( if return_value: return "" self.container_fisrt_full_location = "" + Find.objects.filter(pk=self.pk).update( + container_fisrt_full_location=self.container_fisrt_full_location + ) return True def update_ref_full_location(self, full_location=None, return_value=False): @@ -3664,8 +3669,11 @@ class Find( :param full_location: provided if update is triggered from container """ if getattr(self, "_container_ref_fisrt_full_location", False) \ + or not self.pk \ + or self.has_packaging_for_current_container \ or self.has_packaging_for_reference_container: return False + # if current container has already changed - do not change first self._container_ref_fisrt_full_location = True if self.container_ref: if not full_location: @@ -3681,6 +3689,9 @@ class Find( if return_value: return "" self.container_ref_fisrt_full_location = "" + Find.objects.filter(pk=self.pk).update( + container_ref_fisrt_full_location=self.container_ref_fisrt_full_location + ) return True def update_full_location(self): @@ -3749,9 +3760,7 @@ class Find( except Container.DoesNotExist: pass - if self.update_full_location(): - self.save() - return True + self.update_full_location() updated = self.update_external_id(save=False) if updated: @@ -3964,7 +3973,8 @@ class FindTreatment(Imported): on_delete=models.CASCADE ) full_location = models.TextField(_("Full location"), default="", blank=True) - location_type = models.CharField(_("Location type"), max_length=1, choices=LOCATION_TYPE, + location_type = models.CharField(_("Location type"), max_length=1, + choices=LOCATION_TYPE, default="C") class Meta: diff --git a/archaeological_finds/models_treatments.py b/archaeological_finds/models_treatments.py index ebe842ac7..21f1fe9e6 100644 --- a/archaeological_finds/models_treatments.py +++ b/archaeological_finds/models_treatments.py @@ -983,6 +983,23 @@ class Treatment( post_save.connect(cached_label_changed, sender=Treatment) +def treatment_attached_changed(sender, **kwargs): + # force full location + instance = kwargs.get("instance", None) + find_pk_set = kwargs.get("pk_set", None) + if not find_pk_set or not instance: + return + for find_id in find_pk_set: + q = FindTreatment.objects.filter(find_id=find_id, treatment_id=instance.pk) + if not q.count(): + continue + for ft in q.all(): + ft.generate_full_location() + + +m2m_changed.connect(treatment_attached_changed, sender=Treatment.finds.through) + + def pre_delete_treatment(sender, **kwargs): treatment = kwargs.get("instance") for find in Find.objects.filter(upstream_treatment=treatment).all(): diff --git a/archaeological_finds/tests.py b/archaeological_finds/tests.py index f105093fd..dfb267564 100644 --- a/archaeological_finds/tests.py +++ b/archaeological_finds/tests.py @@ -2541,8 +2541,6 @@ class FindQATest(FindInit, TestCase): value = check[k] value2 = check[k] if k == "container" and data["qa-packaging-container_to_change"] == "reference": - # if current not set -> auto set container to container_ref - value = check["container_ref"] # current set for find_1 -> keep it value2 = Container.objects.get(reference="Test2 base") if k == "container_ref" and data["qa-packaging-container_to_change"] == "current": |
