From ff14b0b36323ede020647ccb4395badfb95c5102 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 6 May 2019 07:58:20 +1000 Subject: [PATCH] Ensure that a StockItem is not already allocated to a Build --- InvenTree/build/models.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/InvenTree/build/models.py b/InvenTree/build/models.py index 9f54713706..504b57cc75 100644 --- a/InvenTree/build/models.py +++ b/InvenTree/build/models.py @@ -32,7 +32,7 @@ class Build(models.Model): URL: External URL for extra information notes: Text notes """ - + def __str__(self): return "Build {q} x {part}".format(q=self.quantity, part=str(self.part)) @@ -137,6 +137,12 @@ class Build(models.Model): if len(stock) == 1: stock_item = stock[0] + # Check that we have not already allocated this stock-item against this build + build_items = BuildItem.objects.filter(build=self, stock_item=stock_item) + + if len(build_items) > 0: + continue + # Are there any parts available? if stock_item.quantity > 0: # Only take as many as are available