Hide supplier_part field if the part cannot be purchased

This commit is contained in:
Oliver Walters 2019-05-09 18:43:22 +10:00
parent 8bf09300bb
commit 2c5bb6b126

View File

@ -143,6 +143,10 @@ class StockItemEdit(AjaxUpdateView):
item = self.get_object() item = self.get_object()
# If the part cannot be purchased, hide the supplier_part field
if not item.part.purchaseable:
form.fields['supplier_part'].widget = HiddenInput()
else:
query = form.fields['supplier_part'].queryset query = form.fields['supplier_part'].queryset
query = query.filter(part=item.part.id) query = query.filter(part=item.part.id)
form.fields['supplier_part'].queryset = query form.fields['supplier_part'].queryset = query
@ -206,6 +210,11 @@ class StockItemCreate(AjaxCreateView):
part = Part.objects.get(id=part_id) part = Part.objects.get(id=part_id)
parts = form.fields['supplier_part'].queryset parts = form.fields['supplier_part'].queryset
parts = parts.filter(part=part.id) parts = parts.filter(part=part.id)
# If the part is NOT purchaseable, hide the supplier_part field
if not part.purchaseable:
form.fields['supplier_part'].widget = HiddenInput()
form.fields['supplier_part'].queryset = parts form.fields['supplier_part'].queryset = parts
# If there is one (and only one) supplier part available, pre-select it # If there is one (and only one) supplier part available, pre-select it