From ec816a5c118292786da48f4fad06fe730f5f147a Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Wed, 21 Jul 2021 23:14:48 +0200 Subject: [PATCH] realise there can be more than one thing on each ticket, fix --- src/backoffice/templates/ticket_stats_detail.html | 6 ++++-- src/shop/models.py | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/backoffice/templates/ticket_stats_detail.html b/src/backoffice/templates/ticket_stats_detail.html index 5a8838e2..9637a194 100644 --- a/src/backoffice/templates/ticket_stats_detail.html +++ b/src/backoffice/templates/ticket_stats_detail.html @@ -14,7 +14,8 @@ Product - Number Sold + Orders + Units Sold Revenue Cost Profit @@ -25,7 +26,8 @@ {% for p in product_list %} {{ p.name }} - {{ p.ticket_count }} + {{ p.order_set.count }} + {{ p.total_units_sold }} {{ p.price|floatformat:"2" }} DKK {{ p.cost|floatformat:"2" }} DKK {{ p.profit|floatformat:"2" }} DKK diff --git a/src/shop/models.py b/src/shop/models.py index 24f69d17..efbd3665 100644 --- a/src/shop/models.py +++ b/src/shop/models.py @@ -7,7 +7,7 @@ from django.contrib import messages from django.contrib.postgres.fields import DateTimeRangeField from django.core.exceptions import ValidationError from django.db import models -from django.db.models.aggregates import Count, Sum +from django.db.models.aggregates import Sum from django.urls import reverse_lazy from django.utils import timezone from django.utils.dateparse import parse_datetime @@ -396,7 +396,7 @@ class ProductCategory(CreatedUpdatedModel, UUIDModel): class ProductStatsManager(models.Manager): def with_ticket_stats(self): - return self.annotate(ticket_count=Count("shopticket")).exclude(ticket_count=0) + return self.annotate(total_units_sold=Sum("orderproductrelation__quantity")) class Product(CreatedUpdatedModel, UUIDModel):