Fix for case where BOM item quantity is zero

This commit is contained in:
Oliver Walters 2020-06-04 11:37:55 +10:00
parent 7c7055c0a0
commit a3c0d35b20

View File

@ -643,11 +643,20 @@ class Part(MPTTModel):
# Calculate the minimum number of parts that can be built using each sub-part # Calculate the minimum number of parts that can be built using each sub-part
for item in self.bom_items.all().prefetch_related('sub_part__stock_items'): for item in self.bom_items.all().prefetch_related('sub_part__stock_items'):
stock = item.sub_part.available_stock stock = item.sub_part.available_stock
# If (by some chance) we get here but the BOM item quantity is invalid,
# ignore!
if item.quantity <= 0:
continue
n = int(stock / item.quantity) n = int(stock / item.quantity)
if total is None or n < total: if total is None or n < total:
total = n total = n
if total is None:
total = 0
return max(total, 0) return max(total, 0)
@property @property