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 08:30:22 +0100 |
| commit | 10177fbddd94fd4ca098fb8319ba2e6baddabad5 (patch) | |
| tree | 31b0a2fc07472631e9744c1013ca64ffe66fde38 /archaeological_warehouse/forms.py | |
| parent | 948696a25ef56e32bc04b93fd8802f45090ee6ba (diff) | |
| download | Ishtar-10177fbddd94fd4ca098fb8319ba2e6baddabad5.tar.bz2 Ishtar-10177fbddd94fd4ca098fb8319ba2e6baddabad5.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 | 58 |
1 files changed, 47 insertions, 11 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 1d3b9d1a0..533315fbe 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -45,6 +45,7 @@ from archaeological_finds.models import ( ConservatoryState, Find, FindBasket, + FindTreatment, IntegrityType, MaterialType, ObjectType, @@ -853,27 +854,40 @@ 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_state = TreatmentState.get_completed_state() try: - location = models.Warehouse.objects.get(pk=self.cleaned_data.get("qalocation", None)) + location = models.Warehouse.objects.get( + pk=self.cleaned_data.get("qalocation", None)) except models.Warehouse.DoesNotExist: location = None @@ -893,8 +907,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() + |
