diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-09 11:14:48 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-03-09 11:14:48 +0100 |
commit | b6db29397aa518cd084bba3f5933644680604e01 (patch) | |
tree | b742211e062221e851c04f6ddcf580ac3faf395c /archaeological_warehouse/tests.py | |
parent | 698bc976af6db131a7b0f7468dc12b0313dce198 (diff) | |
download | Ishtar-b6db29397aa518cd084bba3f5933644680604e01.tar.bz2 Ishtar-b6db29397aa518cd084bba3f5933644680604e01.zip |
Container: manage calculated weight
Diffstat (limited to 'archaeological_warehouse/tests.py')
-rw-r--r-- | archaeological_warehouse/tests.py | 67 |
1 files changed, 67 insertions, 0 deletions
diff --git a/archaeological_warehouse/tests.py b/archaeological_warehouse/tests.py index b65b68351..dc1744312 100644 --- a/archaeological_warehouse/tests.py +++ b/archaeological_warehouse/tests.py @@ -1144,3 +1144,70 @@ class ContainerTest(FindInit, TestCase): container_1.get_material_types_code(), "|".join(sorted([mat0.code, mat1.code, mat2.code]))) + def test_calculated_weight(self): + self.create_finds() + self.create_finds() + self.create_finds() + find0 = self.finds[0] + find1 = self.finds[1] + find1.weight = 600 + find1.save() + find2 = self.finds[2] + find2.weight = 700 + find2.save() + + ct = models.ContainerType.objects.all()[0] + ct.tare_weight = 200 + ct.save() + container_1 = models.Container.objects.create( + reference="Test 1", + location=self.main_warehouse, + container_type=ct) + container_1.save() + self.assertEqual(container_1.calculated_weight, 200) + self.assertEqual(container_1.cached_weight, 200) + find0.container = container_1 + find0.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + # no weight -> tare weight + self.assertEqual(container_1.calculated_weight, 200) + self.assertEqual(container_1.cached_weight, 200) + + find1.container = container_1 + find1.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + # tare weight + find1 weight + self.assertEqual(container_1.calculated_weight, 800) + self.assertEqual(container_1.cached_weight, 800) + + find2.container = container_1 + find2.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + # tare weight + find1 weight + find2 weight + self.assertEqual(container_1.calculated_weight, 1500) + self.assertEqual(container_1.cached_weight, 1500) + + profile, created = IshtarSiteProfile.objects.get_or_create( + slug='default', active=True) + profile.calculate_weight_on_full = True + profile.save() + + container_1.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + # a find with no weight is inside the container + self.assertEqual(container_1.calculated_weight, None) + self.assertEqual(container_1.cached_weight, None) + + find0.container = None + find0.save() + # once the find with no weight is removed the weight is recalculated + container_1 = models.Container.objects.get(pk=container_1.pk) + self.assertEqual(container_1.calculated_weight, 1500) + self.assertEqual(container_1.cached_weight, 1500) + + find0.container = container_1 + find0.save() + container_1 = models.Container.objects.get(pk=container_1.pk) + self.assertEqual(container_1.calculated_weight, None) + self.assertEqual(container_1.cached_weight, None) + |