From bd109be3888a8cc4b6af395285a7cc894f2c6ac5 Mon Sep 17 00:00:00 2001 From: Tom Hubrecht Date: Thu, 1 Jul 2021 12:01:39 +0200 Subject: [PATCH] =?UTF-8?q?On=20d=C3=A9place=20l'annotation?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kfet/views.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/kfet/views.py b/kfet/views.py index c7ca72f3..58e981a0 100644 --- a/kfet/views.py +++ b/kfet/views.py @@ -2473,18 +2473,16 @@ class SalesStatList(BaseListView): super() .get_queryset() .filter(type=Operation.PURCHASE, canceled_at=None, article__isnull=False) + .values_list("article__name") + .annotate(Sum("article_nb")) ) def get_context_data(self, **kwargs): ctx = super().get_context_data(**kwargs) scale = MonthScale(n_steps=self.kwargs.get("n_months", 12), last=True) - qs = self.get_queryset() articles = list(Article.objects.order_by("name")) indexes = {a.name: index for index, a in enumerate(articles)} - ventes = scale.chunkify_qs( - qs.values_list("article__name").annotate(Sum("article_nb")), - field="group__at", - ) + ventes = scale.chunkify_qs(self.get_queryset(), field="group__at") ctx["header"] = ["Mois"] + [a.name for a in articles] ctx["ventes"] = []