Browse Source

[IMP] mis_builder: add a wide-coverage integration test

This reveals a couple of bugs!
pull/189/head
Stéphane Bidoul 9 years ago
parent
commit
e34bd39f17
  1. 2
      mis_builder/models/mis_report.py
  2. 2
      mis_builder/models/mis_report_instance.py
  3. 3
      mis_builder/report/mis_report_instance_xlsx.py
  4. 1
      mis_builder/tests/__init__.py
  5. 131
      mis_builder/tests/test_mis_report_instance.py

2
mis_builder/models/mis_report.py

@ -229,6 +229,7 @@ class KpiMatrix(object):
col = self._cols[col_key] col = self._cols[col_key]
cell_tuple = [] cell_tuple = []
assert len(vals) == col.colspan assert len(vals) == col.colspan
assert len(drilldown_args) == col.colspan
for val, drilldown_arg, subcol in \ for val, drilldown_arg, subcol in \
izip(vals, drilldown_args, col.iter_subcols()): izip(vals, drilldown_args, col.iter_subcols()):
if isinstance(val, DataError): if isinstance(val, DataError):
@ -266,6 +267,7 @@ class KpiMatrix(object):
cell = KpiMatrixCell(row, subcol, val, val_rendered, val_comment, cell = KpiMatrixCell(row, subcol, val, val_rendered, val_comment,
cell_style_props, drilldown_arg) cell_style_props, drilldown_arg)
cell_tuple.append(cell) cell_tuple.append(cell)
assert len(cell_tuple) == col.colspan
col._set_cell_tuple(row, cell_tuple) col._set_cell_tuple(row, cell_tuple)
def compute_comparisons(self): def compute_comparisons(self):

2
mis_builder/models/mis_report_instance.py

@ -298,7 +298,7 @@ class MisReportInstance(models.Model):
@api.multi @api.multi
def preview(self): def preview(self):
assert len(self) == 1
self.ensure_one()
view_id = self.env.ref('mis_builder.' view_id = self.env.ref('mis_builder.'
'mis_report_instance_result_view_form') 'mis_report_instance_result_view_form')
return { return {

3
mis_builder/report/mis_report_instance_xlsx.py

@ -115,6 +115,9 @@ class MisBuilderXslx(ReportXlsx):
cell_xlsx_style = style_obj.to_xlsx_style(cell.style_props) cell_xlsx_style = style_obj.to_xlsx_style(cell.style_props)
cell_xlsx_style['align'] = 'right' cell_xlsx_style['align'] = 'right'
cell_format = workbook.add_format(cell_xlsx_style) cell_format = workbook.add_format(cell_xlsx_style)
if cell.val is None or cell.val is AccountingNone:
val = ''
else:
val = cell.val / float(cell.style_props.get('divider', 1)) val = cell.val / float(cell.style_props.get('divider', 1))
sheet.write(row_pos, col_pos, val, cell_format) sheet.write(row_pos, col_pos, val, cell_format)
col_width[col_pos] = max(col_width[col_pos], col_width[col_pos] = max(col_width[col_pos],

1
mis_builder/tests/__init__.py

@ -6,6 +6,7 @@ from . import test_accounting_none
from . import test_aep from . import test_aep
from . import test_aggregate from . import test_aggregate
from . import test_fetch_query from . import test_fetch_query
from . import test_mis_report_instance
from . import test_mis_safe_eval from . import test_mis_safe_eval
from . import test_render from . import test_render
from . import test_simple_array from . import test_simple_array

131
mis_builder/tests/test_mis_report_instance.py

@ -0,0 +1,131 @@
# -*- coding: utf-8 -*-
# © 2016 ACSONE SA/NV (<http://acsone.eu>)
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
import openerp.tests.common as common
from openerp.tools import test_reports
class TestMisReportInstance(common.TransactionCase):
""" Basic integration test to exercise mis.report.instance.
We don't check the actual results here too much as computation correctness
should be covered by lower level unit tests.
"""
def setUp(self):
super(TestMisReportInstance, self).setUp()
partner_model_id = \
self.env.ref('base.model_res_partner').id
partner_create_date_field_id = \
self.env.ref('base.field_res_partner_create_date').id
partner_debit_field_id = \
self.env.ref('account.field_res_partner_debit').id
# create a report with 2 subkpis and one query
self.report = self.env['mis.report'].create(dict(
name='test report',
subkpi_ids=[(0, 0, dict(
name='sk1',
description='subkpi 1',
sequence=1,
)), (0, 0, dict(
name='sk2',
description='subkpi 2',
sequence=2,
)),
],
query_ids=[(0, 0, dict(
name='partner',
model_id=partner_model_id,
field_ids=[(4, partner_debit_field_id, None)],
date_field=partner_create_date_field_id,
aggregate='sum',
)),
],
))
# kpi with accounting formulas
self.env['mis.report.kpi'].create(dict(
report_id=self.report.id,
description='kpi 1',
name='k1',
multi=True,
expression_ids=[(0, 0, dict(
name='bale[200%]',
subkpi_id=self.report.subkpi_ids[0].id,
)), (0, 0, dict(
name='balp[200%]',
subkpi_id=self.report.subkpi_ids[1].id,
)),
],
))
# kpi with accounting formula and query
self.env['mis.report.kpi'].create(dict(
report_id=self.report.id,
description='kpi 2',
name='k2',
multi=True,
expression_ids=[(0, 0, dict(
name='balp[200%]',
subkpi_id=self.report.subkpi_ids[0].id,
)), (0, 0, dict(
name='partner.debit',
subkpi_id=self.report.subkpi_ids[1].id,
)),
],
))
# kpi with 2 constants
self.env['mis.report.kpi'].create(dict(
report_id=self.report.id,
description='kpi 3',
name='k3',
multi=True,
expression_ids=[(0, 0, dict(
name='AccountingNone',
subkpi_id=self.report.subkpi_ids[0].id,
)), (0, 0, dict(
name='1.0',
subkpi_id=self.report.subkpi_ids[1].id,
)),
],
))
# 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',
))
# create a report instance
self.report_instance = self.env['mis.report.instance'].create(dict(
name='test instance',
report_id=self.report.id,
company_id=self.env.ref('base.main_company').id,
period_ids=[(0, 0, dict(
name='p1',
mode='relative',
type='d',
subkpi_ids=[(4, self.report.subkpi_ids[0].id, None)],
)), (0, 0, dict(
name='p2',
mode='fix',
manual_date_from='2014-01-01',
manual_date_to='2014-12-31',
)),
],
))
def test_json(self):
self.report_instance.compute()
def test_qweb(self):
test_reports.try_report(self.env.cr, self.env.uid,
'mis_builder.report_mis_report_instance',
[self.report_instance.id],
report_type='qweb-pdf')
def test_xlsx(self):
test_reports.try_report(self.env.cr, self.env.uid,
'mis.report.instance.xlsx',
[self.report_instance.id],
report_type='xlsx')
Loading…
Cancel
Save