From 35881616325b890662da5f949741c32fa9ce0d90 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Fri, 10 May 2019 19:03:45 +1000 Subject: [PATCH] Build.getAutoAllocations() only selects parts from the designation location --- InvenTree/build/forms.py | 1 + InvenTree/build/models.py | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/InvenTree/build/forms.py b/InvenTree/build/forms.py index 57c31ff1db..66ec98ac77 100644 --- a/InvenTree/build/forms.py +++ b/InvenTree/build/forms.py @@ -21,6 +21,7 @@ class EditBuildForm(HelperForm): 'title', 'part', 'quantity', + 'take_from', 'batch', 'URL', 'notes', diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 4a9084825f..35ea81c213 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -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]