From 6e33fa775da91ec886ec8c85e4a7505a4303a69a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Sun, 5 Mar 2023 22:41:00 +0800 Subject: [PATCH] Revised the __query_entries method of the IncomeExpenses report to be clear. --- src/accounting/report/reports.py | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/accounting/report/reports.py b/src/accounting/report/reports.py index d4e2fda..563fc8c 100644 --- a/src/accounting/report/reports.py +++ b/src/accounting/report/reports.py @@ -480,21 +480,20 @@ class IncomeExpenses(JournalEntryReport[IncomeExpensesRow]): :return: The journal entries. """ - conditions1: list[sa.BinaryExpression] \ + conditions: list[sa.BinaryExpression] \ = [JournalEntry.currency_code == self.currency.code, JournalEntry.account_id == self.account.id] if self.period.start is not None: - conditions1.append(Transaction.date >= self.period.start) + conditions.append(Transaction.date >= self.period.start) if self.period.end is not None: - conditions1.append(Transaction.date <= self.period.end) - select1: sa.Select = sa.Select(Transaction.id).join(JournalEntry)\ - .filter(*conditions1) + conditions.append(Transaction.date <= self.period.end) + txn_with_account: sa.Select = sa.Select(Transaction.id).\ + join(JournalEntry).filter(*conditions) - conditions: list[sa.BinaryExpression] \ - = [JournalEntry.transaction_id.in_(select1), - JournalEntry.currency_code == self.currency.code, - JournalEntry.account_id != self.account.id] - return JournalEntry.query.join(Transaction).filter(*conditions)\ + return JournalEntry.query.join(Transaction)\ + .filter(JournalEntry.transaction_id.in_(txn_with_account), + JournalEntry.currency_code == self.currency.code, + JournalEntry.account_id != self.account.id)\ .order_by(Transaction.date, sa.desc(JournalEntry.is_debit), JournalEntry.no)