Add category plot on history pages
This commit is contained in:
parent
681651109a
commit
b828324220
6 changed files with 50 additions and 25 deletions
|
@ -1,5 +1,5 @@
|
|||
from account.models import Account
|
||||
from django.db import models
|
||||
from category.utils import get_categories
|
||||
from django.shortcuts import get_object_or_404
|
||||
from django.urls import reverse_lazy
|
||||
from main.views import NummiCreateView, NummiDeleteView, NummiListView, NummiUpdateView
|
||||
|
@ -43,24 +43,7 @@ class StatementUpdateView(NummiUpdateView):
|
|||
|
||||
_transactions = statement.transaction_set.all()
|
||||
if _transactions:
|
||||
_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["categories"] = {
|
||||
"data": _categories,
|
||||
"max": max(
|
||||
_categories.aggregate(
|
||||
max=models.Max("sum_p", default=0),
|
||||
min=models.Min("sum_m", default=0),
|
||||
).values(),
|
||||
),
|
||||
}
|
||||
data["categories"] = get_categories(_transactions)
|
||||
|
||||
return data | {
|
||||
"account": statement.account,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue