diff options
4 files changed, 23 insertions, 2 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 42b8e1749..110f01c9b 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -265,6 +265,7 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): extra_form_modals = ["warehouse", "organization", "person", "container"] associated_models = {'container_type': models.ContainerType, 'location': models.Warehouse, + 'collection': models.Warehouse, 'parent': models.Container} reference = forms.CharField(label=_("Ref."), max_length=200) old_reference = forms.CharField(label=_("Old reference"), required=False, @@ -285,6 +286,15 @@ class ContainerForm(CustomForm, ManageOldType, forms.Form): validators=[valid_id(models.Container)], required=False ) + collection = forms.IntegerField( + label=_("Collection"), + widget=widgets.JQueryAutoComplete( + reverse_lazy('autocomplete-warehouse'), + associated_model=models.Warehouse, new=True), + validators=[valid_id(models.Warehouse)], + help_text=_("Automatically attached to the current warehouse if not " + "filled.") + ) comment = forms.CharField(label=_("Comment"), widget=forms.Textarea, required=False) TYPES = [ diff --git a/archaeological_warehouse/management/commands/migrate_to_new_container_management.py b/archaeological_warehouse/management/commands/migrate_to_new_container_management.py index 24ec078bf..38cabd842 100644 --- a/archaeological_warehouse/management/commands/migrate_to_new_container_management.py +++ b/archaeological_warehouse/management/commands/migrate_to_new_container_management.py @@ -76,8 +76,8 @@ class Command(BaseCommand): parent=parent, container_type=container_types[ division.division.division_id], - location=container.responsible, - responsible=container.responsible) + location=container.location, + responsible=container.location) if created: created_nb += 1 ref = "{} || {}".format(str(new_container.container_type), @@ -89,6 +89,9 @@ class Command(BaseCommand): potential_duplicate[container.responsible_id][ ref].append(division.reference.strip()) parent = new_container + if container.collection_id != container.responsible_id: + container.collection_id = container.responsible_id + container.save() if parent: q = models.Container.objects.filter( location=container.location, diff --git a/archaeological_warehouse/models.py b/archaeological_warehouse/models.py index 8273619d9..5d06cefda 100644 --- a/archaeological_warehouse/models.py +++ b/archaeological_warehouse/models.py @@ -1357,6 +1357,11 @@ class Container(DocumentItem, Merge, LightHistorizedItem, return actions def pre_save(self): + if not self.collection_id and not self.collection: + if self.location_id: + self.collection_id = self.location_id + else: + self.collection = self.location q = Container.objects.filter(index=self.index, location=self.location) if self.id: q = q.exclude(id=self.id) diff --git a/archaeological_warehouse/templates/ishtar/sheet_container.html b/archaeological_warehouse/templates/ishtar/sheet_container.html index 6357c8be4..0d36c253e 100644 --- a/archaeological_warehouse/templates/ishtar/sheet_container.html +++ b/archaeological_warehouse/templates/ishtar/sheet_container.html @@ -107,6 +107,9 @@ <dt>{% trans "Number of owned finds" %}</dt> <dd>{{item.number_of_finds}}</dd> </dl> + {% if item.collection != item.location %} + {% field_flex_detail "Collection" item.collection %} + {% endif %} {% include "ishtar/blocks/sheet_creation_section.html" %} {% field_flex "Old reference" item.old_reference %} {% field_flex_full "Comment" item.comment "<pre>" "</pre>" %} |