From 8ccf2f2646865a9cf586e3ccf444b8375e70a576 Mon Sep 17 00:00:00 2001 From: fleaz Date: Mon, 20 Dec 2021 01:37:29 +0100 Subject: [PATCH] Added monthly sums for tags --- schmeckels/serve.py | 7 ++++++- schmeckels/templates/base.html | 2 +- schmeckels/templates/tag.html | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/schmeckels/serve.py b/schmeckels/serve.py index 34c762b..978ae58 100644 --- a/schmeckels/serve.py +++ b/schmeckels/serve.py @@ -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//delete") diff --git a/schmeckels/templates/base.html b/schmeckels/templates/base.html index 2680087..05ae8ec 100644 --- a/schmeckels/templates/base.html +++ b/schmeckels/templates/base.html @@ -6,7 +6,7 @@ Schmeckels - +