From 5d4effa360e2a9c92af72cab3b359835b1750a8e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BE=9D=E7=91=AA=E8=B2=93?= Date: Mon, 6 Mar 2023 02:32:02 +0800 Subject: [PATCH] Added the "debit" and "credit" properties to, and removed the "is_debit" property from the JournalRow row, to reduce the amount of logic in the template of the journal. --- src/accounting/report/report_rows.py | 22 +++++++++---------- .../templates/accounting/report/journal.html | 4 ++-- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/accounting/report/report_rows.py b/src/accounting/report/report_rows.py index 36677be..2eb81d1 100644 --- a/src/accounting/report/report_rows.py +++ b/src/accounting/report/report_rows.py @@ -47,28 +47,28 @@ class JournalRow(ReportRow): """ self.entry: JournalEntry = entry """The journal entry.""" - self.summary: str | None = entry.summary - """The summary.""" - self.currency_code: str = entry.currency_code - """The currency code.""" - self.is_debit: bool = entry.is_debit - """True for a debit journal entry, or False for a credit entry.""" - self.amount: Decimal = entry.amount - """The amount.""" self.transaction: Transaction | None = None """The transaction.""" self.currency: Currency | None = None """The currency.""" self.account: Account | None = None """The account.""" + self.summary: str | None = entry.summary + """The summary.""" + self.debit: Decimal | None = entry.amount if entry.is_debit else None + """The debit amount.""" + self.credit: Decimal | None = None if entry.is_debit else entry.amount + """The credit amount.""" + self.amount: Decimal = entry.amount + """The amount.""" def as_dict(self) -> dict[str, t.Any]: return {"Date": self.transaction.date, - "Currency": self.currency_code, + "Currency": self.currency.code, "Account": str(self.account).title(), "Summary": self.summary, - "Debit": self.amount if self.is_debit else None, - "Credit": None if self.is_debit else self.amount, + "Debit": self.debit, + "Credit": self.credit, "Note": self.transaction.note} diff --git a/src/accounting/templates/accounting/report/journal.html b/src/accounting/templates/accounting/report/journal.html index f383e66..0839ec7 100644 --- a/src/accounting/templates/accounting/report/journal.html +++ b/src/accounting/templates/accounting/report/journal.html @@ -109,8 +109,8 @@ First written: 2023/3/4 {{ item.currency.name }} {{ item.account.title|title }} {{ item.summary|accounting_default }} - {{ "" if not item.is_debit else item.amount|accounting_format_amount }} - {{ "" if item.is_debit else item.amount|accounting_format_amount }} + {{ item.debit|accounting_format_amount|accounting_default }} + {{ item.credit|accounting_format_amount|accounting_default }} {% endfor %}