diff options
author | Étienne Loks <etienne.loks@iggdrasil.net> | 2020-06-29 15:37:18 +0200 |
---|---|---|
committer | Étienne Loks <etienne.loks@iggdrasil.net> | 2021-02-28 12:15:20 +0100 |
commit | a3af0d081a21713ff4c93c1d077477bc45c17527 (patch) | |
tree | d915605d6207355788d69ad9a8e2a3a35d94507d /archaeological_warehouse/forms.py | |
parent | 2f6802085f89cf947a60da17f6e2b47a580abc4b (diff) | |
download | Ishtar-a3af0d081a21713ff4c93c1d077477bc45c17527.tar.bz2 Ishtar-a3af0d081a21713ff4c93c1d077477bc45c17527.zip |
Container - bulk update: remove parent when changing warehouse (refs #4959)
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() |