Fixed the styles of the negative numbers in the reports with red and braced absolute values.

This commit is contained in:
依瑪貓 2023-03-07 23:21:18 +08:00
parent 3c200d0dc6
commit 24315b8203
6 changed files with 59 additions and 20 deletions

View File

@ -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

View File

@ -24,9 +24,11 @@ from accounting.utils.permission import has_permission, can_view
from .period import Period from .period import Period
from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \ from .reports import Journal, Ledger, IncomeExpenses, TrialBalance, \
IncomeStatement, BalanceSheet IncomeStatement, BalanceSheet
from .template_filters import format_amount
bp: Blueprint = Blueprint("report", __name__) bp: Blueprint = Blueprint("report", __name__)
"""The view blueprint for the reports.""" """The view blueprint for the reports."""
bp.add_app_template_filter(format_amount, "accounting_report_format_amount")
@bp.get("journal", endpoint="journal-default") @bp.get("journal", endpoint="journal-default")

View File

@ -142,14 +142,14 @@ First written: 2023/3/7
<span class="d-none d-md-inline">{{ account.account.code }}</span> <span class="d-none d-md-inline">{{ account.account.code }}</span>
{{ account.account.title|title }} {{ account.account.title|title }}
</div> </div>
<div class="accounting-amount">{{ account.amount|accounting_format_amount }}</div> <div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</div> </div>
<div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total"> <div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ report.assets.total|accounting_format_amount }}</div> <div class="accounting-amount {% if report.assets.total < 0 %} text-danger {% endif %}">{{ report.assets.total|accounting_report_format_amount }}</div>
</div> </div>
{% endif %} {% endif %}
</div> </div>
@ -173,14 +173,14 @@ First written: 2023/3/7
<span class="d-none d-md-inline">{{ account.account.code }}</span> <span class="d-none d-md-inline">{{ account.account.code }}</span>
{{ account.account.title|title }} {{ account.account.title|title }}
</div> </div>
<div class="accounting-amount">{{ account.amount|accounting_format_amount }}</div> <div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</div> </div>
<div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal"> <div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ report.liabilities.total|accounting_format_amount }}</div> <div class="accounting-amount {% if report.liabilities.total < 0 %} text-danger {% endif %}">{{ report.liabilities.total|accounting_report_format_amount }}</div>
</div> </div>
{% endif %} {% endif %}
@ -202,20 +202,20 @@ First written: 2023/3/7
<span class="d-none d-md-inline">{{ account.account.code }}</span> <span class="d-none d-md-inline">{{ account.account.code }}</span>
{{ account.account.title|title }} {{ account.account.title|title }}
</div> </div>
<div class="accounting-amount">{{ account.amount|accounting_format_amount }}</div> <div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
{% endfor %} {% endfor %}
</div> </div>
<div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal"> <div class="d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-subtotal">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ report.owner_s_equity.total|accounting_format_amount }}</div> <div class="accounting-amount {% if report.owner_s_equity.total < 0 %} text-danger {% endif %}">{{ report.owner_s_equity.total|accounting_report_format_amount }}</div>
</div> </div>
{% endif %} {% endif %}
<div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total"> <div class="d-md-none d-flex justify-content-between accounting-report-table-row accounting-balance-sheet-total">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_format_amount }}</div> <div class="accounting-amount {% if report.liabilities.total < 0 %} text-danger {% endif %}">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}</div>
</div> </div>
</div> </div>
</div> </div>
@ -224,14 +224,14 @@ First written: 2023/3/7
<div class="col-sm-6"> <div class="col-sm-6">
<div class="d-flex justify-content-between accounting-balance-sheet-total"> <div class="d-flex justify-content-between accounting-balance-sheet-total">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ report.assets.total|accounting_format_amount }}</div> <div class="accounting-amount {% if report.assets.total < 0 %} text-danger {% endif %}">{{ report.assets.total|accounting_report_format_amount }}</div>
</div> </div>
</div> </div>
<div class="col-sm-6"> <div class="col-sm-6">
<div class="d-flex justify-content-between accounting-balance-sheet-total"> <div class="d-flex justify-content-between accounting-balance-sheet-total">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_format_amount }}</div> <div class="accounting-amount {% if report.liabilities.total + report.owner_s_equity.total < 0 %} text-danger {% endif %}">{{ (report.liabilities.total + report.owner_s_equity.total)|accounting_report_format_amount }}</div>
</div> </div>
</div> </div>
</div> </div>

View File

@ -171,7 +171,7 @@ First written: 2023/3/5
<div>{{ entry.summary|accounting_default }}</div> <div>{{ entry.summary|accounting_default }}</div>
<div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</div> </div>
{% endwith %} {% endwith %}
{% endif %} {% endif %}
@ -182,7 +182,7 @@ First written: 2023/3/5
<div>{{ entry.summary|accounting_default }}</div> <div>{{ entry.summary|accounting_default }}</div>
<div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.income|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.expense|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -193,7 +193,7 @@ First written: 2023/3/5
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ entry.income|accounting_format_amount }}</div> <div class="accounting-amount">{{ entry.income|accounting_format_amount }}</div>
<div class="accounting-amount">{{ entry.expense|accounting_format_amount }}</div> <div class="accounting-amount">{{ entry.expense|accounting_format_amount }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</div> </div>
</div> </div>
{% endwith %} {% endwith %}

View File

@ -149,17 +149,17 @@ First written: 2023/3/7
<span class="d-none d-md-inline">{{ account.account.code }}</span> <span class="d-none d-md-inline">{{ account.account.code }}</span>
{{ account.account.title|title }} {{ account.account.title|title }}
</div> </div>
<div class="accounting-amount">{{ account.amount|accounting_format_amount }}</div> <div class="accounting-amount {% if account.amount < 0 %} text-danger {% endif %}">{{ account.amount|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
<div class="accounting-report-table-row accounting-income-statement-subtotal"> <div class="accounting-report-table-row accounting-income-statement-subtotal">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ subsection.total|accounting_format_amount }}</div> <div class="accounting-amount {% if subsection.total < 0 %} text-danger {% endif %}">{{ subsection.total|accounting_report_format_amount }}</div>
</div> </div>
{% endfor %} {% endfor %}
<div class="accounting-report-table-row accounting-income-statement-total"> <div class="accounting-report-table-row accounting-income-statement-total">
<div>{{ section.accumulated.title|title }}</div> <div>{{ section.accumulated.title|title }}</div>
<div class="accounting-amount">{{ section.accumulated.amount|accounting_format_amount }}</div> <div class="accounting-amount {% if section.accumulated.amount < 0 %} text-danger {% endif %}">{{ section.accumulated.amount|accounting_report_format_amount }}</div>
</div> </div>
{% endfor %} {% endfor %}
</div> </div>

View File

@ -169,7 +169,7 @@ First written: 2023/3/5
<div>{{ entry.summary|accounting_default }}</div> <div>{{ entry.summary|accounting_default }}</div>
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</div> </div>
{% endwith %} {% endwith %}
{% endif %} {% endif %}
@ -179,7 +179,7 @@ First written: 2023/3/5
<div>{{ entry.summary|accounting_default }}</div> <div>{{ entry.summary|accounting_default }}</div>
<div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.debit|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div> <div class="accounting-amount">{{ entry.credit|accounting_format_amount|accounting_default }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</a> </a>
{% endfor %} {% endfor %}
</div> </div>
@ -188,9 +188,9 @@ First written: 2023/3/5
<div class="accounting-report-table-footer"> <div class="accounting-report-table-footer">
<div class="accounting-report-table-row"> <div class="accounting-report-table-row">
<div>{{ A_("Total") }}</div> <div>{{ A_("Total") }}</div>
<div class="accounting-amount">{{ entry.debit|accounting_format_amount }}</div> <div class="accounting-amount">{{ entry.debit|accounting_default }}</div>
<div class="accounting-amount">{{ entry.credit|accounting_format_amount }}</div> <div class="accounting-amount">{{ entry.credit|accounting_default }}</div>
<div class="accounting-amount">{{ entry.balance|accounting_format_amount }}</div> <div class="accounting-amount {% if entry.balance < 0 %} text-danger {% endif %}">{{ entry.balance|accounting_report_format_amount }}</div>
</div> </div>
</div> </div>
{% endwith %} {% endwith %}