Add transactions to snapshot page

This commit is contained in:
Edgar P. Burkhart 2022-05-22 10:15:42 +02:00
parent cb458cf472
commit 43aabf051b
Signed by: edpibu
GPG Key ID: 9833D3C5A25BD227
2 changed files with 52 additions and 1 deletions

View File

@ -1,13 +1,25 @@
{% extends "main/base.html" %}
{% load static %}
{% load main_extras %}
{% block link %}
{{ block.super }}
<link rel="stylesheet" href="{% static 'main/css/form.css' %}" type="text/css" />
<link rel="stylesheet" href="{% static 'main/css/table.css' %}" type="text/css" />
{% endblock %}
{% block body %}
<h1>{{ snapshot }}</h1>
{% with sum=snapshot.sum %}
<h1>
{% if snapshot.previous is not None %}
{% if sum == snapshot.diff %}
<i class="fa fa-check green"></i>
{% else %}
<i class="fa fa-xmark red"></i>
{% endif %}
{% endif %}
{{ snapshot }}
</h1>
<form action="{% url 'update_snapshot' snapshot.id %}" method="post">
{% csrf_token %}
@ -23,4 +35,38 @@
</div>
</form>
{% if transactions %}
<h2>Transactions ({{ sum|floatformat:"2g"|pm }} € / {{ snapshot.diff|floatformat:"2g"|pm }} €)</h2>
<div id="transactions" class="table col6">
<div class="header">
<strong class="date center">Date</strong>
<strong class="name">Nom</strong>
<strong class="value center">Valeur</strong>
<strong class="trader center">Commerçant</strong>
<strong class="category center">Catégorie</strong>
<strong class="description">Description</strong>
</div>
{% for trans in transactions %}
<div class="transaction {% cycle 'w' 'g' %}">
<span class="date num center">{{ trans.date|date:"Y-m-d" }}</span>
<span class="name text"><a href="{% url 'transaction' trans.id %}">{{ trans.name }}</a></span>
<span class="value num right">{{ trans.value|floatformat:"2g"|pm }} €</span>
<span class="trader text center">{{ trans.trader|default_if_none:"" }}</span>
<span class="category text center">
{% if trans.category %}
<i class="fa fa-{{ trans.category.icon }}"></i>
<a href="{% url 'category' trans.category.id %}">
{{ trans.category }}
</a>
{% else %}
{% endif %}
</span>
<span class="description text">{{ trans.description }}</span>
</div>
{% endfor %}
</div>
{% endif %}
{% endwith %}
{% endblock %}

View File

@ -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,
},
)