only count paid orders

This commit is contained in:
Thomas Steen Rasmussen 2021-07-22 07:12:13 +02:00
parent 41467447a8
commit 21b479e253

View file

@ -397,7 +397,8 @@ class ProductCategory(CreatedUpdatedModel, UUIDModel):
class ProductStatsManager(models.Manager): class ProductStatsManager(models.Manager):
def with_ticket_stats(self): def with_ticket_stats(self):
return ( 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(profit=F("price") - F("cost"))
.annotate(total_revenue=F("price") * F("total_units_sold")) .annotate(total_revenue=F("price") * F("total_units_sold"))
.annotate(total_cost=F("cost") * F("total_units_sold")) .annotate(total_cost=F("cost") * F("total_units_sold"))