On déplace l'annotation
This commit is contained in:
parent
44c729dfee
commit
bd109be388
1 changed files with 3 additions and 5 deletions
|
@ -2473,18 +2473,16 @@ class SalesStatList(BaseListView):
|
||||||
super()
|
super()
|
||||||
.get_queryset()
|
.get_queryset()
|
||||||
.filter(type=Operation.PURCHASE, canceled_at=None, article__isnull=False)
|
.filter(type=Operation.PURCHASE, canceled_at=None, article__isnull=False)
|
||||||
|
.values_list("article__name")
|
||||||
|
.annotate(Sum("article_nb"))
|
||||||
)
|
)
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
ctx = super().get_context_data(**kwargs)
|
ctx = super().get_context_data(**kwargs)
|
||||||
scale = MonthScale(n_steps=self.kwargs.get("n_months", 12), last=True)
|
scale = MonthScale(n_steps=self.kwargs.get("n_months", 12), last=True)
|
||||||
qs = self.get_queryset()
|
|
||||||
articles = list(Article.objects.order_by("name"))
|
articles = list(Article.objects.order_by("name"))
|
||||||
indexes = {a.name: index for index, a in enumerate(articles)}
|
indexes = {a.name: index for index, a in enumerate(articles)}
|
||||||
ventes = scale.chunkify_qs(
|
ventes = scale.chunkify_qs(self.get_queryset(), field="group__at")
|
||||||
qs.values_list("article__name").annotate(Sum("article_nb")),
|
|
||||||
field="group__at",
|
|
||||||
)
|
|
||||||
|
|
||||||
ctx["header"] = ["Mois"] + [a.name for a in articles]
|
ctx["header"] = ["Mois"] + [a.name for a in articles]
|
||||||
ctx["ventes"] = []
|
ctx["ventes"] = []
|
||||||
|
|
Loading…
Reference in a new issue