Changed the format_amount template filter to return None when the value is None.

This commit is contained in:
依瑪貓 2023-03-06 01:16:07 +08:00
parent cd49ca44b1
commit a7bcf4b5c1

View File

@ -25,13 +25,15 @@ from flask_babel import get_locale
from accounting.locale import gettext
def format_amount(value: Decimal | None) -> str:
def format_amount(value: Decimal | None) -> str | None:
"""Formats an amount for readability.
:param value: The amount.
:return: The formatted amount text.
"""
if value is None or value == 0:
if value is None:
return None
if value == 0:
return "-"
whole: int = int(value)
frac: Decimal = (value - whole).normalize()