reports: Balance.format(None) uses accounting formats.

This commit is contained in:
Brett Smith 2020-06-21 11:39:31 -04:00
parent 5e9e11923e
commit 42d2002fda
2 changed files with 7 additions and 5 deletions

View file

@ -231,8 +231,9 @@ class Balance(Mapping[str, data.Amount]):
amounts = list(balance.values()) amounts = list(balance.values())
amounts.sort(key=lambda amt: (-abs(amt.number), amt.currency)) amounts.sort(key=lambda amt: (-abs(amt.number), amt.currency))
return sep.join( return sep.join(
babel.numbers.format_currency(amt.number, amt.currency, fmt) babel.numbers.format_currency(
for amt in amounts amt.number, amt.currency, fmt, format_type='accounting',
) for amt in amounts
) )

View file

@ -419,10 +419,11 @@ def test_format_sep(sep):
balance = core.Balance(amounts_from_map(mapping)) balance = core.Balance(amounts_from_map(mapping))
assert balance.format(sep=sep) == expected assert balance.format(sep=sep) == expected
def test_format_none(): @pytest.mark.parametrize('number', [65000, -77000])
args = (65000, 'BRL') def test_format_none(number):
args = (number, 'BRL')
balance = core.Balance([testutil.Amount(*args)]) balance = core.Balance([testutil.Amount(*args)])
expected = babel.numbers.format_currency(*args) expected = babel.numbers.format_currency(*args, format_type='accounting')
assert balance.format(None) == expected assert balance.format(None) == expected
@pytest.mark.parametrize('empty', [ @pytest.mark.parametrize('empty', [