Build.getAutoAllocations() only selects parts from the designation location

This commit is contained in:
Oliver Walters 2019-05-10 19:03:45 +10:00
parent 468322fa9d
commit 3588161632
2 changed files with 6 additions and 0 deletions

View File

@ -21,6 +21,7 @@ class EditBuildForm(HelperForm):
'title',
'part',
'quantity',
'take_from',
'batch',
'URL',
'notes',

View File

@ -146,6 +146,11 @@ class Build(models.Model):
stock = StockItem.objects.filter(part=item.sub_part)
# Ensure that the available stock items are in the correct location
if self.take_from is not None:
# Filter for stock that is located downstream of the designated location
stock = stock.filter(location__in=[cat for cat in self.take_from.getUniqueChildren()])
# Only one StockItem to choose from? Default to that one!
if len(stock) == 1:
stock_item = stock[0]