From 4e3702384bcaeea89f7e4c3bcc4db6ae0d061d6d Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Apr 2019 23:50:35 +1000 Subject: [PATCH] Limit SupplierPart option in Part edit form - Only allow selection of SupplierPart that match the Part being edited --- InvenTree/part/views.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d0f3a1ac01..4d7a861a07 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -169,6 +169,21 @@ class PartEdit(AjaxUpdateView): ajax_form_title = 'Edit Part Properties' context_object_name = 'part' + def get_form(self): + """ Create form for Part editing. + Overrides default get_form() method to limit the choices + for the 'default_supplier' field to SupplierParts that reference this part + """ + + form = super(AjaxUpdateView, self).get_form() + + part = self.get_object() + + form.fields['default_supplier'].queryset = SupplierPart.objects.filter(part=part) + + return form + + class BomExport(AjaxView):