You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
5.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2016 ACSONE SA/NV (<http://acsone.eu>)
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. import openerp.tests.common as common
  5. from openerp.tools import test_reports
  6. class TestMisReportInstance(common.TransactionCase):
  7. """ Basic integration test to exercise mis.report.instance.
  8. We don't check the actual results here too much as computation correctness
  9. should be covered by lower level unit tests.
  10. """
  11. def setUp(self):
  12. super(TestMisReportInstance, self).setUp()
  13. partner_model_id = \
  14. self.env.ref('base.model_res_partner').id
  15. partner_create_date_field_id = \
  16. self.env.ref('base.field_res_partner_create_date').id
  17. partner_debit_field_id = \
  18. self.env.ref('account.field_res_partner_debit').id
  19. # create a report with 2 subkpis and one query
  20. self.report = self.env['mis.report'].create(dict(
  21. name='test report',
  22. subkpi_ids=[(0, 0, dict(
  23. name='sk1',
  24. description='subkpi 1',
  25. sequence=1,
  26. )), (0, 0, dict(
  27. name='sk2',
  28. description='subkpi 2',
  29. sequence=2,
  30. ))],
  31. query_ids=[(0, 0, dict(
  32. name='partner',
  33. model_id=partner_model_id,
  34. field_ids=[(4, partner_debit_field_id, None)],
  35. date_field=partner_create_date_field_id,
  36. aggregate='sum',
  37. ))],
  38. ))
  39. # kpi with accounting formulas
  40. self.env['mis.report.kpi'].create(dict(
  41. report_id=self.report.id,
  42. description='kpi 1',
  43. name='k1',
  44. multi=True,
  45. expression_ids=[(0, 0, dict(
  46. name='bale[200%]',
  47. subkpi_id=self.report.subkpi_ids[0].id,
  48. )), (0, 0, dict(
  49. name='balp[200%]',
  50. subkpi_id=self.report.subkpi_ids[1].id,
  51. ))],
  52. ))
  53. # kpi with accounting formula and query
  54. self.env['mis.report.kpi'].create(dict(
  55. report_id=self.report.id,
  56. description='kpi 2',
  57. name='k2',
  58. multi=True,
  59. expression_ids=[(0, 0, dict(
  60. name='balp[200%]',
  61. subkpi_id=self.report.subkpi_ids[0].id,
  62. )), (0, 0, dict(
  63. name='partner.debit',
  64. subkpi_id=self.report.subkpi_ids[1].id,
  65. ))],
  66. ))
  67. # kpi with a simple expression summing other multi-valued kpis
  68. self.env['mis.report.kpi'].create(dict(
  69. report_id=self.report.id,
  70. description='kpi 4',
  71. name='k4',
  72. multi=False,
  73. expression='k1 + k2 + k3',
  74. ))
  75. # kpi with 2 constants
  76. self.env['mis.report.kpi'].create(dict(
  77. report_id=self.report.id,
  78. description='kpi 3',
  79. name='k3',
  80. multi=True,
  81. expression_ids=[(0, 0, dict(
  82. name='AccountingNone',
  83. subkpi_id=self.report.subkpi_ids[0].id,
  84. )), (0, 0, dict(
  85. name='1.0',
  86. subkpi_id=self.report.subkpi_ids[1].id,
  87. ))],
  88. ))
  89. # kpi with a NameError (x not defined)
  90. self.env['mis.report.kpi'].create(dict(
  91. report_id=self.report.id,
  92. description='kpi 5',
  93. name='k5',
  94. multi=True,
  95. expression_ids=[(0, 0, dict(
  96. name='x',
  97. subkpi_id=self.report.subkpi_ids[0].id,
  98. )), (0, 0, dict(
  99. name='1.0',
  100. subkpi_id=self.report.subkpi_ids[1].id,
  101. ))],
  102. ))
  103. # create a report instance
  104. self.report_instance = self.env['mis.report.instance'].create(dict(
  105. name='test instance',
  106. report_id=self.report.id,
  107. company_id=self.env.ref('base.main_company').id,
  108. period_ids=[(0, 0, dict(
  109. name='p1',
  110. mode='relative',
  111. type='d',
  112. subkpi_ids=[(4, self.report.subkpi_ids[0].id, None)],
  113. )), (0, 0, dict(
  114. name='p2',
  115. mode='fix',
  116. manual_date_from='2014-01-01',
  117. manual_date_to='2014-12-31',
  118. ))],
  119. ))
  120. self.report_instance.period_ids[1].comparison_column_ids = \
  121. [(4, self.report_instance.period_ids[0].id, None)]
  122. def test_json(self):
  123. self.report_instance.compute()
  124. def test_qweb(self):
  125. test_reports.try_report(self.env.cr, self.env.uid,
  126. 'mis_builder.report_mis_report_instance',
  127. [self.report_instance.id],
  128. report_type='qweb-pdf')
  129. def test_xlsx(self):
  130. test_reports.try_report(self.env.cr, self.env.uid,
  131. 'mis.report.instance.xlsx',
  132. [self.report_instance.id],
  133. report_type='xlsx')