From 3a113c89c4996d530c5dfe121eb3de7316b09521 Mon Sep 17 00:00:00 2001 From: NguyenND Date: Fri, 5 Jun 2026 13:04:04 -0400 Subject: [PATCH] 06/05 Optimize app: add quick filter for transaction page --- app/routes/transactions.py | 23 ++++++++++++++++++++++- app/templates/transactions/index.html | 18 ++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) diff --git a/app/routes/transactions.py b/app/routes/transactions.py index 0cff435..3b5cd69 100644 --- a/app/routes/transactions.py +++ b/app/routes/transactions.py @@ -72,6 +72,22 @@ def index(): date_from = request.args.get('date_from', '') date_to = request.args.get('date_to', '') + from datetime import timedelta + today = date.today() + this_month_from = today.replace(day=1).strftime('%Y-%m-%d') + this_month_to = today.strftime('%Y-%m-%d') + last_month_last = today.replace(day=1) - timedelta(days=1) + last_month_first = last_month_last.replace(day=1) + last_month_from = last_month_first.strftime('%Y-%m-%d') + last_month_to = last_month_last.strftime('%Y-%m-%d') + + if date_from == this_month_from and date_to == this_month_to: + active_quick = 'this_month' + elif date_from == last_month_from and date_to == last_month_to: + active_quick = 'last_month' + else: + active_quick = '' + query = Transaction.query.filter( Transaction.transaction_type == tab ).order_by(Transaction.date.desc(), Transaction.id.desc()) @@ -120,7 +136,12 @@ def index(): category_id=category_id, account_id=account_id, date_from=date_from, - date_to=date_to) + date_to=date_to, + active_quick=active_quick, + this_month_from=this_month_from, + this_month_to=this_month_to, + last_month_from=last_month_from, + last_month_to=last_month_to) @transactions_bp.route('/new', methods=['GET', 'POST']) diff --git a/app/templates/transactions/index.html b/app/templates/transactions/index.html index ad1c808..1d62731 100644 --- a/app/templates/transactions/index.html +++ b/app/templates/transactions/index.html @@ -23,6 +23,24 @@ + +
+ + This Month + + + Last Month + + {% if active_quick %} + + + + {% endif %} +
+