diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-05-15 17:33:49 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2023-05-15 18:14:00 +0200 |
commit | f44bca5141fa5b3f59ee6bf237778749451e2e15 (patch) | |
tree | 8e09e8c56425ee73912b07901e556e94a4e5dd89 | |
parent | c1cc4454309084090aecc7e407076c57c6b7c4d0 (diff) | |
download | Ishtar-f44bca5141fa5b3f59ee6bf237778749451e2e15.tar.bz2 Ishtar-f44bca5141fa5b3f59ee6bf237778749451e2e15.zip |
🐛 recalculate container weight on find remove (refs #5470)
-rw-r--r-- | archaeological_finds/models_finds.py | 14 | ||||
-rw-r--r-- | archaeological_warehouse/tests.py | 11 | ||||
-rw-r--r-- | changelog/en/changelog_2022-06-15.md | 3 | ||||
-rw-r--r-- | changelog/fr/changelog_2023-01-25.md | 3 |
4 files changed, 26 insertions, 5 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index 4b976a730..5eb204949 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -3241,7 +3241,7 @@ class Find( old_container = self.__class__.objects.filter(pk=self.pk).values_list( "container_id", flat=True )[0] - super(Find, self).save(*args, **kwargs) + super().save(*args, **kwargs) self.skip_history_when_saving = True if self.container_ref and not self.container: @@ -3249,12 +3249,16 @@ class Find( if self.container and self.container._calculate_weight(): self.container.save() - elif not self.container and old_container: + if (self.container and self.container.pk != old_container) or ( + not self.container and old_container): # force recalculation of weight when a find is removed Container = apps.get_model("archaeological_warehouse.Container") - old_container = Container.objects.get(pk=old_container) - if old_container._calculate_weight(): - old_container.save() + try: + old_container = Container.objects.get(pk=old_container) + if old_container._calculate_weight(): + old_container.save() + except Container.DoesNotExist: + pass updated = self.update_external_id(save=False) if updated: diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index 54432f9a5..ebea75217 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -1177,11 +1177,22 @@ class ContainerTest(FindInit, TestCase): self.assertEqual(container_1.calculated_weight, 1500) self.assertEqual(container_1.cached_weight, 1500) + container_2 = models.Container.objects.create( + reference="Test 2", location=self.main_warehouse, container_type=ct + ) + find2.container = container_2 + find2.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + self.assertEqual(container_1.calculated_weight, 800) + self.assertEqual(container_1.cached_weight, 800) + profile, created = IshtarSiteProfile.objects.get_or_create( slug="default", active=True ) profile.calculate_weight_on_full = True profile.save() + find2.container = container_1 + find2.save() container_1.save() container_1 = models.Container.objects.get(pk=container_1.pk) diff --git a/changelog/en/changelog_2022-06-15.md b/changelog/en/changelog_2022-06-15.md index 8184abfb0..8d87e79c8 100644 --- a/changelog/en/changelog_2022-06-15.md +++ b/changelog/en/changelog_2022-06-15.md @@ -1,6 +1,9 @@ v4.0.46 - 2023- -------------------- + +🐛 JS: fix UnitWidget (inappropriate l10n) + ### Technical ### - JS: fix UnitWidget (inappropriate l10n) diff --git a/changelog/fr/changelog_2023-01-25.md b/changelog/fr/changelog_2023-01-25.md index ec3f0aec7..3f820557e 100644 --- a/changelog/fr/changelog_2023-01-25.md +++ b/changelog/fr/changelog_2023-01-25.md @@ -1,6 +1,9 @@ v4.0.46 - 2023- -------------------- +### Corrections de dysfonctionnements ### +- recalcul du poids d'un contenant lorsque du mobilier en est retiré (refs #5470) + ### Technique ### - JS : correction UnitWidget (localisation inappropriée) |