06/05 Optimize app: add quick filter for transaction page
This commit is contained in:
@@ -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'])
|
||||
|
||||
Reference in New Issue
Block a user