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_warehouse/forms.py | |
| 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_warehouse/forms.py')
| -rw-r--r-- | archaeological_warehouse/forms.py | 55 |
1 files changed, 45 insertions, 10 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 07c10ba91..3acc24282 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() + |
