@@ -219,15 +219,16 @@ class AccountSplitter:
self._split_iter = self._iter_splits(template_vars)
self._last_template_vars = template_vars
return next(self._split_iter)
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.### ¤¤'
def __init__(self, template_s, signed_currencies=frozenset(),
date_fmt=DATE_FMT,
signed_currency_fmt=SIGNED_CURRENCY_FMT,
@@ -298,18 +299,23 @@ class Template:
template_vars['payee']
if template_vars.get(self.date_field) is None:
raise errors.UserInputConfigurationError(
"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)
def is_empty(self):
return not self.format_funcs