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 08:30:22 +0100
commit10177fbddd94fd4ca098fb8319ba2e6baddabad5 (patch)
tree31b0a2fc07472631e9744c1013ca64ffe66fde38 /archaeological_finds/models_finds.py
parent948696a25ef56e32bc04b93fd8802f45090ee6ba (diff)
downloadIshtar-10177fbddd94fd4ca098fb8319ba2e6baddabad5.tar.bz2
Ishtar-10177fbddd94fd4ca098fb8319ba2e6baddabad5.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 0d7ee8b71..4b7536735 100644
--- a/archaeological_finds/models_finds.py
+++ b/archaeological_finds/models_finds.py
@@ -2428,11 +2428,11 @@ 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()
@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()
@@ -3404,8 +3404,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:
@@ -3421,6 +3423,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):
@@ -3429,8 +3434,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:
@@ -3446,6 +3454,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):
@@ -3514,9 +3525,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:
@@ -3694,7 +3703,8 @@ class FindTreatment(models.Model):
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: