summaryrefslogtreecommitdiff
path: root/archaeological_warehouse
diff options
context:
space:
mode:
Diffstat (limited to 'archaeological_warehouse')
-rw-r--r--archaeological_warehouse/models.py28
1 files changed, 25 insertions, 3 deletions
diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py
index db08c3467..61b2e3f6d 100644
--- a/archaeological_warehouse/models.py
+++ b/archaeological_warehouse/models.py
@@ -45,6 +45,7 @@ from ishtar_common.models_common import GeneralType, \
from ishtar_common.model_merging import merge_model_objects
from ishtar_common.utils import cached_label_changed, \
cached_label_and_geo_changed, get_generated_id
+from ishtar_common.data_importer import ImporterError
class DivisionContainer(DashboardFormItem):
@@ -990,7 +991,25 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
@property
def get_merge_key(self):
- return str(self.location.uuid) + "|" + self._generate_cached_division()
+ try:
+ return str(self.location.uuid) + "|" + \
+ self._generate_cached_division()
+ except Warehouse.DoesNotExist:
+ return
+
+ @post_importer_action
+ def put_document_by_complete_identifier(self, context, value):
+ Document = apps.get_model("ishtar_common", "Document")
+ try:
+ doc = Document.objects.get(complete_identifier=value)
+ except Document.DoesNotExist:
+ raise ImporterError(str(_("Document with complete id: {} does not "
+ "exists")).format(value))
+ doc.container_id = self.pk
+ doc.container_ref_id = self.pk
+ doc.skip_history_when_saving = True
+ doc.save()
+ put_document_by_complete_identifier.post_save = True
def _generate_cached_division(self):
parents = []
@@ -1371,8 +1390,11 @@ class Container(DocumentItem, Merge, LightHistorizedItem,
if not self.responsibility_id and not self.responsibility:
if self.location_id:
self.responsibility_id = self.location_id
- if self.location:
- self.responsibility = self.location
+ else:
+ try:
+ self.responsibility = self.location
+ except Warehouse.DoesNotExist:
+ return
if self.container_type.stationary:
return
q = Container.objects.filter(index=self.index, location=self.location)