From d976ede6448530b8bc0a5a82c28dc701a595b071 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20BEAU?= Date: Thu, 28 Apr 2016 00:45:38 +0200 Subject: [PATCH] [IMP] improve view and onchange on multi expression --- mis_builder/models/mis_builder.py | 48 ++++++++----------------------- mis_builder/views/mis_builder.xml | 27 +++++++++-------- 2 files changed, 27 insertions(+), 48 deletions(-) diff --git a/mis_builder/models/mis_builder.py b/mis_builder/models/mis_builder.py index 1452be70..67649f9d 100644 --- a/mis_builder/models/mis_builder.py +++ b/mis_builder/models/mis_builder.py @@ -158,38 +158,6 @@ class MisReportKpi(models.Model): })] }) - @api.model - def create(self, vals): - kpi = super(MisReportKpi, self).create(vals) - if kpi.multi: - kpi._populate_expression() - return kpi - - @api.multi - def write(self, vals): - res = super(MisReportKpi, self).write(vals) - if vals.get('multi'): - self._populate_expression() - return res - - @api.multi - def _populate_expression(self): - for kpi in self: - if kpi.multi: - if kpi.expression_ids: - expression = kpi.expression_ids[0].name - else: - expression = "AccountingNone" - existing_subkpis = kpi.expression_ids.mapped('subkpi_id') - expressions = [] - for subkpi in kpi.report_id.subkpi_ids: - if not subkpi in existing_subkpis: - self.env['mis.report.kpi.expression'].create({ - 'name': expression, - 'kpi_id': kpi.id, - 'subkpi_id': subkpi.id, - }) - @api.onchange('multi') def _onchange_multi(self): for kpi in self: @@ -198,6 +166,14 @@ class MisReportKpi(models.Model): kpi.expression = kpi.expression_ids[0].name else: kpi.expression = None + else: + expressions = [] + for subkpi in kpi.report_id.subkpi_ids: + expressions.append((0, 0, { + 'name': kpi.expression, + 'subkpi_id': subkpi.id, + })) + kpi.expression_ids = expressions @api.onchange('description') def _onchange_description(self): @@ -587,14 +563,14 @@ class MisReport(models.Model): '#ERR', '\n\n%s' % (traceback.format_exc(),))) except: - raise vals.append(DataError( '#ERR', '\n\n%s' % (traceback.format_exc(),))) - #TODO escape total - localdict[kpi.name] = SimpleArray(vals) - res[kpi] = SimpleArray(vals) + if kpi.multi: + vals = SimpleArray(vals) + localdict[kpi.name] = vals + res[kpi] = vals if len(recompute_queue) == 0: # nothing to recompute, we are done diff --git a/mis_builder/views/mis_builder.xml b/mis_builder/views/mis_builder.xml index 36b611b4..226307f3 100644 --- a/mis_builder/views/mis_builder.xml +++ b/mis_builder/views/mis_builder.xml @@ -58,8 +58,7 @@ - + @@ -109,16 +108,6 @@ - - - - - - - - @@ -132,6 +121,20 @@ + + + + + + + + + +