From afffd06fb8d9833432fe08ddde295517d9ecb082 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 8 May 2019 18:00:34 +1000 Subject: [PATCH] Limit choices for 'parent' field when editing StockLocation --- InvenTree/stock/views.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/InvenTree/stock/views.py b/InvenTree/stock/views.py index 1f6f85ea1a..e618be1ee8 100644 --- a/InvenTree/stock/views.py +++ b/InvenTree/stock/views.py @@ -75,6 +75,24 @@ class StockLocationEdit(AjaxUpdateView): ajax_template_name = 'modal_form.html' ajax_form_title = 'Edit Stock Location' + def get_form(self): + """ Customize form data for StockLocation editing. + + Limit the choices for 'parent' field to those which make sense. + """ + + form = super(AjaxUpdateView, self).get_form() + + location = self.get_object() + + # Remove any invalid choices for the 'parent' field + parent_choices = StockLocation.objects.all() + parent_choices = parent_choices.exclude(id__in=location.getUniqueChildren()) + + form.fields['parent'].queryset = parent_choices + + return form + class StockLocationQRCode(QRCodeView): """ View for displaying a QR code for a StockLocation object """