Add missing data for snapshot html plot

This commit is contained in:
Edgar P. Burkhart 2023-01-03 18:36:02 +01:00
parent 344a1558af
commit 60c875c2a5
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227

View file

@ -231,6 +231,30 @@ class SnapshotUpdateView(NummiUpdateView):
data["transactions_url"] = reverse_lazy(
"snapshot_transactions", args=(snapshot.pk,)
)
if _transactions:
data["categories"] = (
_transactions.values(
"category", "category__name", "category__icon"
)
.annotate(
sum=models.Sum("value"),
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
sum_p=models.Sum("value", filter=models.Q(value__gt=0)),
)
.order_by("-sum")
)
data["cat_lim"] = max(
map(
lambda x: abs(x) if x else 0,
data["categories"]
.aggregate(
max=models.Max("sum_p"),
min=models.Min("sum_m"),
)
.values(),
)
)
data["cat_lim_m"] = -data["cat_lim"]
return data | {
"new_transaction_url": reverse_lazy(