diff --git a/nummi/main/templates/main/account_form.html b/nummi/main/templates/main/account_form.html
index cd424f9..7967eb0 100644
--- a/nummi/main/templates/main/account_form.html
+++ b/nummi/main/templates/main/account_form.html
@@ -11,6 +11,9 @@
+
{% endblock %}
{% block body %}
@@ -27,5 +30,7 @@
{% if transactions %}
{% translate "Transactions" %}
{% include "main/table/transaction.html" %}
+ {% translate "History" %}
+ {% include "main/plot/history.html" %}
{% endif %}
{% endblock %}
diff --git a/nummi/main/views.py b/nummi/main/views.py
index f462130..e6f35b1 100644
--- a/nummi/main/views.py
+++ b/nummi/main/views.py
@@ -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(),
+ ),
+ },
}