Merge pull request #186 from SchrodingersGat/supplier-part-limit

Supplier part limit
This commit is contained in:
Oliver 2019-04-29 00:02:03 +10:00 committed by GitHub
commit e7a73e2dd9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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):