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_finds | |
parent | 698bc976af6db131a7b0f7468dc12b0313dce198 (diff) | |
download | Ishtar-b6db29397aa518cd084bba3f5933644680604e01.tar.bz2 Ishtar-b6db29397aa518cd084bba3f5933644680604e01.zip |
Container: manage calculated weight
Diffstat (limited to 'archaeological_finds')
-rw-r--r-- | archaeological_finds/models_finds.py | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/archaeological_finds/models_finds.py b/archaeological_finds/models_finds.py index c3faf93d0..066bdb239 100644 --- a/archaeological_finds/models_finds.py +++ b/archaeological_finds/models_finds.py @@ -21,6 +21,7 @@ from collections import OrderedDict import datetime import uuid +from django.apps import apps from django.conf import settings from django.contrib.gis.db import models from django.contrib.postgres.indexes import GinIndex @@ -2680,12 +2681,26 @@ class Find(BulkUpdatedItem, ValueGetter, DocumentItem, BaseHistorizedItem, return True def save(self, *args, **kwargs): + old_container = None + # fetch in db + if self.pk: + old_container = self.__class__.objects.filter( + pk=self.pk).values_list("container_id", flat=True)[0] super(Find, self).save(*args, **kwargs) self.skip_history_when_saving = True if self.container_ref and not self.container: self.container = self.container_ref + if self.container and self.container._calculate_weight(): + self.container.save() + elif 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() + updated = self.update_external_id(save=False) if updated: self._cached_label_checked = False |