fix: handle None as amount in fmt_money (#17395)
This commit is contained in:
parent
bdc90a2938
commit
4e6ea5b554
2 changed files with 5 additions and 1 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
|
|
@ -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(".")
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue