Browse Source

[IMP] mis_builder: AEP: replace_exprs_by_account_id now works on a list of expressions

pull/189/head
Stéphane Bidoul 8 years ago
parent
commit
378d168e50
  1. 26
      mis_builder/models/aep.py
  2. 6
      mis_builder/tests/test_aep.py

26
mis_builder/models/aep.py

@ -301,9 +301,9 @@ class AccountingExpressionProcessor(object):
return self._ACC_RE.sub(f, expr)
def replace_expr_by_account_id(self, expr):
"""Replace accounting variables in an expression by their amount,
iterating by accounts involved in the expression.
def replace_exprs_by_account_id(self, exprs):
"""Replace accounting variables in a list of expression
by their amount, iterating by accounts involved in the expression.
yields account_id, replaced_expr
@ -341,17 +341,19 @@ class AccountingExpressionProcessor(object):
return '(' + repr(v) + ')'
account_ids = set()
for mo in self._ACC_RE.finditer(expr):
field, mode, account_codes, domain = self._parse_match_object(mo)
key = (domain, mode)
account_ids_data = self._data[key]
for account_code in account_codes:
for account_id in self._account_ids_by_code[account_code]:
if account_id in account_ids_data:
account_ids.add(account_id)
for expr in exprs:
for mo in self._ACC_RE.finditer(expr):
field, mode, account_codes, domain = \
self._parse_match_object(mo)
key = (domain, mode)
account_ids_data = self._data[key]
for account_code in account_codes:
for account_id in self._account_ids_by_code[account_code]:
if account_id in account_ids_data:
account_ids.add(account_id)
for account_id in account_ids:
yield account_id, self._ACC_RE.sub(f, expr)
yield account_id, [self._ACC_RE.sub(f, expr) for expr in exprs]
@classmethod
def _get_balances(cls, mode, company, date_from, date_to,

6
mis_builder/tests/test_aep.py

@ -113,9 +113,9 @@ class TestAEP(common.TransactionCase):
def _eval_by_account_id(self, expr):
res = {}
eval_dict = {'AccountingNone': AccountingNone}
for account_id, replaced_expr in \
self.aep.replace_expr_by_account_id(expr):
res[account_id] = safe_eval(replaced_expr, eval_dict)
for account_id, replaced_exprs in \
self.aep.replace_exprs_by_account_id([expr]):
res[account_id] = safe_eval(replaced_exprs[0], eval_dict)
return res
def test_sanity_check(self):

Loading…
Cancel
Save