summaryrefslogtreecommitdiff
path: root/archaeological_warehouse/forms.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_warehouse/forms.py
parentd317f541575a7ef59e7b06df5edc5b9c1560512f (diff)
downloadIshtar-0b796e98bf8c196b3ec5005720925178782c046d.tar.bz2
Ishtar-0b796e98bf8c196b3ec5005720925178782c046d.zip
🐛 treatment container history: fix history on container move (refs #6532)
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r--archaeological_warehouse/forms.py55
1 files changed, 45 insertions, 10 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py
index 5b22362c4..8e272e9c2 100644
--- a/archaeological_warehouse/forms.py
+++ b/archaeological_warehouse/forms.py
@@ -46,6 +46,7 @@ from archaeological_finds.models import (
ConservatoryState,
Find,
FindBasket,
+ FindTreatment,
IntegrityType,
MaterialType,
ObjectType,
@@ -859,21 +860,33 @@ class QAContainerMoveForm(QABasePackagingForm):
def save(self, items, user):
location_id = self.cleaned_data.get("qalocation", None)
parent_id = self.cleaned_data.get("qaparent", None)
+
+ changed = []
for container in self.items:
- changed = False
+ # move the container
if parent_id and parent_id != container.parent_id:
container.parent_id = parent_id
- changed = True
+ models.Container.objects.filter(id=container.id).update(
+ parent_id=parent_id
+ )
+ changed.append(container)
if location_id and location_id != container.location_id:
container.location_id = location_id
- # remove parent if do not share the same location
- if not changed and container.parent \
- and container.parent.location != container.location:
- container.parent = None
- changed = True
- if changed:
- container.save()
+ models.Container.objects.filter(id=container.id).update(
+ location_id=location_id
+ )
+ if container not in changed:
+ # remove parent if do not share the same location
+ if container.parent \
+ and container.parent.location != container.location:
+ container.parent = None
+ models.Container.objects.filter(id=container.id).update(
+ parent=None
+ )
+ changed.append(container)
if not self.cleaned_data.get("create_treatment", False):
+ for container in changed:
+ container.save()
return
treat_type = TreatmentType.objects.get(pk=self.cleaned_data['treatment_type'])
treat_input_status = TreatmentInputStatus.get_validated_state()
@@ -902,8 +915,30 @@ class QAContainerMoveForm(QABasePackagingForm):
q = Find.objects.filter(Q(container=container) | Q(container_ref=container))
if not q.count():
continue
+ loca = container.generate_full_location()
for find in q.all():
- t.finds.add(find)
+ if find.update_current_full_location():
+ Find.objects.filter(pk=find.id).update(
+ container_fisrt_full_location=find.container_fisrt_full_location
+ )
+ if find.update_ref_full_location():
+ Find.objects.filter(pk=find.id).update(
+ container_ref_fisrt_full_location=find.container_ref_fisrt_full_location
+ )
+ location_type = "C"
+ if find.container_ref == container:
+ if find.container == container:
+ location_type = "B"
+ else:
+ location_type = "R"
+ FindTreatment.objects.create(
+ find=find, treatment=t,
+ location_type=location_type,
+ full_location=loca
+ )
t.save() # force find container history
+ for container in changed: # container post treatment after save
+ container.save()
+