Ensure that a StockItem is not already allocated to a Build

This commit is contained in:
Oliver Walters 2019-05-06 07:58:20 +10:00
parent 7c70b31af4
commit ff14b0b363

View File

@ -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