realise there can be more than one thing on each ticket, fix
This commit is contained in:
parent
0973709ef0
commit
ec816a5c11
|
@ -14,7 +14,8 @@
|
|||
<thead>
|
||||
<tr>
|
||||
<th>Product</th>
|
||||
<th class="text-center">Number Sold</th>
|
||||
<th class="text-center">Orders</th>
|
||||
<th class="text-center">Units Sold</th>
|
||||
<th class="text-right">Revenue</th>
|
||||
<th class="text-right">Cost</th>
|
||||
<th class="text-right">Profit</th>
|
||||
|
@ -25,7 +26,8 @@
|
|||
{% for p in product_list %}
|
||||
<tr>
|
||||
<td>{{ p.name }}</td>
|
||||
<td class="text-center">{{ p.ticket_count }}</td>
|
||||
<td class="text-center">{{ p.order_set.count }}</td>
|
||||
<td class="text-center">{{ p.total_units_sold }}</td>
|
||||
<td class="text-right">{{ p.price|floatformat:"2" }} DKK</td>
|
||||
<td class="text-right">{{ p.cost|floatformat:"2" }} DKK</td>
|
||||
<td class="text-right">{{ p.profit|floatformat:"2" }} DKK</td>
|
||||
|
|
|
@ -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):
|
||||
|
|
Loading…
Reference in a new issue