From 9efdd836f4adbee6f1765235cb4b74a91b954149 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Mon, 10 Jun 2019 21:56:50 +1000 Subject: [PATCH] Tweak the 'on_order' calculation --- InvenTree/company/models.py | 2 +- InvenTree/part/models.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/InvenTree/company/models.py b/InvenTree/company/models.py index 33841d59db..069ecb0ad6 100644 --- a/InvenTree/company/models.py +++ b/InvenTree/company/models.py @@ -327,7 +327,7 @@ class SupplierPart(models.Model): if q is None or r is None: return 0 else: - return q - r + return max(q-r, 0) def purchase_orders(self): diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index f1294a972d..6749fa0ad6 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -809,7 +809,7 @@ class Part(models.Model): def on_order(self): """ Return the total number of items on order for this part. """ - return sum([part.on_order() for part in self.supplier_parts.all()]) + return sum([part.on_order() for part in self.supplier_parts.all().prefetch_related('purchase_order_line_items')]) def attach_file(instance, filename):