diff --git a/src/accounting/report/template_filters.py b/src/accounting/report/template_filters.py
new file mode 100644
index 0000000..53346ec
--- /dev/null
+++ b/src/accounting/report/template_filters.py
@@ -0,0 +1,37 @@
+# The Mia! Accounting Flask Project.
+# Author: imacat@mail.imacat.idv.tw (imacat), 2023/3/7
+
+# Copyright (c) 2023 imacat.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+"""The template filters for the reports.
+
+"""
+from decimal import Decimal
+
+from accounting.template_filters import format_amount as core_format_amount
+
+
+def format_amount(value: Decimal | None) -> str | None:
+ """Formats an amount for the report.
+
+ :param value: The amount.
+ :return: The formatted amount text.
+ """
+ if value is None:
+ return ""
+ is_negative: bool = value < 0
+ formatted: str = core_format_amount(abs(value))
+ if is_negative:
+ formatted = f"({formatted})"
+ return formatted
diff --git a/src/accounting/report/views.py b/src/accounting/report/views.py
index 54e2709..395797c 100644
--- a/src/accounting/report/views.py
+++ b/src/accounting/report/views.py
@@ -24,9 +24,11 @@ from accounting.utils.permission import has_permission, can_view
from .period import Period
from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \
IncomeStatement, BalanceSheet
+from .template_filters import format_amount
bp: Blueprint = Blueprint("report", __name__)
"""The view blueprint for the reports."""
+bp.add_app_template_filter(format_amount, "accounting_report_format_amount")
@bp.get("journal", endpoint="journal-default")
diff --git a/src/accounting/templates/accounting/report/balance-sheet.html b/src/accounting/templates/accounting/report/balance-sheet.html
index d1c9b26..d6373af 100644
--- a/src/accounting/templates/accounting/report/balance-sheet.html
+++ b/src/accounting/templates/accounting/report/balance-sheet.html
@@ -142,14 +142,14 @@ First written: 2023/3/7
{{ account.account.code }}
{{ account.account.title|title }}
-
{{ account.amount|accounting_format_amount }}
+ {{ account.amount|accounting_report_format_amount }}
{% endfor %}
{% endfor %}
{{ A_("Total") }}
-
{{ report.assets.total|accounting_format_amount }}
+
{{ report.assets.total|accounting_report_format_amount }}
{% endif %}
@@ -173,14 +173,14 @@ First written: 2023/3/7
{{ account.account.code }}
{{ account.account.title|title }}
- {{ account.amount|accounting_format_amount }}
+ {{ account.amount|accounting_report_format_amount }}
{% endfor %}
{% endfor %}
{{ A_("Total") }}
-
{{ report.liabilities.total|accounting_format_amount }}
+
{{ report.liabilities.total|accounting_report_format_amount }}
{% endif %}
@@ -202,20 +202,20 @@ First written: 2023/3/7
{{ account.account.code }}
{{ account.account.title|title }}
- {{ account.amount|accounting_format_amount }}
+ {{ account.amount|accounting_report_format_amount }}
{% endfor %}
{% endfor %}
{{ A_("Total") }}
-
{{ report.owner_s_equity.total|accounting_format_amount }}
+
{{ report.owner_s_equity.total|accounting_report_format_amount }}
{% endif %}
{{ A_("Total") }}
-
{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_format_amount }}
+
{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}
@@ -224,14 +224,14 @@ First written: 2023/3/7
{{ A_("Total") }}
-
{{ report.assets.total|accounting_format_amount }}
+
{{ report.assets.total|accounting_report_format_amount }}
{{ A_("Total") }}
-
{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_format_amount }}
+
{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}
diff --git a/src/accounting/templates/accounting/report/income-expenses.html b/src/accounting/templates/accounting/report/income-expenses.html
index 12b3d8b..3bd4ec9 100644
--- a/src/accounting/templates/accounting/report/income-expenses.html
+++ b/src/accounting/templates/accounting/report/income-expenses.html
@@ -171,7 +171,7 @@ First written: 2023/3/5
{{ entry.summary|accounting_default }}
{{ entry.income|accounting_format_amount|accounting_default }}
{{ entry.expense|accounting_format_amount|accounting_default }}
- {{ entry.balance|accounting_format_amount }}
+ {{ entry.balance|accounting_report_format_amount }}
{% endwith %}
{% endif %}
@@ -182,7 +182,7 @@ First written: 2023/3/5
{{ entry.summary|accounting_default }}
{{ entry.income|accounting_format_amount|accounting_default }}
{{ entry.expense|accounting_format_amount|accounting_default }}
- {{ entry.balance|accounting_format_amount }}
+ {{ entry.balance|accounting_report_format_amount }}
{% endfor %}
@@ -193,7 +193,7 @@ First written: 2023/3/5
{{ A_("Total") }}
{{ entry.income|accounting_format_amount }}
{{ entry.expense|accounting_format_amount }}
- {{ entry.balance|accounting_format_amount }}
+ {{ entry.balance|accounting_report_format_amount }}
{% endwith %}
diff --git a/src/accounting/templates/accounting/report/income-statement.html b/src/accounting/templates/accounting/report/income-statement.html
index 661f2e4..1d9c9ce 100644
--- a/src/accounting/templates/accounting/report/income-statement.html
+++ b/src/accounting/templates/accounting/report/income-statement.html
@@ -149,17 +149,17 @@ First written: 2023/3/7
{{ account.account.code }}
{{ account.account.title|title }}
- {{ account.amount|accounting_format_amount }}
+ {{ account.amount|accounting_report_format_amount }}
{% endfor %}
{{ A_("Total") }}
-
{{ subsection.total|accounting_format_amount }}
+
{{ subsection.total|accounting_report_format_amount }}
{% endfor %}
{{ section.accumulated.title|title }}
-
{{ section.accumulated.amount|accounting_format_amount }}
+
{{ section.accumulated.amount|accounting_report_format_amount }}
{% endfor %}
diff --git a/src/accounting/templates/accounting/report/ledger.html b/src/accounting/templates/accounting/report/ledger.html
index 074b7ab..ed0bb27 100644
--- a/src/accounting/templates/accounting/report/ledger.html
+++ b/src/accounting/templates/accounting/report/ledger.html
@@ -169,7 +169,7 @@ First written: 2023/3/5
{{ entry.summary|accounting_default }}
{{ entry.debit|accounting_format_amount|accounting_default }}
{{ entry.credit|accounting_format_amount|accounting_default }}
- {{ entry.balance|accounting_format_amount }}
+ {{ entry.balance|accounting_report_format_amount }}
{% endwith %}
{% endif %}
@@ -179,7 +179,7 @@ First written: 2023/3/5
{{ entry.summary|accounting_default }}
{{ entry.debit|accounting_format_amount|accounting_default }}
{{ entry.credit|accounting_format_amount|accounting_default }}
- {{ entry.balance|accounting_format_amount }}
+ {{ entry.balance|accounting_report_format_amount }}
{% endfor %}
@@ -188,9 +188,9 @@ First written: 2023/3/5
{% endwith %}