diff --git a/InvenTree/part/views.py b/InvenTree/part/views.py index d0f3a1ac01..af8559fb01 100644 --- a/InvenTree/part/views.py +++ b/InvenTree/part/views.py @@ -91,6 +91,17 @@ class PartCreate(AjaxCreateView): return context + def get_form(self): + """ Create Form for making new Part object. + Remove the 'default_supplier' field as there are not yet any matching SupplierPart objects + """ + form = super(AjaxCreateView, self).get_form() + + # Hide the default_supplier field (there are no matching supplier parts yet!) + del form.fields['default_supplier'] + + return form + # Pre-fill the category field if a valid category is provided def get_initial(self): """ Get initial data for the new Part object: @@ -169,6 +180,20 @@ 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): @@ -425,6 +450,9 @@ class SupplierPartCreate(AjaxCreateView): context_object_name = 'part' def get_form(self): + """ Create Form instance to create a new SupplierPart object. + Hide some fields if they are not appropriate in context + """ form = super(AjaxCreateView, self).get_form() if form.initial.get('supplier', None):