From d8965c6c2ba68a657b6cd489bd265bd63530f403 Mon Sep 17 00:00:00 2001 From: Oliver Date: Mon, 5 Jun 2023 13:40:50 +1000 Subject: [PATCH] Prevent div-by-zero error (#4967) - Div-by-zero could occur when calculating how many items can be built for a part - Might result if (somehow) the BomItem has a quantity of zero --- InvenTree/part/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 46affda7cf..984016ede0 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1302,6 +1302,11 @@ class Part(InvenTreeBarcodeMixin, InvenTreeNotesMixin, MetadataMixin, MPTTModel) ) for item in queryset.all(): + + if item.quantity <= 0: + # Ignore zero-quantity items + continue + # Iterate through each item in the queryset, work out the limiting quantity quantity = item.available_stock + item.substitute_stock