OCA reporting engine fork for dev and update.
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.

80 lines
3.4 KiB

  1. # Copyright 2019 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo.tests.common import TransactionCase
  4. from odoo.exceptions import ValidationError
  5. class TestReportSubstitute(TransactionCase):
  6. def setUp(self):
  7. # In the demo file we create a new report for ir.module.module model
  8. # with a substation rule from the original report action
  9. super(TestReportSubstitute, self).setUp()
  10. self.action_report = self.env.ref('base.ir_module_reference_print')
  11. self.res_ids = self.env.ref('base.module_base').ids
  12. self.substitution_rule = self.env.ref(
  13. 'report_substitute.substitution_rule_demo_1'
  14. )
  15. def test_substitution(self):
  16. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  17. self.assertIn('<div class="page">Substitution Report</div>', res)
  18. # remove the substation rule
  19. self.substitution_rule.unlink()
  20. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  21. self.assertNotIn('<div class="page">Substitution Report</div>', res)
  22. def test_recursive_substitution(self):
  23. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  24. self.assertNotIn('<div class="page">Substitution Report 2</div>', res)
  25. self.env['ir.actions.report.substitution.rule'].create(
  26. {
  27. 'substitution_action_report_id': self.env.ref(
  28. 'report_substitute.substitution_report_print_2'
  29. ).id,
  30. 'action_report_id': self.env.ref(
  31. 'report_substitute.substitution_report_print'
  32. ).id,
  33. }
  34. )
  35. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  36. self.assertIn('<div class="page">Substitution Report 2</div>', res)
  37. def test_substitution_with_domain(self):
  38. self.substitution_rule.write({'domain': "[('name', '=', 'base')]"})
  39. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  40. self.assertIn('<div class="page">Substitution Report</div>', res)
  41. self.substitution_rule.write({'domain': "[('name', '!=', 'base')]"})
  42. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  43. self.assertNotIn('<div class="page">Substitution Report</div>', res)
  44. def test_substitution_with_action_dict(self):
  45. substitution_report_action = self.env[
  46. 'ir.actions.report'
  47. ].get_substitution_report_action(
  48. self.action_report.read()[0], self.res_ids
  49. )
  50. self.assertEqual(
  51. substitution_report_action['id'],
  52. self.substitution_rule.substitution_action_report_id.id,
  53. )
  54. def test_substitution_with_report_action(self):
  55. res = self.action_report.report_action(self.res_ids)
  56. self.assertEqual(
  57. res['report_name'],
  58. self.substitution_rule.substitution_action_report_id.report_name,
  59. )
  60. def test_substitution_infinite_loop(self):
  61. with self.assertRaises(ValidationError):
  62. self.env['ir.actions.report.substitution.rule'].create(
  63. {
  64. 'action_report_id': self.env.ref(
  65. 'report_substitute.substitution_report_print'
  66. ).id,
  67. 'substitution_action_report_id': self.env.ref(
  68. 'base.ir_module_reference_print'
  69. ).id,
  70. }
  71. )