From 1c4362c42a3c50e88d62b4812f16fbb6ebef9610 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Mon, 5 Jun 2023 13:49:39 +1000 Subject: [PATCH] Prevent div-by-zero error (#4967) (#4968) - 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 (cherry picked from commit d8965c6c2ba68a657b6cd489bd265bd63530f403) Co-authored-by: Oliver --- InvenTree/part/models.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 89bbc5df26..3204acd1ce 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1293,6 +1293,11 @@ class Part(InvenTreeBarcodeMixin, 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