Merge pull request #285 from SchrodingersGat/hide-supplier-part

Hide supplier_part field if the part cannot be purchased
This commit is contained in:
Oliver 2019-05-09 18:46:48 +10:00 committed by GitHub
commit f4941d55ed
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -143,6 +143,10 @@ class StockItemEdit(AjaxUpdateView):
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 = query.filter(part=item.part.id)
form.fields['supplier_part'].queryset = query
@ -206,6 +210,11 @@ class StockItemCreate(AjaxCreateView):
part = Part.objects.get(id=part_id)
parts = form.fields['supplier_part'].queryset
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
# If there is one (and only one) supplier part available, pre-select it