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"] = []