Browse Source

[IMP] mis_builder: more tests and fixes wrt DataError in results

pull/189/head
Stéphane Bidoul 8 years ago
parent
commit
4fdc99014d
  1. 15
      mis_builder/models/mis_report.py
  2. 3
      mis_builder/models/mis_report_style.py
  3. 8
      mis_builder/report/mis_report_instance_xlsx.py
  4. 27
      mis_builder/tests/test_mis_report_instance.py

15
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)

3
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:

8
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],

27
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()

Loading…
Cancel
Save