diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index 91a1212c..47a3b6d5 100644 --- a/mis_builder/models/aep.py +++ b/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, diff --git a/mis_builder/tests/test_aep.py b/mis_builder/tests/test_aep.py index a602be66..9f8db4d4 100644 --- a/mis_builder/tests/test_aep.py +++ b/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):