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.

This commit is contained in:
依瑪貓 2023-03-06 02:32:02 +08:00
parent dd05478bf3
commit 5d4effa360
2 changed files with 13 additions and 13 deletions

View File

@ -47,28 +47,28 @@ class JournalRow(ReportRow):
""" """
self.entry: JournalEntry = entry self.entry: JournalEntry = entry
"""The journal 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 self.transaction: Transaction | None = None
"""The transaction.""" """The transaction."""
self.currency: Currency | None = None self.currency: Currency | None = None
"""The currency.""" """The currency."""
self.account: Account | None = None self.account: Account | None = None
"""The account.""" """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]: def as_dict(self) -> dict[str, t.Any]:
return {"Date": self.transaction.date, return {"Date": self.transaction.date,
"Currency": self.currency_code, "Currency": self.currency.code,
"Account": str(self.account).title(), "Account": str(self.account).title(),
"Summary": self.summary, "Summary": self.summary,
"Debit": self.amount if self.is_debit else None, "Debit": self.debit,
"Credit": None if self.is_debit else self.amount, "Credit": self.credit,
"Note": self.transaction.note} "Note": self.transaction.note}

View File

@ -109,8 +109,8 @@ First written: 2023/3/4
<td>{{ item.currency.name }}</td> <td>{{ item.currency.name }}</td>
<td>{{ item.account.title|title }}</td> <td>{{ item.account.title|title }}</td>
<td>{{ item.summary|accounting_default }}</td> <td>{{ item.summary|accounting_default }}</td>
<td class="accounting-amount">{{ "" if not item.is_debit else item.amount|accounting_format_amount }}</td> <td class="accounting-amount">{{ item.debit|accounting_format_amount|accounting_default }}</td>
<td class="accounting-amount">{{ "" if item.is_debit else item.amount|accounting_format_amount }}</td> <td class="accounting-amount">{{ item.credit|accounting_format_amount|accounting_default }}</td>
</tr> </tr>
{% endfor %} {% endfor %}
</tbody> </tbody>