From d0d3d1478a5af184938448423395d6959608aa8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Bidoul?= Date: Sat, 25 Apr 2015 23:40:04 +0200 Subject: [PATCH] [IMP] mis_builder: refactor drilldown to move the logic to the server --- mis_builder/models/mis_builder.py | 32 ++++++++++++++--------- mis_builder/static/src/js/mis_builder.js | 28 +++++++------------- mis_builder/static/src/xml/mis_widget.xml | 6 ++--- 3 files changed, 33 insertions(+), 33 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 021ee4e8..bbffcedc 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -480,18 +480,16 @@ class mis_report_instance_period(orm.Model): 'Period name should be unique by report'), ] - def compute_domain(self, cr, uid, ids, account_, context=None): - if isinstance(ids, (int, long)): - ids = [ids] - domain = [] - this = self.browse(cr, uid, ids, context=context)[0] + def drilldown(self, cr, uid, id, expr, context=None): + this = self.browse(cr, uid, id, context=context)[0] env = Environment(cr, uid, {}) aep = AccountingExpressionProcessor(env) - aep.parse_expr(account_) + aep.parse_expr(expr) aep.done_parsing([('company_id', '=', this.report_instance_id.company_id.id)]) - domain.extend(aep.get_aml_domain_for_expr(account_)) - if domain != []: + domain = aep.get_aml_domain_for_expr(expr) + if domain: + # TODO: reuse compute_period_domain # compute date/period period_ids = [] date_from = None @@ -514,9 +512,18 @@ class mis_report_instance_period(orm.Model): if date_from: domain.extend([('date', '>=', date_from), ('date', '<=', date_to)]) + return { + 'name': expr + ' - ' + this.name, + 'domain': domain, + 'type': 'ir.actions.act_window', + 'res_model': 'account.move.line', + 'views': [[False, 'list'], [False, 'form']], + 'view_type': 'list', + 'view_mode': 'list', + 'target': 'current', + } else: - domain = False - return domain + return False def compute_period_domain(self, cr, uid, period_report, is_end, is_initial, context=None): @@ -657,7 +664,8 @@ class mis_report_instance_period(orm.Model): except: kpi_style = None - drilldown = bool(aep.get_aml_domain_for_expr(kpi.expression)) + drilldown = (kpi_val is not None and + bool(aep.get_aml_domain_for_expr(kpi.expression))) res[kpi.name] = { 'val': kpi_val, @@ -669,7 +677,7 @@ class mis_report_instance_period(orm.Model): 'dp': kpi.dp, 'is_percentage': kpi.type == 'pct', 'period_id': c.id, - 'period_name': c.name, + 'expr': kpi.expression, 'drilldown': drilldown, } diff --git a/mis_builder/static/src/js/mis_builder.js b/mis_builder/static/src/js/mis_builder.js index fcd656f5..fb0f773a 100644 --- a/mis_builder/static/src/js/mis_builder.js +++ b/mis_builder/static/src/js/mis_builder.js @@ -20,32 +20,24 @@ openerp.mis_builder = function(instance) { self.renderElement(); }); }, + events: { "click a.mis_builder_drilldown": "drilldown", }, + drilldown: function(event) { - var val_c = JSON.parse($(event.target).data("val-c")); - var val = JSON.parse($(event.target).data("val")); - var period_id = JSON.parse($(event.target).data("period-id")); - var period_name = JSON.parse($(event.target).data("period-name")); var self = this; - if (!(val === null) && (val_c.indexOf('bal') >=0)){ + var drilldown = JSON.parse($(event.target).data("drilldown")); + if (drilldown) { + var period_id = JSON.parse($(event.target).data("period-id")); + var val_c = JSON.parse($(event.target).data("expr")); new instance.web.Model("mis.report.instance.period").call( - "compute_domain", + "drilldown", [period_id, val_c], {'context': new instance.web.CompoundContext()} - ).then(function(result){ - if (result != false){ - self.do_action({ - name: val_c + ' - ' + period_name, - domain: JSON.stringify(result), - type: 'ir.actions.act_window', - res_model: "account.move.line", - views: [[false, 'list'], [false, 'form']], - view_type : "list", - view_mode : "list", - target: 'current', - }); + ).then(function(result) { + if (result) { + self.do_action(result); } }); } diff --git a/mis_builder/static/src/xml/mis_widget.xml b/mis_builder/static/src/xml/mis_widget.xml index 5edbe648..b8a13176 100644 --- a/mis_builder/static/src/xml/mis_widget.xml +++ b/mis_builder/static/src/xml/mis_widget.xml @@ -30,10 +30,10 @@ + t-att-data-expr="JSON.stringify(value_value.expr)" + >