Add history chart in accounts
This commit is contained in:
parent
3f92a6d2ba
commit
9a2bbcd5c3
2 changed files with 25 additions and 0 deletions
|
@ -11,6 +11,9 @@
|
|||
<link rel="stylesheet"
|
||||
href="{% static 'main/css/table.css' %}"
|
||||
type="text/css"/>
|
||||
<link rel="stylesheet"
|
||||
href="{% static 'main/css/plot.css' %}"
|
||||
type="text/css"/>
|
||||
{% endblock %}
|
||||
{% block body %}
|
||||
<h1>
|
||||
|
@ -27,5 +30,7 @@
|
|||
{% if transactions %}
|
||||
<h2>{% translate "Transactions" %}</h2>
|
||||
{% include "main/table/transaction.html" %}
|
||||
<h2>{% translate "History" %}</h2>
|
||||
{% include "main/plot/history.html" %}
|
||||
{% endif %}
|
||||
{% endblock %}
|
||||
|
|
|
@ -188,12 +188,32 @@ class AccountUpdateView(NummiUpdateView):
|
|||
"account_snapshots", args=(account.pk,)
|
||||
)
|
||||
|
||||
_history = (
|
||||
account.transaction_set.filter(category__budget=True)
|
||||
.values(month=models.functions.TruncMonth("date"))
|
||||
.annotate(
|
||||
sum_p=models.Sum("value", filter=models.Q(value__gt=0)),
|
||||
sum_m=models.Sum("value", filter=models.Q(value__lt=0)),
|
||||
sum=models.Sum("value"),
|
||||
)
|
||||
.order_by("-month")
|
||||
)
|
||||
|
||||
return data | {
|
||||
"transactions": _transactions[:8],
|
||||
"new_snapshot_url": reverse_lazy(
|
||||
"snapshot", kwargs={"account": account.pk}
|
||||
),
|
||||
"snapshots": _snapshots[:8],
|
||||
"history": {
|
||||
"data": _history,
|
||||
"max": max(
|
||||
_history.aggregate(
|
||||
max=models.Max("sum_p", default=0),
|
||||
min=-models.Min("sum_m", default=0),
|
||||
).values(),
|
||||
),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue