From 093834dd15dbb98e23042e0f55bacac9e40e0ad0 Mon Sep 17 00:00:00 2001 From: Brett Smith Date: Thu, 9 Nov 2017 16:16:20 -0500 Subject: [PATCH] template: Support variables in account names. --- import2ledger/template.py | 6 ++++-- tests/data/templates.ini | 4 ++-- tests/test_templates.py | 5 +++-- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/import2ledger/template.py b/import2ledger/template.py index f29da23..160e3fe 100644 --- a/import2ledger/template.py +++ b/import2ledger/template.py @@ -136,8 +136,10 @@ class AccountSplitter: else: amt_fmt = self.unsigned_currency_fmt for account, amount in amounts.items(): - amt_s = babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt) - yield ' {:45} {:>19}\n'.format(account, amt_s) + yield ' {:45} {:>19}\n'.format( + account.format_map(template_vars), + babel.numbers.format_currency(amount, template_vars['currency'], amt_fmt), + ) def render_next(self, template_vars): if template_vars is not self._last_template_vars: diff --git a/tests/data/templates.ini b/tests/data/templates.ini index c0d2adf..a59d7b3 100644 --- a/tests/data/templates.ini +++ b/tests/data/templates.ini @@ -15,8 +15,8 @@ template = ;TransactionID: {txid} Accrued:Accounts Receivable {amount} ;Entity: Supplier - Income:Donations:Specific -.955* {amount} - ;Program: Specific + Income:Donations:{program} -.955* {amount} + ;Program: {program} ;Entity: {entity} Income:Donations:General -.045 * {amount} ;Entity: {entity} diff --git a/tests/test_templates.py b/tests/test_templates.py index 8400d2c..32c93ea 100644 --- a/tests/test_templates.py +++ b/tests/test_templates.py @@ -42,6 +42,7 @@ def test_currency_formatting(): def test_complex_template(): template_vars = { 'entity': 'T-T', + 'program': 'Spectrum Defense', 'txid': 'ABCDEF', } tmpl = template_from('Complex', date_fmt='%Y-%m-%d', signed_currencies=['USD']) @@ -54,8 +55,8 @@ def test_complex_template(): " ;TransactionID: ABCDEF", " Accrued:Accounts Receivable $125.50", " ;Entity: Supplier", - " Income:Donations:Specific $-119.85", - " ;Program: Specific", + " Income:Donations:Spectrum Defense $-119.85", + " ;Program: Spectrum Defense", " ;Entity: T-T", " Income:Donations:General $-5.65", " ;Entity: T-T",