06/05 Optimize app: add quick filter for transaction page

This commit is contained in:
2026-06-05 13:04:04 -04:00
parent 8a4eeac781
commit 3a113c89c4
2 changed files with 40 additions and 1 deletions
+22 -1
View File
@@ -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'])
+18
View File
@@ -23,6 +23,24 @@
</a>
</div>
<!-- Quick date filters -->
<div class="d-flex gap-1 mb-3 align-items-center flex-wrap">
<a href="{{ url_for('transactions.index', tab=tab, date_from=this_month_from, date_to=this_month_to, q=search, category_id=category_id, account_id=account_id) }}"
class="btn btn-sm {% if active_quick == 'this_month' %}btn-primary{% else %}btn-outline-secondary{% endif %}" style="font-size:12px;">
<i class="bi bi-calendar-check me-1"></i>This Month
</a>
<a href="{{ url_for('transactions.index', tab=tab, date_from=last_month_from, date_to=last_month_to, q=search, category_id=category_id, account_id=account_id) }}"
class="btn btn-sm {% if active_quick == 'last_month' %}btn-primary{% else %}btn-outline-secondary{% endif %}" style="font-size:12px;">
<i class="bi bi-calendar-minus me-1"></i>Last Month
</a>
{% if active_quick %}
<a href="{{ url_for('transactions.index', tab=tab, q=search, category_id=category_id, account_id=account_id) }}"
class="btn btn-sm btn-outline-secondary" style="font-size:12px;" title="Clear date filter">
<i class="bi bi-x-lg"></i>
</a>
{% endif %}
</div>
<!-- Filters -->
<div class="pcard pcard-sm mb-3">
<form method="GET" action="{{ url_for('transactions.index') }}" class="row g-2 align-items-end">