From 7881a67db4798e48e85369a0a17bcea37fa5e7d6 Mon Sep 17 00:00:00 2001 From: Oliver Walters Date: Sun, 26 May 2019 00:01:01 +1000 Subject: [PATCH] Calculate stock based on variant stock if part is a template --- InvenTree/part/models.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/InvenTree/part/models.py b/InvenTree/part/models.py index 1511b7a0d8..f7b577ccea 100644 --- a/InvenTree/part/models.py +++ b/InvenTree/part/models.py @@ -522,7 +522,10 @@ class Part(models.Model): Part may be stored in multiple locations """ - total = self.stock_entries.aggregate(total=Sum('quantity'))['total'] + if self.is_template: + total = sum([variant.total_stock for variant in self.variants.all()]) + else: + total = self.stock_entries.aggregate(total=Sum('quantity'))['total'] if total: return total