From 9af17587fc872f1f630bcf78bf10c38bdcc55e0d Mon Sep 17 00:00:00 2001 From: Thomas Binsfeld Date: Fri, 27 May 2016 16:01:38 +0200 Subject: [PATCH] [IMP] prepare_locals_dict (#199) --- mis_builder/models/mis_report.py | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/mis_builder/models/mis_report.py b/mis_builder/models/mis_report.py index 2d0dfac0..7068afbf 100644 --- a/mis_builder/models/mis_report.py +++ b/mis_builder/models/mis_report.py @@ -797,6 +797,17 @@ class MisReport(models.Model): aep.done_parsing() return aep + def prepare_locals_dict(self): + return { + 'sum': _sum, + 'min': _min, + 'max': _max, + 'len': len, + 'avg': _avg, + 'AccountingNone': AccountingNone, + 'SimpleArray': SimpleArray, + } + @api.multi def _fetch_queries(self, date_from, date_to, get_additional_query_filter=None): @@ -874,7 +885,8 @@ class MisReport(models.Model): target_move, subkpis_filter=None, get_additional_move_line_filter=None, - get_additional_query_filter=None): + get_additional_query_filter=None, + locals_dict=None): """ Evaluate a report for a given period, populating a KpiMatrix. :param kpi_matrix: the KpiMatrix object to be populated created @@ -892,18 +904,16 @@ class MisReport(models.Model): query argument and returns a domain compatible with the query underlying model + :param locals_dict: personalized locals dictionary used as evaluation + context for the KPI expressions """ self.ensure_one() - locals_dict = { - 'sum': _sum, - 'min': _min, - 'max': _max, - 'len': len, - 'avg': _avg, - 'AccountingNone': AccountingNone, - 'SimpleArray': SimpleArray, - } + # prepare the localsdict + if locals_dict is None: + locals_dict = {} + + locals_dict.update(self.prepare_locals_dict()) # fetch non-accounting queries locals_dict.update(self._fetch_queries(