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 15:36:27 +0100
commitabb31a2cce1ed14abaec5977a0f5b757f3e23699 (patch)
treead04096baba0c4f1c5b7a0708ce98a307a65a694 /archaeological_finds/models_finds.py
parent56f912402c97b5d26e36073eed2803ef513af639 (diff)
downloadIshtar-abb31a2cce1ed14abaec5977a0f5b757f3e23699.tar.bz2
Ishtar-abb31a2cce1ed14abaec5977a0f5b757f3e23699.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 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: