Limit user choices in the manual part allocation form

This commit is contained in:
Oliver Walters 2019-05-10 19:12:56 +10:00
parent bbf46c4580
commit 763e0a991c
2 changed files with 11 additions and 1 deletions

View File

@ -149,7 +149,7 @@ class Build(models.Model):
# 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()])
stock = stock.filter(location__in=[loc for loc in self.take_from.getUniqueChildren()])
# Only one StockItem to choose from? Default to that one!
if len(stock) == 1:

View File

@ -374,6 +374,16 @@ class BuildItemCreate(AjaxCreateView):
query = query.filter(part=part_id)
if build_id is not None:
try:
build = Build.objects.get(id=build_id)
if build.take_from is not None:
# Limit query to stock items that are downstream of the 'take_from' location
query = query.filter(location__in=[loc for loc in build.take_from.getUniqueChildren()])
except Build.DoesNotExist:
pass
# Exclude StockItem objects which are already allocated to this build and part
query = query.exclude(id__in=[item.stock_item.id for item in BuildItem.objects.filter(build=build_id, stock_item__part=part_id)])