diff options
Diffstat (limited to 'archaeological_warehouse/forms.py')
-rw-r--r-- | archaeological_warehouse/forms.py | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/archaeological_warehouse/forms.py b/archaeological_warehouse/forms.py index 6ea1ae4f6..170edce1f 100644 --- a/archaeological_warehouse/forms.py +++ b/archaeological_warehouse/forms.py @@ -596,7 +596,7 @@ class QAContainerFormMulti(QAForm): self.items = kwargs["items"] super(QAContainerFormMulti, self).__init__(*args, **kwargs) locations = set([item.location_id for item in self.items]) - if len(locations) == 1: + if len(locations) == 1 and "qalocation" in self.fields: self.fields["qalocation"].initial = locations.pop() def _get_qalocation(self, value): @@ -641,7 +641,7 @@ class QAContainerFormMulti(QAForm): _("Cannot do this changes because it would generate " "many containers with location: {}, container type: " "{}, parent: {} {} and reference: {}. " - "Merge theses containers first?")).format( + "Merge these containers first?")).format( models.Warehouse.objects.get(pk=vals["location_id"]), models.ContainerType.objects.get( pk=vals["container_type_id"]), @@ -650,3 +650,14 @@ class QAContainerFormMulti(QAForm): ) ) return self.cleaned_data + + def save(self, items, user): + super(QAContainerFormMulti, self).save(items, user) + if self.cleaned_data.get("qaparent", None): + return + for item in items: + item = models.Container.objects.get(pk=item.pk) + # remove parent if do not share the same location + if item.parent and item.parent.location != item.location: + item.parent = None + item.save() |