mirror of
https://github.com/inventree/InvenTree.git
synced 2025-06-18 04:55:44 +00:00
Cleanup get_required_parts function
This commit is contained in:
@ -584,7 +584,7 @@ class BuildItem(models.Model):
|
||||
errors = {}
|
||||
|
||||
try:
|
||||
if self.stock_item.part not in self.build.part.required_parts():
|
||||
if self.stock_item.part not in self.build.part.getRequiredParts(recursive=False):
|
||||
errors['stock_item'] = [_("Selected stock item not found in BOM for part '{p}'".format(p=self.build.part.full_name))]
|
||||
|
||||
if self.quantity > self.stock_item.quantity:
|
||||
|
@ -493,7 +493,7 @@ class BuildItemDelete(AjaxDeleteView):
|
||||
|
||||
class BuildItemCreate(AjaxCreateView):
|
||||
"""
|
||||
View for allocating a StockItems to a build output.
|
||||
View for allocating a StockItems to a build output.
|
||||
"""
|
||||
|
||||
model = BuildItem
|
||||
@ -591,13 +591,20 @@ class BuildItemCreate(AjaxCreateView):
|
||||
pass
|
||||
|
||||
# Exclude StockItem objects which are already allocated to this build and part
|
||||
stock_filter = stock_filter.exclude(id__in=[item.stock_item.id for item in BuildItem.objects.filter(build=build_id, stock_item__part=part_id)])
|
||||
stock_filter = stock_filter.exclude(
|
||||
id__in=[
|
||||
item.stock_item.id for item in BuildItem.objects.filter(build=build_id, stock_item__part=part_id)
|
||||
]
|
||||
)
|
||||
|
||||
except Part.DoesNotExist:
|
||||
self.part = None
|
||||
pass
|
||||
|
||||
form.fields['stock_item'].query = stock_filter
|
||||
else:
|
||||
self.part = None
|
||||
|
||||
form.fields['stock_item'].queryset = stock_filter
|
||||
|
||||
self.available_stock = stock_filter.all()
|
||||
|
||||
@ -708,13 +715,12 @@ class BuildItemEdit(AjaxUpdateView):
|
||||
}
|
||||
|
||||
def get_form(self):
|
||||
""" Create form for editing a BuildItem.
|
||||
"""
|
||||
Create form for editing a BuildItem.
|
||||
|
||||
- Limit the StockItem options to items that match the part
|
||||
"""
|
||||
|
||||
build_item = self.get_object()
|
||||
|
||||
form = super(BuildItemEdit, self).get_form()
|
||||
|
||||
# Hide fields which we do not wish the user to edit
|
||||
|
Reference in New Issue
Block a user