From 43aabf051bd2d3759fe0cdeb8a56413ef76dcba6 Mon Sep 17 00:00:00 2001 From: "Edgar P. Burkhart" Date: Sun, 22 May 2022 10:15:42 +0200 Subject: [PATCH] Add transactions to snapshot page --- nummi/main/templates/main/snapshot.html | 48 ++++++++++++++++++++++++- nummi/main/views.py | 5 +++ 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/nummi/main/templates/main/snapshot.html b/nummi/main/templates/main/snapshot.html index b6d60aa..54289d6 100644 --- a/nummi/main/templates/main/snapshot.html +++ b/nummi/main/templates/main/snapshot.html @@ -1,13 +1,25 @@ {% extends "main/base.html" %} {% load static %} +{% load main_extras %} {% block link %} {{ block.super }} + {% endblock %} {% block body %} -

{{ snapshot }}

+{% with sum=snapshot.sum %} +

+ {% if snapshot.previous is not None %} + {% if sum == snapshot.diff %} + + {% else %} + + {% endif %} + {% endif %} + {{ snapshot }} +

{% csrf_token %} @@ -23,4 +35,38 @@
+{% if transactions %} +

Transactions ({{ sum|floatformat:"2g"|pm }} € / {{ snapshot.diff|floatformat:"2g"|pm }} €)

+ +
+
+ Date + Nom + Valeur + Commerçant + Catégorie + Description +
+ {% for trans in transactions %} +
+ {{ trans.date|date:"Y-m-d" }} + {{ trans.name }} + {{ trans.value|floatformat:"2g"|pm }} € + {{ trans.trader|default_if_none:"–" }} + + {% if trans.category %} + + + {{ trans.category }} + + {% else %} + – + {% endif %} + + {{ trans.description }} +
+ {% endfor %} +
+{% endif %} +{% endwith %} {% endblock %} diff --git a/nummi/main/views.py b/nummi/main/views.py index 0489190..724a404 100644 --- a/nummi/main/views.py +++ b/nummi/main/views.py @@ -120,14 +120,19 @@ def update_category(request, uuid): def snapshot(request, date=None): if date is None: _snapshot = Snapshot() + _transactions = None else: _snapshot = get_object_or_404(Snapshot, date=date) + _transactions = Transaction.objects.filter( + date__lt=_snapshot.date, date__gte=_snapshot.previous.date + ) return render( request, "main/snapshot.html", { "snapshot": _snapshot, "form": SnapshotForm(instance=_snapshot), + "transactions": _transactions, }, )