06/05 Optimize app: filters

This commit is contained in:
2026-06-05 15:06:14 -04:00
parent 1a4e68b422
commit db44d6057b
2 changed files with 130 additions and 8 deletions
+17 -1
View File
@@ -71,6 +71,8 @@ def index():
account_id = request.args.get('account_id', '', type=str)
date_from = request.args.get('date_from', '')
date_to = request.args.get('date_to', '')
amount_min = request.args.get('amount_min', '')
amount_max = request.args.get('amount_max', '')
from datetime import timedelta
today = date.today()
@@ -93,7 +95,12 @@ def index():
).order_by(Transaction.date.desc(), Transaction.id.desc())
if search:
query = query.filter(Transaction.description.ilike(f'%{search}%'))
query = query.filter(
or_(
Transaction.description.ilike(f'%{search}%'),
Transaction.notes.ilike(f'%{search}%'),
)
)
try:
if category_id:
query = query.filter(Transaction.category_id == int(category_id))
@@ -111,6 +118,13 @@ def index():
query = query.filter(Transaction.date <= datetime.strptime(date_to, '%Y-%m-%d').date())
except ValueError:
pass
try:
if amount_min:
query = query.filter(Transaction.amount >= float(amount_min))
if amount_max:
query = query.filter(Transaction.amount <= float(amount_max))
except (ValueError, TypeError):
pass
pagination = query.paginate(page=page, per_page=30, error_out=False)
@@ -137,6 +151,8 @@ def index():
account_id=account_id,
date_from=date_from,
date_to=date_to,
amount_min=amount_min,
amount_max=amount_max,
active_quick=active_quick,
this_month_from=this_month_from,
this_month_to=this_month_to,