On déplace l'annotation

This commit is contained in:
Tom Hubrecht 2021-07-01 12:01:39 +02:00
parent 44c729dfee
commit bd109be388

View file

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