Revised the __query_entries method of the IncomeExpenses report to be clear.

This commit is contained in:
依瑪貓 2023-03-05 22:41:00 +08:00
parent e244ff70e6
commit 6e33fa775d

View File

@ -480,21 +480,20 @@ class IncomeExpenses(JournalEntryReport[IncomeExpensesRow]):
:return: The journal entries. :return: The journal entries.
""" """
conditions1: list[sa.BinaryExpression] \ conditions: list[sa.BinaryExpression] \
= [JournalEntry.currency_code == self.currency.code, = [JournalEntry.currency_code == self.currency.code,
JournalEntry.account_id == self.account.id] JournalEntry.account_id == self.account.id]
if self.period.start is not None: 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: if self.period.end is not None:
conditions1.append(Transaction.date <= self.period.end) conditions.append(Transaction.date <= self.period.end)
select1: sa.Select = sa.Select(Transaction.id).join(JournalEntry)\ txn_with_account: sa.Select = sa.Select(Transaction.id).\
.filter(*conditions1) join(JournalEntry).filter(*conditions)
conditions: list[sa.BinaryExpression] \ return JournalEntry.query.join(Transaction)\
= [JournalEntry.transaction_id.in_(select1), .filter(JournalEntry.transaction_id.in_(txn_with_account),
JournalEntry.currency_code == self.currency.code, JournalEntry.currency_code == self.currency.code,
JournalEntry.account_id != self.account.id] JournalEntry.account_id != self.account.id)\
return JournalEntry.query.join(Transaction).filter(*conditions)\
.order_by(Transaction.date, .order_by(Transaction.date,
sa.desc(JournalEntry.is_debit), sa.desc(JournalEntry.is_debit),
JournalEntry.no) JournalEntry.no)