From d16d9307f41850241e854b90b4f95aa965d7e924 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Mon, 25 Apr 2022 22:24:01 +0200 Subject: [PATCH] Add average basket --- src/purchase/templates/purchase/reports.html | 7 +++++-- src/purchase/views/reports.py | 5 ++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/purchase/templates/purchase/reports.html b/src/purchase/templates/purchase/reports.html index 19b6b00..be6188e 100644 --- a/src/purchase/templates/purchase/reports.html +++ b/src/purchase/templates/purchase/reports.html @@ -3,8 +3,11 @@ {% block content %}

Reports

-

Total turnover

- +

General

+

Products

{% include "purchase/snippets/report_products.html" %} diff --git a/src/purchase/views/reports.py b/src/purchase/views/reports.py index a3964b1..50782c5 100644 --- a/src/purchase/views/reports.py +++ b/src/purchase/views/reports.py @@ -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(),