From c3fd55ec15b796db29550bb2fd4ccfe8100c2dcf 2020-05-19 19:22:00 From: Brett Smith Date: 2020-05-19 19:22:00 Subject: [PATCH] historical: Beancount can handle commas in amounts. And having it looks nicer, is more consistent with our historical books, is less code for me, and is no more trouble for the user. --- diff --git a/oxrlib/commands/historical.py b/oxrlib/commands/historical.py index 3dee51fd69fcd53e2c0f44832ac698e58945b7af..b887f3675479738d5d0a419ccedd33cadd416f5b 100644 --- a/oxrlib/commands/historical.py +++ b/oxrlib/commands/historical.py @@ -176,13 +176,13 @@ class BeancountFormatter(LedgerFormatter): COST_FMT = '{{{}}}' def __init__(self, cost_rates, price_rates=None, - signed_currencies=(), base_fmt='###0.###', + signed_currencies=(), base_fmt='#,##0.###', rate_precision=5, denomination=None): super().__init__( cost_rates, price_rates, (), - base_fmt.replace(',', ''), + base_fmt, rate_precision, denomination, ) diff --git a/tests/test_historical.py b/tests/test_historical.py index 2d019e9a05abf4ae6ee9ac6addb41ad8bfbc790b..951aa737fb0c92ada813afc76980a67c01bccfdf 100644 --- a/tests/test_historical.py +++ b/tests/test_historical.py @@ -95,7 +95,6 @@ def check_fx_amount(config, lines, amount, cost, fx_code, fx_sign=None, price=No cost_re = '{{={}}}'.format(rate_fmt.format(cost)) price_re = ' @ {}'.format(rate_fmt.format(price)) else: - amount = amount.replace(',', '') cost_re = '{{{}}}'.format(rate_fmt.format(cost)) if config.args.from_date is None: price_re = '' @@ -115,7 +114,7 @@ def check_nonfx_amount(config, lines, amount, code=None, sign=None): else: expected = f'{amount} {code}\n' else: - expected = f'{amount.replace(",", "")} {code or "USD"}\n' + expected = f'{amount} {code or "USD"}\n' assert next(lines, "") == expected def test_rate_list(single_responder, output, any_date):