summaryrefslogtreecommitdiff
path: root/archaeological_finds/models_finds.py
diff options
context:
space:
mode:
authorÉtienne Loks <etienne.loks@iggdrasil.net>2025-12-12 08:30:22 +0100
committerÉtienne Loks <etienne.loks@iggdrasil.net>2025-12-12 17:24:41 +0100
commit0b796e98bf8c196b3ec5005720925178782c046d (patch)
treeb98b84f9cc2db3b8d782a4c974878640235051d9 /archaeological_finds/models_finds.py
parentd317f541575a7ef59e7b06df5edc5b9c1560512f (diff)
downloadIshtar-0b796e98bf8c196b3ec5005720925178782c046d.tar.bz2
Ishtar-0b796e98bf8c196b3ec5005720925178782c046d.zip
🐛 treatment container history: fix history on container move (refs #6532)
Diffstat (limited to 'archaeological_finds/models_finds.py')
-rw-r--r--archaeological_finds/models_finds.py22
1 files changed, 16 insertions, 6 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py
index 42725f881..1a08eb171 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2582,7 +2582,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):
@@ -2611,7 +2611,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()
@@ -3607,8 +3607,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:
@@ -3624,6 +3626,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):
@@ -3632,8 +3637,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:
@@ -3649,6 +3657,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):
@@ -3717,9 +3728,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:
@@ -3901,7 +3910,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: