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.

127 lines
4.8 KiB

  1. # Copyright 2021 Akretion France (http://www.akretion.com/)
  2. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
  4. from odoo.tests import tagged
  5. from odoo.tests.common import TransactionCase
  6. @tagged("post_install", "-at_install")
  7. class TestResPartner(TransactionCase):
  8. def setUp(self):
  9. super().setUp()
  10. self.partner_simple = self.env["res.partner"].create(
  11. {
  12. "name": "Alexia Payet",
  13. "email": "alexia.payet@akretion.com",
  14. }
  15. )
  16. self.partner_space_start = self.env["res.partner"].create(
  17. {
  18. "name": "Alexia Payet",
  19. "email": " alexia.payet@videolan.org",
  20. }
  21. )
  22. self.partner_space_end = self.env["res.partner"].create(
  23. {
  24. "name": "Alexia Payet",
  25. "email": "alexia.payet@via.ecp.fr ",
  26. }
  27. )
  28. self.company1_id = self.env.ref("base.main_company").id
  29. partner_company = self.env["res.partner"].create(
  30. {
  31. "name": "Test Company",
  32. "is_company": True,
  33. "country_id": self.env.ref("base.fr").id,
  34. }
  35. )
  36. self.company2_id = (
  37. self.env["res.company"]
  38. .create(
  39. {
  40. "name": "Test Company",
  41. "partner_id": partner_company.id,
  42. "currency_id": self.env.ref("base.EUR").id,
  43. }
  44. )
  45. .id
  46. )
  47. def test_partner_duplicate_simple(self):
  48. partner1 = self.env["res.partner"].create(
  49. {
  50. "name": "Test regular",
  51. "email": "alexis.payet@akretion.com",
  52. }
  53. )
  54. self.assertFalse(partner1.same_email_partner_id)
  55. partner1.write({"email": "alexia.payet@akretion.com"})
  56. self.assertEqual(partner1.same_email_partner_id, self.partner_simple)
  57. def test_partner_duplicate_spaces_caps(self):
  58. partner2 = self.env["res.partner"].create(
  59. {
  60. "name": "Test space",
  61. "email": "alexia.payet@videolan.org",
  62. }
  63. )
  64. self.assertEqual(partner2.same_email_partner_id, self.partner_space_start)
  65. partner2.write({"email": "alexia.payet@videolan.org "})
  66. self.assertEqual(partner2.same_email_partner_id, self.partner_space_start)
  67. partner2.write({"email": " alexia.payet@videolan.org"})
  68. self.assertEqual(partner2.same_email_partner_id, self.partner_space_start)
  69. partner2.write({"email": " Alexia.Payet@videolan.org "})
  70. self.assertEqual(partner2.same_email_partner_id, self.partner_space_start)
  71. partner2.write({"email": "Alexia.Pazet@videolan.org"})
  72. self.assertFalse(partner2.same_email_partner_id)
  73. partner3 = self.env["res.partner"].create(
  74. {
  75. "name": "Test space2",
  76. "email": "Alexia.Payet@via.ecp.fr",
  77. }
  78. )
  79. self.assertEqual(partner3.same_email_partner_id, self.partner_space_end)
  80. partner3.write({"email": " Alexia.Payet@via.ecp.fr"})
  81. self.assertEqual(partner3.same_email_partner_id, self.partner_space_end)
  82. partner3.write({"email": " Alexia.Payet@Via.Ecp.Fr "})
  83. self.assertEqual(partner3.same_email_partner_id, self.partner_space_end)
  84. def test_partner_duplicate_multi_company(self):
  85. partner_company1 = self.env["res.partner"].create(
  86. {
  87. "name": "Toto",
  88. "email": "alexandra.payet@via.ecp.fr",
  89. "company_id": self.company1_id,
  90. }
  91. )
  92. partner_company2 = self.env["res.partner"].create(
  93. {
  94. "name": "Toto",
  95. "email": "alexandra.payet@via.ecp.fr",
  96. "company_id": self.company2_id,
  97. }
  98. )
  99. self.assertFalse(partner_company1.same_email_partner_id)
  100. self.assertFalse(partner_company2.same_email_partner_id)
  101. partner_company2.write({"company_id": False})
  102. self.assertEqual(partner_company2.same_email_partner_id, partner_company1)
  103. def test_partner_duplicate_parent_child(self):
  104. parent_partner = self.env["res.partner"].create(
  105. {
  106. "name": "Rocket Corp",
  107. "is_company": True,
  108. "email": "contact@rocket.com",
  109. }
  110. )
  111. child_partner = self.env["res.partner"].create(
  112. {
  113. "name": "M. Dupont",
  114. "is_company": False,
  115. "parent_id": parent_partner.id,
  116. "email": "contact@rocket.com",
  117. }
  118. )
  119. self.assertFalse(parent_partner.same_email_partner_id)
  120. self.assertFalse(child_partner.same_email_partner_id)