Added monthly sums for tags

This commit is contained in:
fleaz 2021-12-20 01:37:29 +01:00
parent 73c2986940
commit 8ccf2f2646
3 changed files with 26 additions and 2 deletions

View file

@ -66,8 +66,13 @@ def tags():
def tag(name):
tag = session.query(Tag).filter(Tag.name == name).first()
transactions = session.query(Transaction).filter(Transaction.tags.any(id=tag.id)).all()
sum_months = session.query(func.sum(Transaction.amount).label("amount"), func.strftime("%Y-%m",Transaction.date).label("month")).filter(Transaction.tags.any(id=tag.id)).group_by("month").all()
months = []
for m in sum_months:
months.append({'amount' : format_amount(m['amount']),
"month": m['month']})
return render_template("tag.html", tag=tag, transactions=transactions)
return render_template("tag.html", tag=tag, months=months, transactions=transactions)
@app.route("/tag/<name>/delete")

View file

@ -6,7 +6,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Schmeckels</title>
<link href="https://unpkg.com/tailwindcss/dist/tailwind.min.css" rel="stylesheet">
<script src="https://cdn.tailwindcss.com"></script>
<link href="/static/style.css" rel="stylesheet">
<style>
{% block style %} {% endblock %}

View file

@ -4,6 +4,25 @@
<h1>Transaktionen aus {{ tag.name }}</h1>
<h2>Monatliche ausgaben</h2>
<table class="table-auto">
<thead>
<tr>
<th class="px-4 py-2">Monat</th>
<th class="px-4 py-2">Summe</th>
</tr>
</thead>
<tbody>
{% for m in months %}
<tr>
<td class="border px-4 py-2">{{ m.month }}</td>
<td class="border px-4 py-2">{{ m.amount }}</td>
</tr>
{% endfor %}
</tbody>
</table>
<table class="table-auto">
<thead>
<tr>