From 6becf7af03eb931e7492034a6e0f20903324a900 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 11 Oct 2014 14:30:19 +0200 Subject: [PATCH] [IMP] prepare performance optimization to fetch only used balances (WIP) --- mis_builder/models/mis_builder.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 17f58856..6649f743 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -68,6 +68,17 @@ def _python_bal_var(account_code): return 'bal_' + re.sub(r'\W', '_', account_code) +def _get_bal_vars_in_expr(expr): + return re.findall(expr, r'\bbal_\w+') + + +def _get_vars_in_expr(expr, varnames=None): + if not varnames: + return [] + varnames_re = r'\b' + r'\b|\b'.join(varnames) + r'\b' + return re.findall(expr, varnames_re) + + class mis_report_kpi(orm.Model): """ A KPI is an element of a MIS report. @@ -548,6 +559,13 @@ class mis_report_instance_period(orm.Model): return res + def _get_bal_vars_in_report(self, report): + res = set() + for kpi in report.kpi_ids: + for bal_var in _get_bal_vars_in_expr(kpi.expression): + res.add(bal_var) + return res + def _compute(self, cr, uid, c, context=None): if context is None: context = {}