Merge pull request #850 from SchrodingersGat/bom-division-fix

Fix for case where BOM item quantity is zero
This commit is contained in:
Oliver 2020-06-04 11:42:39 +10:00 committed by GitHub
commit c1da4d5207
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -643,11 +643,20 @@ class Part(MPTTModel):
# 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'):
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)
if total is None or n < total:
total = n
if total is None:
total = 0
return max(total, 0)
@property