Add average basket

This commit is contained in:
Gabriel Augendre 2022-04-25 22:24:01 +02:00
parent be6ec786db
commit d16d9307f4
2 changed files with 9 additions and 3 deletions

View file

@ -3,8 +3,11 @@
{% block content %}
<h1>Reports</h1>
<h2>Total turnover</h2>
<ul><li>{{ total|currency }}</li></ul>
<h2>General</h2>
<ul>
<li>Total turnover: {{ total|currency }}</li>
<li>Average basket: {{ average_basket|currency }}</li>
</ul>
<h2>Products</h2>
{% include "purchase/snippets/report_products.html" %}

View file

@ -1,4 +1,4 @@
from django.db.models import Sum
from django.db.models import Avg, Sum
from django.views.generic import TemplateView
from purchase.models import Basket, PaymentMethod, Product
@ -14,6 +14,9 @@ class ReportsView(ProtectedViewsMixin, TemplateView):
context.update(
{
"total": Basket.objects.priced().aggregate(total=Sum("price"))["total"],
"average_basket": Basket.objects.priced().aggregate(avg=Avg("price"))[
"avg"
],
"products": Product.objects.with_turnover().with_sold(),
"payment_methods": PaymentMethod.objects.with_turnover().with_sold(),
"no_payment_method": Basket.objects.no_payment_method().priced(),