From 3d245c7ce3c6e75beb63878a71734333ef4a7281 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 28 Jun 2020 19:14:51 +1000 Subject: [PATCH] Improve logic of "quantity_to_order" function --- InvenTree/part/models.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 47e22fc938..550645cb68 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -594,7 +594,16 @@ class Part(MPTTModel): def quantity_to_order(self): """ Return the quantity needing to be ordered for this part. """ - required = -1 * self.net_stock + # How many do we need to have "on hand" at any point? + required = self.net_stock - self.minimum_stock + + if required < 0: + return abs(required) + + # Do not need to order any + return 0 + + required = self.net_stock return max(required, 0) @property