diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 35ea81c213..028f6b0f4c 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -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: diff --git a/InvenTree/build/views.py b/InvenTree/build/views.py index 79e3819df5..85d07858fb 100644 --- a/InvenTree/build/views.py +++ b/InvenTree/build/views.py @@ -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)])