From b95b5ef5c943b0f3a9b0ff9758ad8b370c4b4508 Mon Sep 17 00:00:00 2001 From: Laetitia Gangloff Date: Fri, 6 Mar 2015 16:18:58 +0100 Subject: [PATCH] Add tooltip to see the expression used. Add onclick to go to account.move.line concerned --- mis_builder/models/mis_builder.py | 51 +++++++++++++++++++++-- mis_builder/static/src/css/custom.css | 3 ++ mis_builder/static/src/js/mis_builder.js | 28 +++++++++++++ mis_builder/static/src/xml/mis_widget.xml | 12 +++++- mis_builder/tests/mis_builder_test.py | 30 ++++++++----- 5 files changed, 108 insertions(+), 16 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 2c28a2ea..29601a0a 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -506,6 +506,49 @@ class mis_report_instance_period(orm.Model): 'Period name should be unique by report'), ] + def compute_domain(self, cr, uid, ids, bal_, context=None): + if isinstance(ids, (int, long)): + ids = [ids] + domain = [] + # extract all bal code + b = _get_bal_vars_in_expr(bal_, is_solde=False) + bs = _get_bal_vars_in_expr(bal_, is_solde=True) + all_code = [] + all_code.extend([_get_bal_code(bal, False) for bal in b]) + all_code.extend([_get_bal_code(bal, True) for bal in bs]) + + domain.append(('account_id.code', 'in', all_code)) + + # compute date/period + period_ids = [] + date_from = None + date_to = None + + period_obj = self.pool['account.period'] + + for c in self.browse(cr, uid, ids, context=context): + target_move = c.report_instance_id.target_move + if target_move == 'posted': + domain.append(('move_id.state', '=', target_move)) + if c.period_from: + compute_period_ids = period_obj.build_ctx_periods( + cr, uid, c.period_from.id, c.period_to.id) + period_ids.extend(compute_period_ids) + else: + if not date_from or date_from > c.date_from: + date_from = c.date_from + if not date_to or date_to < c.date_to: + date_to = c.date_to + if period_ids: + if date_from: + domain.append('|') + domain.append(('period_id', 'in', period_ids)) + if date_from: + domain.extend([('date', '>=', c.date_from), + ('date', '<=', c.date_to)]) + + return domain + def _fetch_bal(self, cr, uid, company_id, bal_vars, context=None, is_solde=False): account_obj = self.pool['account.account'] @@ -646,19 +689,19 @@ class mis_report_instance_period(orm.Model): for kpi in c.report_instance_id.report_id.kpi_ids: try: + kpi_val_comment = kpi.expression kpi_val = safe_eval(kpi.expression, localdict) except ZeroDivisionError: kpi_val = None kpi_val_rendered = '#DIV/0' - kpi_val_comment = traceback.format_exc() + kpi_val_comment += '\n\n%s' % (traceback.format_exc(),) except: kpi_val = None kpi_val_rendered = '#ERR' - kpi_val_comment = traceback.format_exc() + kpi_val_comment += '\n\n%s' % (traceback.format_exc(),) else: kpi_val_rendered = kpi_obj._render( cr, uid, lang_id, kpi, kpi_val, context=context) - kpi_val_comment = None localdict[kpi.name] = kpi_val try: @@ -677,6 +720,8 @@ class mis_report_instance_period(orm.Model): 'suffix': kpi.suffix, 'dp': kpi.dp, 'is_percentage': kpi.type == 'pct', + 'period_id': c.id, + 'period_name': c.name, } return res diff --git a/mis_builder/static/src/css/custom.css b/mis_builder/static/src/css/custom.css index 361333f1..b2f624d4 100644 --- a/mis_builder/static/src/css/custom.css +++ b/mis_builder/static/src/css/custom.css @@ -1,3 +1,6 @@ .openerp .rallign { text-align: right; +} +.openerp a.mis_builder { + color: #4c4c4c; } \ No newline at end of file diff --git a/mis_builder/static/src/js/mis_builder.js b/mis_builder/static/src/js/mis_builder.js index f6709bf9..5dbe085f 100644 --- a/mis_builder/static/src/js/mis_builder.js +++ b/mis_builder/static/src/js/mis_builder.js @@ -20,6 +20,34 @@ openerp.mis_builder = function(instance) { self.renderElement(); }); }, + events: { + "click .open_account_move a": "go_to_move", + }, + go_to_move : 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) || (val_c.indexOf('bals_') >= 0))){ + new instance.web.Model("mis.report.instance.period").call( + "compute_domain", + [period_id, val_c], + {'context': new instance.web.CompoundContext()} + ).then(function(result){ + 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', + }); + }); + } + }, }); instance.web.form.custom_widgets.add('mis_report', 'instance.mis_builder.MisReport'); diff --git a/mis_builder/static/src/xml/mis_widget.xml b/mis_builder/static/src/xml/mis_widget.xml index 6ec2722d..fcad82b3 100644 --- a/mis_builder/static/src/xml/mis_widget.xml +++ b/mis_builder/static/src/xml/mis_widget.xml @@ -25,9 +25,17 @@ - + diff --git a/mis_builder/tests/mis_builder_test.py b/mis_builder/tests/mis_builder_test.py index dacb754d..7730e57c 100644 --- a/mis_builder/tests/mis_builder_test.py +++ b/mis_builder/tests/mis_builder_test.py @@ -65,17 +65,25 @@ class mis_builder_test(common.TransactionCase): self.ref('mis_builder.mis_report_instance_test')) self.assertDictContainsSubset( {'content': - OrderedDict([(u'total_test', - {'kpi_name': u'total test', - 'default_style': None, - 'cols': [{'style': None, - 'default_style': None, - 'suffix': False, - 'val_c': None, - 'val': 0, - 'val_r': '0 ', - 'is_percentage': False, - 'dp': 0}]})]), + OrderedDict([( + u'total_test', + {'kpi_name': u'total test', + 'default_style': None, + 'cols': [{ + 'period_name': 'today', + 'period_id': + self.ref( + 'mis_builder.mis_report_instance_period_test'), + 'style': None, + 'default_style': None, + 'suffix': False, + 'val_c': 'len(test)', + 'val': 0, + 'val_r': '0 ', + 'is_percentage': False, + 'dp': 0}] + } + )]), 'header': OrderedDict([('', {'kpi_name': '', 'default_style': '',