Sort transactions newest to oldest

So newest (and most relevant) transactions appear on page 1
#3
This commit is contained in:
RunasSudo 2024-04-03 21:08:52 +11:00
parent 128054d965
commit bf34d6c3bf
Signed by: RunasSudo
GPG Key ID: 7234E476BF21C61A
4 changed files with 15 additions and 11 deletions

View File

@ -1,5 +1,5 @@
# DrCr: Web-based double-entry bookkeeping framework # DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo) # Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -29,7 +29,7 @@ from math import copysign
@app.route('/tax/cgt-adjustments') @app.route('/tax/cgt-adjustments')
def cgt_adjustments(): def cgt_adjustments():
adjustments = db.select(CGTCostAdjustment).order_by(CGTCostAdjustment.dt, CGTCostAdjustment.account) adjustments = db.select(CGTCostAdjustment).order_by(CGTCostAdjustment.dt.desc(), CGTCostAdjustment.account)
if 'account' in request.args: if 'account' in request.args:
adjustments = adjustments.where(CGTCostAdjustment.account == request.args['account']) adjustments = adjustments.where(CGTCostAdjustment.account == request.args['account'])
if 'quantity' in request.args: if 'quantity' in request.args:

View File

@ -1,5 +1,5 @@
# DrCr: Web-based double-entry bookkeeping framework # DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo) # Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -27,7 +27,7 @@ from datetime import datetime
@app.route('/journal') @app.route('/journal')
def journal(): def journal():
transactions = db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings)).order_by(Transaction.dt)).all() transactions = db.session.scalars(db.select(Transaction).options(db.selectinload(Transaction.postings)).order_by(Transaction.dt.desc())).all()
return render_template( return render_template(
'journal/journal.html', 'journal/journal.html',
@ -125,7 +125,7 @@ def journal_edit_transaction():
@app.route('/balance-assertions') @app.route('/balance-assertions')
def balance_assertions(): def balance_assertions():
assertions = db.session.scalars(db.select(BalanceAssertion).order_by(BalanceAssertion.dt)).all() assertions = db.session.scalars(db.select(BalanceAssertion).order_by(BalanceAssertion.dt.desc())).all()
# Check assertion status # Check assertion status
transactions = all_transactions() transactions = all_transactions()

View File

@ -1,5 +1,5 @@
# DrCr: Web-based double-entry bookkeeping framework # DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo) # Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -29,7 +29,7 @@ def statement_lines():
# JOIN all associated postings (called in is_complex/charge_account) # JOIN all associated postings (called in is_complex/charge_account)
statement_lines = db.select(StatementLine).options( statement_lines = db.select(StatementLine).options(
db.joinedload(StatementLine.reconciliation).joinedload(StatementLineReconciliation.posting).joinedload(Posting.transaction).joinedload(Transaction.postings) db.joinedload(StatementLine.reconciliation).joinedload(StatementLineReconciliation.posting).joinedload(Posting.transaction).joinedload(Transaction.postings)
).order_by(StatementLine.dt) ).order_by(StatementLine.dt.desc())
if 'account' in request.args: if 'account' in request.args:
statement_lines = statement_lines.where(StatementLine.source_account == request.args['account']) statement_lines = statement_lines.where(StatementLine.source_account == request.args['account'])
@ -188,6 +188,10 @@ def statement_lines_import():
for statement_line in statement_lines: for statement_line in statement_lines:
statement_line.source_account = request.form['source-account'] statement_line.source_account = request.form['source-account']
# Ignore pending, etc.
# FIXME: This needs to be customisable
statement_lines = [l for l in statement_lines if 'PENDING' not in l.description]
if request.form['action'] == 'preview': if request.form['action'] == 'preview':
return render_template('statements/import_preview.html', statement_lines=statement_lines) return render_template('statements/import_preview.html', statement_lines=statement_lines)

View File

@ -1,5 +1,5 @@
# DrCr: Web-based double-entry bookkeeping framework # DrCr: Web-based double-entry bookkeeping framework
# Copyright (C) 2022–2023 Lee Yingtong Li (RunasSudo) # Copyright (C) 2022–2024 Lee Yingtong Li (RunasSudo)
# #
# This program is free software: you can redistribute it and/or modify # This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as published by # it under the terms of the GNU Affero General Public License as published by
@ -64,7 +64,7 @@ def general_ledger():
return render_template( return render_template(
'general_ledger.html', 'general_ledger.html',
commodity_detail=request.args.get('commodity_detail', '0') == '1', commodity_detail=request.args.get('commodity_detail', '0') == '1',
transactions=sorted(all_transactions(), key=lambda t: t.dt) transactions=sorted(all_transactions(), key=lambda t: t.dt, reverse=True)
) )
@app.route('/trial-balance') @app.route('/trial-balance')
@ -87,14 +87,14 @@ def account_transactions():
'transactions_commodity_detail.html', 'transactions_commodity_detail.html',
account=request.args['account'], account=request.args['account'],
running_total=Balance(), running_total=Balance(),
transactions=sorted(transactions, key=lambda t: t.dt) transactions=sorted(transactions, key=lambda t: t.dt, reverse=True)
) )
else: else:
return render_template( return render_template(
'transactions.html', 'transactions.html',
account=request.args['account'], account=request.args['account'],
running_total=Amount(0, '$'), running_total=Amount(0, '$'),
transactions=sorted(transactions, key=lambda t: t.dt) transactions=sorted(transactions, key=lambda t: t.dt, reverse=True)
) )
@app.route('/balance-sheet') @app.route('/balance-sheet')