diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-09-09 14:45:17 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2024-09-10 15:40:21 +0200 |
commit | 66232651ef2a2c1f331dc381a8f86f24a279ba85 (patch) | |
tree | e4c43e6209a35d84f3b1b362237570224f511fd5 /archaeological_warehouse | |
parent | 39daa533e0b9d2a942223eeca817cdaa8887d69b (diff) | |
download | Ishtar-66232651ef2a2c1f331dc381a8f86f24a279ba85.tar.bz2 Ishtar-66232651ef2a2c1f331dc381a8f86f24a279ba85.zip |
✨ find container history: manage first packaging info
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r-- | archaeological_warehouse/models.py | 16 | ||||
-rw-r--r-- | archaeological_warehouse/tests.py | 21 |
2 files changed, 36 insertions, 1 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index d501eab1f..8bcc2bd65 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -1946,6 +1946,21 @@ class Container( ] return actions + def update_find_location(self): + full_location = self.generate_full_location() + if not full_location: + return + for find in self.finds.all(): + updated = find.update_current_full_location(full_location) + if updated: + find.skip_history_when_saving = True + find.save() + for find in self.finds_ref.all(): + updated = find.update_ref_full_location(full_location) + if updated: + find.skip_history_when_saving = True + find.save() + def pre_save(self): if self.parent == self: self.parent = None @@ -1992,6 +2007,7 @@ class Container( logger.debug(f"[ishtar] archaeological_warehouse.models.Container.save - {self.pk} - {self.cached_label}") self.pre_save() super().save(*args, **kwargs) + self.update_find_location() self._change_child_location(self) updated = False updated += self._prevent_parent_infinite_loop() diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index ebea75217..a5610893a 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -639,6 +639,8 @@ class ContainerTest(FindInit, TestCase): self.assertEqual(models.Container.objects.count(), self.container_number + 1) def test_change_location(self): + find = self.create_finds()[0][0] + find = Find.objects.get(pk=find.pk) container = models.Container.objects.create( reference="Test", responsible=self.main_warehouse, @@ -646,7 +648,6 @@ class ContainerTest(FindInit, TestCase): container_type=models.ContainerType.objects.all()[0], ) container.save() - container = models.Container.objects.get(pk=container.pk) container_2 = models.Container.objects.create( reference="Test2", responsible=self.main_warehouse, @@ -654,8 +655,16 @@ class ContainerTest(FindInit, TestCase): container_type=models.ContainerType.objects.all()[0], parent=container, ) + container = models.Container.objects.get(pk=container.pk) self.assertIn(self.main_warehouse.name, container.cached_location) + find.container = container + find.container_ref = container_2 + find.save() + find = Find.objects.get(pk=find.pk) + self.assertEqual(find.container_fisrt_full_location, container.generate_full_location()) + self.assertEqual(find.container_ref_fisrt_full_location, container_2.generate_full_location()) + models.ContainerLocalisation.objects.create( container=container, division=self.div_link, @@ -679,6 +688,16 @@ class ContainerTest(FindInit, TestCase): ) container_2 = models.Container.objects.get(pk=container_2.pk) self.assertEqual(container_2.location, other_warehouse) + find = Find.objects.get(pk=find.pk) + self.assertEqual(find.container_fisrt_full_location, container.generate_full_location()) + self.assertEqual(find.container_ref_fisrt_full_location, container_2.generate_full_location()) + + find.container = None + find.container_ref = None + find.save() + find = Find.objects.get(pk=find.pk) + self.assertEqual(find.container_fisrt_full_location, "") + self.assertEqual(find.container_ref_fisrt_full_location, "") """ def test_reassign_existing_division_on_warehouse_change(self): |