fix: handle None as amount in fmt_money (#17395)

This commit is contained in:
Ankush Menat 2022-07-04 16:27:57 +05:30 committed by GitHub
parent bdc90a2938
commit 4e6ea5b554
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

View file

@ -95,6 +95,7 @@ class TestFmtMoney(unittest.TestCase):
def test_custom_fmt_money_format(self):
self.assertEqual(fmt_money(100000, format="#,###.##"), "100,000.00")
self.assertEqual(fmt_money(None, format="#,###.##"), "0.00")
if __name__ == "__main__":

View file

@ -1111,7 +1111,7 @@ def parse_val(v):
def fmt_money(
amount: str | float | int,
amount: str | float | int | None,
precision: int | None = None,
currency: str | None = None,
format: str | None = None,
@ -1135,6 +1135,9 @@ def fmt_money(
if isinstance(amount, str):
amount = flt(amount, precision)
if amount is None:
amount = 0
if decimal_str:
decimals_after = str(round(amount % 1, precision))
parts = decimals_after.split(".")