summaryrefslogtreecommitdiff
path: root/archaeological_finds
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_finds')
-rw-r--r--archaeological_finds/models_finds.py15
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