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.

90 lines
3.4 KiB

  1. # Copyright 2020 NextERP Romania SRL
  2. # Copyright 2021 Tecnativa - Víctor Martínez
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import common
  5. from .fake_models import ResUsers, setup_test_model, teardown_test_model
  6. class TestCommentTemplate(common.SavepointCase):
  7. at_install = False
  8. post_install = True
  9. @classmethod
  10. def setUpClass(cls):
  11. super().setUpClass()
  12. setup_test_model(cls.env, ResUsers)
  13. cls.user_obj = cls.env.ref("base.model_res_users")
  14. cls.user = cls.env.ref("base.user_demo")
  15. cls.user2 = cls.env.ref("base.demo_user0")
  16. cls.partner_id = cls.env.ref("base.res_partner_12")
  17. cls.partner2_id = cls.env.ref("base.res_partner_10")
  18. cls.main_company = cls.env.ref("base.main_company")
  19. cls.company = cls.env["res.company"].create({"name": "Test company"})
  20. cls.before_template_id = cls.env["base.comment.template"].create(
  21. {
  22. "name": "Top template",
  23. "text": "Text before lines",
  24. "model_ids": [(6, 0, cls.user_obj.ids)],
  25. "company_id": cls.company.id,
  26. }
  27. )
  28. cls.after_template_id = cls.env["base.comment.template"].create(
  29. {
  30. "name": "Bottom template",
  31. "position": "after_lines",
  32. "text": "Text after lines",
  33. "model_ids": [(6, 0, cls.user_obj.ids)],
  34. "company_id": cls.company.id,
  35. }
  36. )
  37. cls.user.partner_id.base_comment_template_ids = [
  38. (4, cls.before_template_id.id),
  39. (4, cls.after_template_id.id),
  40. ]
  41. @classmethod
  42. def tearDownClass(cls):
  43. teardown_test_model(cls.env, ResUsers)
  44. super(TestCommentTemplate, cls).tearDownClass()
  45. def test_template_name_get(self):
  46. self.assertEqual(
  47. self.before_template_id.display_name, "Top template (Top)",
  48. )
  49. self.assertEqual(
  50. self.after_template_id.display_name, "Bottom template (Bottom)",
  51. )
  52. def test_general_template(self):
  53. # Need to force _compute because only trigger when partner_id have changed
  54. self.user._compute_comment_template_ids()
  55. # Check getting default comment template
  56. self.assertTrue(self.before_template_id in self.user.comment_template_ids)
  57. self.assertTrue(self.after_template_id in self.user.comment_template_ids)
  58. def test_partner_template(self):
  59. self.partner2_id.base_comment_template_ids = [
  60. (4, self.before_template_id.id),
  61. (4, self.after_template_id.id),
  62. ]
  63. self.assertTrue(
  64. self.before_template_id in self.partner2_id.base_comment_template_ids
  65. )
  66. self.assertTrue(
  67. self.after_template_id in self.partner2_id.base_comment_template_ids
  68. )
  69. def test_partner_template_domain(self):
  70. # Check getting the comment template if domain is set
  71. self.partner2_id.base_comment_template_ids = [
  72. (4, self.before_template_id.id),
  73. (4, self.after_template_id.id),
  74. ]
  75. self.before_template_id.domain = "[('id', 'in', %s)]" % self.user.ids
  76. self.assertTrue(
  77. self.before_template_id in self.partner2_id.base_comment_template_ids
  78. )
  79. self.assertTrue(
  80. self.before_template_id not in self.partner_id.base_comment_template_ids
  81. )