From a8578dcee5b4cad64ec6e10b1dc5cbfad815b4c8 Mon Sep 17 00:00:00 2001 From: Étienne Loks Date: Mon, 29 Jun 2020 15:37:18 +0200 Subject: Container - bulk update: remove parent when changing warehouse (refs #4959) --- archaeological_warehouse/forms.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) (limited to 'archaeological_warehouse/forms.py') 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() -- cgit v1.2.3