From 50ae922a9992d59602695e8569ffcf42c56f2e97 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sat, 23 Mar 2024 11:51:37 +0100 Subject: [PATCH] Add total line in account list on index page --- nummi/main/static/main/css/plot.css | 4 ---- nummi/main/static/main/css/table.css | 3 +++ nummi/main/templates/main/index.html | 6 ++++++ nummi/main/templatetags/main_extras.py | 7 +++++++ nummi/main/views.py | 3 ++- 5 files changed, 18 insertions(+), 5 deletions(-) diff --git a/nummi/main/static/main/css/plot.css b/nummi/main/static/main/css/plot.css index 4a9eb36..3ec218b 100644 --- a/nummi/main/static/main/css/plot.css +++ b/nummi/main/static/main/css/plot.css @@ -77,10 +77,6 @@ table.full-width col.bar { background: #eeeeff; } } - - tfoot { - background: var(--bg-01); - } } .calendar { diff --git a/nummi/main/static/main/css/table.css b/nummi/main/static/main/css/table.css index c2c9fec..e93c777 100644 --- a/nummi/main/static/main/css/table.css +++ b/nummi/main/static/main/css/table.css @@ -45,6 +45,9 @@ table { font-weight: 300; } } + tfoot tr:not(.new) { + background: var(--bg-01); + } } .date, diff --git a/nummi/main/templates/main/index.html b/nummi/main/templates/main/index.html index 1c278b0..19a5b54 100644 --- a/nummi/main/templates/main/index.html +++ b/nummi/main/templates/main/index.html @@ -41,6 +41,12 @@ {% endfor %} + + {{ "functions"|remix }} + {% translate "Total" %} + {{ accounts|balance|value }} + + {% translate "Create account" %} diff --git a/nummi/main/templatetags/main_extras.py b/nummi/main/templatetags/main_extras.py index fd29a10..8234b3f 100644 --- a/nummi/main/templatetags/main_extras.py +++ b/nummi/main/templatetags/main_extras.py @@ -59,3 +59,10 @@ def css(href): return mark_safe( f"""""" ) + + +@register.filter +def balance(accounts): + return sum( + statement.value for acc in accounts if (statement := acc.statement_set.first()) + ) diff --git a/nummi/main/views.py b/nummi/main/views.py index a6361ab..72e6840 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -26,9 +26,10 @@ class IndexView(LoginRequiredMixin, TemplateView): _max = 8 _transactions = Transaction.objects.filter(user=self.request.user) _statements = Statement.objects.filter(user=self.request.user) + _accounts = Account.objects.filter(user=self.request.user) res = { - "accounts": Account.objects.filter(user=self.request.user), + "accounts": _accounts, "transactions": _transactions[:_max], "categories": Category.objects.filter(user=self.request.user), "statements": _statements[:_max],