diff --git a/src/accounting/report/reports/journal.py b/src/accounting/report/reports/journal.py index 0552d3a..f62cc8b 100644 --- a/src/accounting/report/reports/journal.py +++ b/src/accounting/report/reports/journal.py @@ -49,7 +49,7 @@ class ReportEntry: """The journal entry.""" self.transaction: Transaction | None = None """The transaction.""" - self.currency: Currency | None = None + self.currency: Currency = entry.currency """The account.""" self.account: Account = entry.account """The account.""" @@ -154,12 +154,8 @@ def populate_entries(entries: list[ReportEntry]) -> None: transactions: dict[int, Transaction] \ = {x.id: x for x in Transaction.query.filter( Transaction.id.in_({x.entry.transaction_id for x in entries}))} - currencies: dict[int, Currency] \ - = {x.code: x for x in Currency.query.filter( - Currency.code.in_({x.entry.currency_code for x in entries}))} for entry in entries: entry.transaction = transactions[entry.entry.transaction_id] - entry.currency = currencies[entry.entry.currency_code] def get_csv_rows(entries: list[ReportEntry]) -> list[CSVRow]: @@ -208,7 +204,8 @@ class Journal(BaseReport): .order_by(Transaction.date, JournalEntry.is_debit.desc(), JournalEntry.no) - .options(selectinload(JournalEntry.account)).all()] + .options(selectinload(JournalEntry.account), + selectinload(JournalEntry.currency)).all()] def csv(self) -> Response: """Returns the report as CSV for download. diff --git a/src/accounting/report/reports/search.py b/src/accounting/report/reports/search.py index 44f76fe..03cd7ca 100644 --- a/src/accounting/report/reports/search.py +++ b/src/accounting/report/reports/search.py @@ -69,7 +69,8 @@ class EntryCollector: pass conditions.append(sa.or_(*sub_conditions)) return [ReportEntry(x) for x in JournalEntry.query.filter(*conditions) - .options(selectinload(JournalEntry.account))] + .options(selectinload(JournalEntry.account), + selectinload(JournalEntry.currency))] @staticmethod def __get_account_condition(k: str) -> sa.Select: