File diff cc2b3978011a → 89378cbf90fc
import2ledger/hooks/ledger_entry.py
Show inline comments
...
 
@@ -222,9 +222,10 @@ class AccountSplitter:
 

	
 

	
 
class Template:
 
    ACCOUNT_SPLIT_RE = re.compile(r'(?:\t|  )\s*')
 
    ACCOUNT_SPLIT_RE = re.compile(r'(?: ?\t|  )[ \t]*')
 
    DATE_FMT = '%Y/%m/%d'
 
    PAYEE_LINE_RE = re.compile(r'^\{(\w*_)*date\}\s')
 
    NEWLINE_RE = re.compile(r'[\f\n\r\v\u0085\u2028\u2029]')
 
    SIGNED_CURRENCY_FMT = '¤#,##0.###;¤-#,##0.###'
 
    UNSIGNED_CURRENCY_FMT = '#,##0.### ¤¤'
 

	
...
 
@@ -301,12 +302,17 @@ class Template:
 
                "entry needs {} field but that's not set by the importer".format(
 
                    self.date_field,
 
                ), self.splitter.template_name)
 
        render_vars = {
 
            'amount': strparse.currency_decimal(template_vars['amount']),
 
        }
 
        render_vars = {}
 
        for key, value in template_vars.items():
 
            if value is not None and (key == 'date' or key.endswith('_date')):
 
            if value is None:
 
                pass
 
            elif key == 'date' or key.endswith('_date'):
 
                render_vars[key] = value.strftime(self.date_fmt)
 
            elif isinstance(value, str):
 
                value = self.NEWLINE_RE.sub(' ', value)
 
                value = self.ACCOUNT_SPLIT_RE.sub(' ', value)
 
                render_vars[key] = value
 
        render_vars['amount'] = strparse.currency_decimal(template_vars['amount'])
 
        all_vars = collections.ChainMap(render_vars, template_vars)
 
        return ''.join(f(all_vars) for f in self.format_funcs)