Cleanup queryset for BomItemEdit view

This commit is contained in:
Oliver Walters 2020-11-24 09:43:49 +11:00
parent 3391db506a
commit 371ec582e1

View File

@ -2497,6 +2497,8 @@ class BomItemEdit(AjaxUpdateView):
- Remove any part items that are already in the BOM - Remove any part items that are already in the BOM
""" """
item = self.get_object()
form = super().get_form() form = super().get_form()
part_id = form['part'].value() part_id = form['part'].value()
@ -2504,9 +2506,14 @@ class BomItemEdit(AjaxUpdateView):
try: try:
part = Part.objects.get(pk=part_id) part = Part.objects.get(pk=part_id)
query = form.fields['sub_part'].queryset # Construct a queryset
query = Part.objects.filter(component=True)
# Reduce the available selection options # Limit to "active" items, *unless* the currently selected item is not active
if item.sub_part.active:
query = query.filter(active=True)
# Prevent the parent part from being selected
query = query.exclude(pk=part_id) query = query.exclude(pk=part_id)
# Eliminate any options that are already in the BOM, # Eliminate any options that are already in the BOM,