Add total line in account list on index page

This commit is contained in:
Edgar P. Burkhart 2024-03-23 11:51:37 +01:00
parent 18a58783c8
commit 50ae922a99
Signed by: edpibu
GPG key ID: 9833D3C5A25BD227
5 changed files with 18 additions and 5 deletions

View file

@ -77,10 +77,6 @@ table.full-width col.bar {
background: #eeeeff;
}
}
tfoot {
background: var(--bg-01);
}
}
.calendar {

View file

@ -45,6 +45,9 @@ table {
font-weight: 300;
}
}
tfoot tr:not(.new) {
background: var(--bg-01);
}
}
.date,

View file

@ -41,6 +41,12 @@
{% endfor %}
</tbody>
<tfoot>
<tr>
<td>{{ "functions"|remix }}</td>
<th class="l">{% translate "Total" %}</th>
<td class="value">{{ accounts|balance|value }}</td>
<td></td>
</tr>
<tr class="new">
<td colspan="4">
<a href="{% url "new_account" %}">{% translate "Create account" %}</a>

View file

@ -59,3 +59,10 @@ def css(href):
return mark_safe(
f"""<link rel="stylesheet" href="{static(href)}" type="text/css">"""
)
@register.filter
def balance(accounts):
return sum(
statement.value for acc in accounts if (statement := acc.statement_set.first())
)

View file

@ -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],