From 39723b1299e1a17fc6675ee5a098c4f36fbeda22 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 19:14:07 +0800 Subject: [PATCH] Removed the lazy setting from the account relationship of the JournalEntry data model. It results in problems in the income and expense report. --- src/accounting/models.py | 2 +- tests/testlib_txn.py | 80 ++++++++++++++++++++-------------------- 2 files changed, 41 insertions(+), 41 deletions(-) diff --git a/src/accounting/models.py b/src/accounting/models.py index d0c88b4..6d358c7 100644 --- a/src/accounting/models.py +++ b/src/accounting/models.py @@ -655,7 +655,7 @@ class JournalEntry(db.Model): onupdate="CASCADE"), nullable=False) """The account ID.""" - account = db.relationship(Account, back_populates="entries", lazy=False) + account = db.relationship(Account, back_populates="entries") """The account.""" summary = db.Column(db.String, nullable=True) """The summary.""" diff --git a/tests/testlib_txn.py b/tests/testlib_txn.py index da675d2..f327487 100644 --- a/tests/testlib_txn.py +++ b/tests/testlib_txn.py @@ -137,48 +137,48 @@ def get_unchanged_update_form(txn_id: int, app: Flask, csrf_token: str) \ assert txn is not None currencies: list[TransactionCurrency] = txn.currencies - form: dict[str, str] = {"csrf_token": csrf_token, - "next": NEXT_URI, - "date": txn.date, - "note": " \n \n\n " if txn.note is None - else f"\n \n\n \n \n{txn.note} \n\n "} - currency_indices_used: set[int] = set() - currency_no: int = 0 - for currency in currencies: - currency_index: int = __get_new_index(currency_indices_used) - currency_no = currency_no + 3 + randbelow(3) - currency_prefix: str = f"currency-{currency_index}" - form[f"{currency_prefix}-no"] = str(currency_no) - form[f"{currency_prefix}-code"] = currency.code - entry_indices_used: set[int] - entry_no: int - prefix: str + form: dict[str, str] = {"csrf_token": csrf_token, + "next": NEXT_URI, + "date": txn.date, + "note": " \n \n\n " if txn.note is None + else f"\n \n\n \n \n{txn.note} \n\n "} + currency_indices_used: set[int] = set() + currency_no: int = 0 + for currency in currencies: + currency_index: int = __get_new_index(currency_indices_used) + currency_no = currency_no + 3 + randbelow(3) + currency_prefix: str = f"currency-{currency_index}" + form[f"{currency_prefix}-no"] = str(currency_no) + form[f"{currency_prefix}-code"] = currency.code + entry_indices_used: set[int] + entry_no: int + prefix: str - entry_indices_used = set() - entry_no = 0 - for entry in currency.debit: - entry_index: int = __get_new_index(entry_indices_used) - entry_no = entry_no + 3 + randbelow(3) - prefix = f"{currency_prefix}-debit-{entry_index}" - form[f"{prefix}-eid"] = str(entry.id) - form[f"{prefix}-no"] = str(entry_no) - form[f"{prefix}-account_code"] = entry.account.code - form[f"{prefix}-summary"] \ - = " " if entry.summary is None else f" {entry.summary} " - form[f"{prefix}-amount"] = str(entry.amount) + entry_indices_used = set() + entry_no = 0 + for entry in currency.debit: + entry_index: int = __get_new_index(entry_indices_used) + entry_no = entry_no + 3 + randbelow(3) + prefix = f"{currency_prefix}-debit-{entry_index}" + form[f"{prefix}-eid"] = str(entry.id) + form[f"{prefix}-no"] = str(entry_no) + form[f"{prefix}-account_code"] = entry.account.code + form[f"{prefix}-summary"] \ + = " " if entry.summary is None else f" {entry.summary} " + form[f"{prefix}-amount"] = str(entry.amount) - entry_indices_used = set() - entry_no = 0 - for entry in currency.credit: - entry_index: int = __get_new_index(entry_indices_used) - entry_no = entry_no + 3 + randbelow(3) - prefix = f"{currency_prefix}-credit-{entry_index}" - form[f"{prefix}-eid"] = str(entry.id) - form[f"{prefix}-no"] = str(entry_no) - form[f"{prefix}-account_code"] = entry.account.code - form[f"{prefix}-summary"] \ - = " " if entry.summary is None else f" {entry.summary} " - form[f"{prefix}-amount"] = str(entry.amount) + entry_indices_used = set() + entry_no = 0 + for entry in currency.credit: + entry_index: int = __get_new_index(entry_indices_used) + entry_no = entry_no + 3 + randbelow(3) + prefix = f"{currency_prefix}-credit-{entry_index}" + form[f"{prefix}-eid"] = str(entry.id) + form[f"{prefix}-no"] = str(entry_no) + form[f"{prefix}-account_code"] = entry.account.code + form[f"{prefix}-summary"] \ + = " " if entry.summary is None else f" {entry.summary} " + form[f"{prefix}-amount"] = str(entry.amount) return form