From 615e67e02ab2c4375d69b4207d996912c986a608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sun, 3 May 2015 18:38:58 +0200 Subject: [PATCH] [IMP] mis_builder: tiny refactoring --- mis_builder/models/aep.py | 1 + mis_builder/models/mis_builder.py | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/mis_builder/models/aep.py b/mis_builder/models/aep.py index 155088e7..4e6233db 100644 --- a/mis_builder/models/aep.py +++ b/mis_builder/models/aep.py @@ -155,6 +155,7 @@ class AccountingExpressionProcessor(object): account_ids.update(self._account_ids_by_code[account_code]) self._map_account_ids[key] = list(account_ids) + @classmethod def has_account_var(self, expr): return bool(self.ACC_RE.search(expr)) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 1c3a1b60..1421a020 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -35,7 +35,7 @@ from openerp import tools from openerp.tools.safe_eval import safe_eval from openerp.tools.translate import _ -from .aep import AccountingExpressionProcessor +from .aep import AccountingExpressionProcessor as AEP class AutoStruct(object): @@ -457,9 +457,9 @@ class mis_report_instance_period(orm.Model): if context is None: context = {} this = self.browse(cr, uid, _id, context=context)[0] - env = Environment(cr, uid, context) - aep = AccountingExpressionProcessor(env) - if aep.has_account_var(expr): + if AEP.has_account_var(expr): + env = Environment(cr, uid, context) + aep = AEP(env) aep.parse_expr(expr) aep.done_parsing(this.report_instance_id.root_account) domain = aep.get_aml_domain_for_expr( @@ -585,7 +585,7 @@ class mis_report_instance_period(orm.Model): kpi_style = None drilldown = (kpi_val is not None and - aep.has_account_var(kpi.expression)) + AEP.has_account_var(kpi.expression)) res[kpi.name] = { 'val': kpi_val, @@ -702,7 +702,7 @@ class mis_report_instance(orm.Model): # prepare AccountingExpressionProcessor env = Environment(cr, uid, context) - aep = AccountingExpressionProcessor(env) + aep = AEP(env) for kpi in this.report_id.kpi_ids: aep.parse_expr(kpi.expression) aep.done_parsing(this.root_account)