diff --git a/mis_builder/models/mis_report.py b/mis_builder/models/mis_report.py index fd952e18..0d9e397e 100644 --- a/mis_builder/models/mis_report.py +++ b/mis_builder/models/mis_report.py @@ -236,7 +236,6 @@ class KpiMatrix(object): if isinstance(val, DataError): val_rendered = val.name val_comment = val.msg - val = None else: val_rendered = self._style_model.render( self.lang, row.style_props, kpi.type, val) @@ -401,9 +400,13 @@ class KpiMatrix(object): # TODO use subcol style here row_data['cells'].append({}) else: + if cell.val is AccountingNone or \ + isinstance(cell.val, DataError): + val = None + else: + val = cell.val col_data = { - 'val': (cell.val - if cell.val is not AccountingNone else None), + 'val': val, 'val_r': cell.val_rendered, 'val_c': cell.val_comment, 'style': self._style_model.to_css_style( @@ -967,15 +970,15 @@ class MisReport(models.Model): if isinstance(vals[0], tuple): vals = vals[0] assert len(vals) == col.colspan - elif isinstance(vals[0], NameDataError): + elif isinstance(vals[0], DataError): vals = (vals[0],) * col.colspan else: raise UserError("Probably not your fault... but I'm " "really curious to know how you " "managed to raise this error so " "I can handle one more corner case!") - if len(drilldown_args) != len(vals): - drilldown_args = [None] * len(vals) + if len(drilldown_args) != col.colspan: + drilldown_args = [None] * col.colspan kpi_matrix.set_values( kpi, col_key, vals, drilldown_args) diff --git a/mis_builder/models/mis_report_style.py b/mis_builder/models/mis_report_style.py index 51e164c0..7b124922 100644 --- a/mis_builder/models/mis_report_style.py +++ b/mis_builder/models/mis_report_style.py @@ -7,6 +7,7 @@ from openerp import api, fields, models, _ from openerp.exceptions import UserError from .accounting_none import AccountingNone +from .data_error import DataError class PropertyDict(dict): @@ -196,6 +197,8 @@ class MisReportKpiStyle(models.Model): average_value=1, average_base_value=1): delta = AccountingNone style_r = style_props.copy() + if isinstance(value, DataError) or isinstance(base_value, DataError): + return AccountingNone, '', style_r if value is None: value = AccountingNone if base_value is None: diff --git a/mis_builder/report/mis_report_instance_xlsx.py b/mis_builder/report/mis_report_instance_xlsx.py index 6bdcc689..ae7767ec 100644 --- a/mis_builder/report/mis_report_instance_xlsx.py +++ b/mis_builder/report/mis_report_instance_xlsx.py @@ -8,6 +8,7 @@ import logging from openerp.report import report_sxw from ..models.accounting_none import AccountingNone +from ..models.data_error import DataError _logger = logging.getLogger(__name__) @@ -115,9 +116,14 @@ class MisBuilderXslx(ReportXlsx): cell_xlsx_style = style_obj.to_xlsx_style(cell.style_props) cell_xlsx_style['align'] = 'right' cell_format = workbook.add_format(cell_xlsx_style) - if cell.val is None or cell.val is AccountingNone: + if isinstance(cell.val, DataError): + val = cell.val.name + # TODO display cell.val.msg as Excel comment? + elif cell.val is None or cell.val is AccountingNone: val = '' else: + _logger.info("*** %s %s %s", cell.row.label, + cell.subcol.label, cell.val) val = cell.val / float(cell.style_props.get('divider', 1)) sheet.write(row_pos, col_pos, val, cell_format) col_width[col_pos] = max(col_width[col_pos], diff --git a/mis_builder/tests/test_mis_report_instance.py b/mis_builder/tests/test_mis_report_instance.py index c7b7cc2c..848ed8a9 100644 --- a/mis_builder/tests/test_mis_report_instance.py +++ b/mis_builder/tests/test_mis_report_instance.py @@ -73,6 +73,14 @@ class TestMisReportInstance(common.TransactionCase): )), ], )) + # kpi with a simple expression summing other multi-valued kpis + self.env['mis.report.kpi'].create(dict( + report_id=self.report.id, + description='kpi 4', + name='k4', + multi=False, + expression='k1 + k2 + k3', + )) # kpi with 2 constants self.env['mis.report.kpi'].create(dict( report_id=self.report.id, @@ -88,13 +96,20 @@ class TestMisReportInstance(common.TransactionCase): )), ], )) - # kpi with a simple expression summing other multi-valued kpis + # kpi with a NameError (x not defined) self.env['mis.report.kpi'].create(dict( report_id=self.report.id, - description='kpi 4', - name='k4', - multi=False, - expression='k1 + k2 + k3', + description='kpi 5', + name='k5', + multi=True, + expression_ids=[(0, 0, dict( + name='x', + subkpi_id=self.report.subkpi_ids[0].id, + )), (0, 0, dict( + name='1.0', + subkpi_id=self.report.subkpi_ids[1].id, + )), + ], )) # create a report instance self.report_instance = self.env['mis.report.instance'].create(dict( @@ -114,6 +129,8 @@ class TestMisReportInstance(common.TransactionCase): )), ], )) + self.report_instance.period_ids[1].comparison_column_ids = \ + [(4, self.report_instance.period_ids[0].id, None)] def test_json(self): self.report_instance.compute()