From fcc35f226030589bded2c5c51e645aa73f3369ca Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Wed, 17 Feb 2021 13:14:27 +1100 Subject: [PATCH] Fix display of parts currently being built --- InvenTree/part/models.py | 18 ++++++++++++------ InvenTree/part/templates/part/part_base.html | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 82a7073612..0257caee0c 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -1094,16 +1094,22 @@ class Part(MPTTModel): @property def quantity_being_built(self): - """ Return the current number of parts currently being built + """ + Return the current number of parts currently being built. + + Note: This is the total quantity of Build orders, *not* the number of build outputs. + In this fashion, it is the "projected" quantity of builds """ - stock_items = self.stock_items.filter(is_building=True) + builds = self.active_builds - query = stock_items.aggregate( - quantity=Coalesce(Sum('quantity'), Decimal(0)) - ) + quantity = 0 - return query['quantity'] + for build in builds: + # The remaining items in the build + quantity += build.remaining + + return quantity def build_order_allocations(self): """ diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 57821b4a89..1221c271b6 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -164,7 +164,7 @@ {% if quantity_being_built > 0 %} - {% trans "Underway" %} + {% trans "Building" %} {% decimal quantity_being_built %} {% endif %}