Calculate stock based on variant stock if part is a template

This commit is contained in:
Oliver Walters 2019-05-26 00:01:01 +10:00
parent c45a506a10
commit 7881a67db4

View File

@ -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