From 21b479e2534290dfa37de2f8c8f01b1070df5483 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Thu, 22 Jul 2021 07:12:13 +0200 Subject: [PATCH] only count paid orders --- src/shop/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/shop/models.py b/src/shop/models.py index 8ed335b8..06b89b33 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -397,7 +397,8 @@ class ProductCategory(CreatedUpdatedModel, UUIDModel): class ProductStatsManager(models.Manager): def with_ticket_stats(self): return ( - self.annotate(total_units_sold=Sum("orderproductrelation__quantity")) + self.filter(orderproductrelation__order__paid=True) + .annotate(total_units_sold=Sum("orderproductrelation__quantity")) .annotate(profit=F("price") - F("cost")) .annotate(total_revenue=F("price") * F("total_units_sold")) .annotate(total_cost=F("cost") * F("total_units_sold"))