From bf34d6c3bfff38a31e637780a0e7930e78ebf72d Mon Sep 17 00:00:00 2001 From: RunasSudo Date: Wed, 3 Apr 2024 21:08:52 +1100 Subject: [PATCH] Sort transactions newest to oldest So newest (and most relevant) transactions appear on page 1 #3 --- austax/views.py | 4 ++-- drcr/journal/views.py | 6 +++--- drcr/statements/views.py | 8 ++++++-- drcr/views.py | 8 ++++---- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/austax/views.py b/austax/views.py index ecc3474..edb79ff 100644 --- a/austax/views.py +++ b/austax/views.py @@ -1,5 +1,5 @@ # 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 # 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') 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: adjustments = adjustments.where(CGTCostAdjustment.account == request.args['account']) if 'quantity' in request.args: diff --git a/drcr/journal/views.py b/drcr/journal/views.py index bf5327f..b855878 100644 --- a/drcr/journal/views.py +++ b/drcr/journal/views.py @@ -1,5 +1,5 @@ # 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 # 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') 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( 'journal/journal.html', @@ -125,7 +125,7 @@ def journal_edit_transaction(): @app.route('/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 transactions = all_transactions() diff --git a/drcr/statements/views.py b/drcr/statements/views.py index 448716f..10e929c 100644 --- a/drcr/statements/views.py +++ b/drcr/statements/views.py @@ -1,5 +1,5 @@ # 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 # 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) statement_lines = db.select(StatementLine).options( 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: 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: 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': return render_template('statements/import_preview.html', statement_lines=statement_lines) diff --git a/drcr/views.py b/drcr/views.py index 781588f..fcdea35 100644 --- a/drcr/views.py +++ b/drcr/views.py @@ -1,5 +1,5 @@ # 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 # it under the terms of the GNU Affero General Public License as published by @@ -64,7 +64,7 @@ def general_ledger(): return render_template( 'general_ledger.html', 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') @@ -87,14 +87,14 @@ def account_transactions(): 'transactions_commodity_detail.html', account=request.args['account'], running_total=Balance(), - transactions=sorted(transactions, key=lambda t: t.dt) + transactions=sorted(transactions, key=lambda t: t.dt, reverse=True) ) else: return render_template( 'transactions.html', account=request.args['account'], 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')