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.

48 lines
2.2 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. class TestReportSubstitute(TransactionCase):
  5. def setUp(self):
  6. # In the demo file we create a new report for ir.module.module model
  7. # with a substation rule from the original report action
  8. super(TestReportSubstitute, self).setUp()
  9. self.action_report = self.env.ref('base.ir_module_reference_print')
  10. self.res_ids = self.env.ref('base.module_base').ids
  11. self.substitution_rule = self.env.ref(
  12. 'report_substitute.substitution_rule_demo_1'
  13. )
  14. def test_substitution(self):
  15. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  16. self.assertIn('<div class="page">Substitution Report</div>', res)
  17. # remove the substation rule
  18. self.substitution_rule.unlink()
  19. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  20. self.assertNotIn('<div class="page">Substitution Report</div>', res)
  21. def test_recursive_substitution(self):
  22. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  23. self.assertNotIn('<div class="page">Substitution Report 2</div>', res)
  24. self.env['ir.actions.report.substitution.rule'].create(
  25. {
  26. 'substitution_action_report_id': self.env.ref(
  27. 'report_substitute.substitution_report_print_2'
  28. ).id,
  29. 'action_report_id': self.env.ref(
  30. 'report_substitute.substitution_report_print'
  31. ).id,
  32. }
  33. )
  34. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  35. self.assertIn('<div class="page">Substitution Report 2</div>', res)
  36. def test_substitution_with_domain(self):
  37. self.substitution_rule.write({'domain': "[('name', '=', 'base')]"})
  38. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  39. self.assertIn('<div class="page">Substitution Report</div>', res)
  40. self.substitution_rule.write({'domain': "[('name', '!=', 'base')]"})
  41. res = str(self.action_report.render(res_ids=self.res_ids)[0])
  42. self.assertNotIn('<div class="page">Substitution Report</div>', res)