06/02 Optimize app
This commit is contained in:
@@ -157,6 +157,37 @@ def delete(id):
|
||||
return redirect(url_for('accounts.index'))
|
||||
|
||||
|
||||
@accounts_bp.route('/<int:id>/payments')
|
||||
@login_required
|
||||
def payments(id):
|
||||
account = db.get_or_404(Account, id)
|
||||
page = request.args.get('page', 1, type=int)
|
||||
|
||||
pagination = Transaction.query.filter(
|
||||
Transaction.transaction_type == 'transfer',
|
||||
Transaction.to_account_id == account.id,
|
||||
).order_by(Transaction.date.desc(), Transaction.id.desc()).paginate(
|
||||
page=page, per_page=30, error_out=False
|
||||
)
|
||||
|
||||
# Running total paid this month
|
||||
today = date.today()
|
||||
paid_this_month = db.session.query(
|
||||
func.coalesce(func.sum(Transaction.amount), 0)
|
||||
).filter(
|
||||
Transaction.transaction_type == 'transfer',
|
||||
Transaction.to_account_id == account.id,
|
||||
extract('year', Transaction.date) == today.year,
|
||||
extract('month', Transaction.date) == today.month,
|
||||
).scalar()
|
||||
|
||||
return render_template('accounts/payments.html',
|
||||
account=account,
|
||||
pagination=pagination,
|
||||
payments=pagination.items,
|
||||
paid_this_month=float(paid_this_month))
|
||||
|
||||
|
||||
@accounts_bp.route('/<int:id>/adjust', methods=['GET', 'POST'])
|
||||
@login_required
|
||||
def adjust_balance(id):
|
||||
|
||||
Reference in New Issue
Block a user