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.

74 lines
2.6 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.fr_country_id = self.env.ref("base.fr").id
  11. self.partner_simple = self.env["res.partner"].create(
  12. {
  13. "name": "Alexia Payet",
  14. "mobile": " +33699887766 ",
  15. "country_id": self.fr_country_id,
  16. }
  17. )
  18. self.partner_simple._onchange_mobile_validation()
  19. self.company1_id = self.env.ref("base.main_company").id
  20. partner_company = self.env["res.partner"].create(
  21. {
  22. "name": "Test Company",
  23. "is_company": True,
  24. "country_id": self.env.ref("base.fr").id,
  25. }
  26. )
  27. self.company2_id = (
  28. self.env["res.company"]
  29. .create(
  30. {
  31. "name": "Test Company",
  32. "partner_id": partner_company.id,
  33. "currency_id": self.env.ref("base.EUR").id,
  34. }
  35. )
  36. .id
  37. )
  38. def test_partner_duplicate_simple(self):
  39. partner1 = self.env["res.partner"].create(
  40. {
  41. "name": "Test regular",
  42. "mobile": "06 99 88 77 65",
  43. "country_id": self.fr_country_id,
  44. }
  45. )
  46. partner1._onchange_mobile_validation()
  47. self.assertFalse(partner1.same_mobile_partner_id)
  48. partner1.write({"mobile": " 06 99 88 77 66"})
  49. partner1._onchange_mobile_validation()
  50. self.assertEqual(partner1.same_mobile_partner_id, self.partner_simple)
  51. def test_partner_duplicate_multi_company(self):
  52. partner_company1 = self.env["res.partner"].create(
  53. {
  54. "name": "Toto",
  55. "mobile": "+33 6 11 22 33 44",
  56. "company_id": self.company1_id,
  57. }
  58. )
  59. partner_company2 = self.env["res.partner"].create(
  60. {
  61. "name": "Toto",
  62. "mobile": "+33 6 11 22 33 44",
  63. "company_id": self.company2_id,
  64. }
  65. )
  66. self.assertFalse(partner_company1.same_mobile_partner_id)
  67. self.assertFalse(partner_company2.same_mobile_partner_id)
  68. partner_company2.write({"company_id": False})
  69. self.assertEqual(partner_company2.same_mobile_partner_id, partner_company1)