Changeset - 093834dd15db
[Not reviewed]
0 3 0
Brett Smith - 7 years ago 2017-11-09 21:18:03
brettcsmith@brettcsmith.org
template: Support variables in account names.
3 files changed with 9 insertions and 6 deletions:
0 comments (0 inline, 0 general)
import2ledger/template.py
Show inline comments
...
 
@@ -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:
tests/data/templates.ini
Show inline comments
...
 
@@ -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}
tests/test_templates.py
Show inline comments
...
 
@@ -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",
0 comments (0 inline, 0 general)