mirror of
https://github.com/inventree/InvenTree
synced 2024-08-30 18:33:04 +00:00
Cleanup queryset for BomItemCreate view
This commit is contained in:
parent
af9b88de11
commit
3391db506a
@ -2428,30 +2428,35 @@ class BomItemCreate(AjaxCreateView):
|
|||||||
|
|
||||||
part_id = form['part'].value()
|
part_id = form['part'].value()
|
||||||
|
|
||||||
|
# Construct a queryset for the part field
|
||||||
|
part_query = Part.objects.filter(active=True)
|
||||||
|
|
||||||
|
# Construct a queryset for the sub_part field
|
||||||
|
sub_part_query = Part.objects.filter(
|
||||||
|
component=True,
|
||||||
|
active=True
|
||||||
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
part = Part.objects.get(id=part_id)
|
part = Part.objects.get(id=part_id)
|
||||||
|
|
||||||
# Only allow active parts to be selected
|
# Hide the 'part' field
|
||||||
query = form.fields['part'].queryset.filter(active=True)
|
form.fields['part'].widget = HiddenInput()
|
||||||
form.fields['part'].queryset = query
|
|
||||||
|
|
||||||
# Don't allow selection of sub_part objects which are already added to the Bom!
|
# Exclude the part from its own BOM
|
||||||
query = form.fields['sub_part'].queryset
|
sub_part_query = sub_part_query.exclude(id=part.id)
|
||||||
|
|
||||||
# Don't allow a part to be added to its own BOM
|
|
||||||
query = query.exclude(id=part.id)
|
|
||||||
query = query.filter(active=True)
|
|
||||||
|
|
||||||
# Eliminate any options that are already in the BOM!
|
# Eliminate any options that are already in the BOM!
|
||||||
query = query.exclude(id__in=[item.id for item in part.getRequiredParts()])
|
sub_part_query = sub_part_query.exclude(id__in=[item.id for item in part.getRequiredParts()])
|
||||||
|
|
||||||
form.fields['sub_part'].queryset = query
|
|
||||||
|
|
||||||
form.fields['part'].widget = HiddenInput()
|
|
||||||
|
|
||||||
except (ValueError, Part.DoesNotExist):
|
except (ValueError, Part.DoesNotExist):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# Set the querysets for the fields
|
||||||
|
form.fields['part'].queryset = part_query
|
||||||
|
form.fields['sub_part'].queryset = sub_part_query
|
||||||
|
|
||||||
return form
|
return form
|
||||||
|
|
||||||
def get_initial(self):
|
def get_initial(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user