From d11e2d226c3a8559b6656a0dc80af50a0ca6c89b Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 22 Dec 2022 12:42:34 +1100 Subject: [PATCH] Display last stocktake information on part page --- InvenTree/part/models.py | 6 ++++++ InvenTree/part/templates/part/part_base.html | 14 ++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 5a9c504414..b5693df6cd 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -2161,6 +2161,12 @@ class Part(InvenTreeBarcodeMixin, MetadataMixin, MPTTModel): return params + @property + def latest_stocktake(self): + """Return the latest PartStocktake object associated with this part (if one exists)""" + + return self.stocktakes.order_by('-pk').first() + @property def has_variants(self): """Check if this Part object has variants underneath it.""" diff --git a/InvenTree/part/templates/part/part_base.html b/InvenTree/part/templates/part/part_base.html index 1e005b1adb..d21f8c2ee5 100644 --- a/InvenTree/part/templates/part/part_base.html +++ b/InvenTree/part/templates/part/part_base.html @@ -338,6 +338,20 @@ {% endif %} {% endwith %} + {% with part.latest_stocktake as stocktake %} + {% if stocktake %} + + + {% trans "Last Stocktake" %} + + {% decimal stocktake.quantity %} + + {{ stocktake.user.username }} + + + + {% endif %} + {% endwith %} {% with part.get_latest_serial_number as sn %} {% if part.trackable and sn %}