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.

117 lines
4.8 KiB

  1. # Copyright 2016-2019 Akretion France
  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.common import TransactionCase
  5. class TestCRMPhone(TransactionCase):
  6. def test_phone(self):
  7. company = self.env.ref('base.main_company')
  8. fr_country_id = self.env.ref('base.fr').id
  9. company.country_id = fr_country_id
  10. rpo = self.env['res.partner']
  11. # Create an existing partner without country
  12. partner1 = rpo.create({
  13. 'name': 'Pierre Paillet',
  14. 'phone': '04-72-08-87-32',
  15. 'mobile': '06.42.77.42.66',
  16. })
  17. partner1._onchange_phone_validation()
  18. partner1._onchange_mobile_validation()
  19. self.assertEquals(partner1.phone, '+33 4 72 08 87 32')
  20. self.assertEquals(partner1.mobile, '+33 6 42 77 42 66')
  21. # Create a partner with country
  22. parent_partner2 = rpo.create({
  23. 'name': 'C2C',
  24. 'country_id': self.env.ref('base.ch').id,
  25. })
  26. partner2 = rpo.create({
  27. 'name': 'Joël Grand-Guillaume',
  28. 'parent_id': parent_partner2.id,
  29. 'phone': '(0) 21 619 10 10',
  30. 'mobile': '(0) 79 606 42 42',
  31. })
  32. partner2._onchange_phone_validation()
  33. partner2._onchange_mobile_validation()
  34. self.assertEquals(partner2.country_id, self.env.ref('base.ch'))
  35. self.assertEquals(partner2.phone, '+41 21 619 10 10')
  36. self.assertEquals(partner2.mobile, '+41 79 606 42 42')
  37. # Write on an existing partner
  38. partner3 = rpo.create({
  39. 'name': 'Belgian corp',
  40. 'country_id': self.env.ref('base.be').id,
  41. })
  42. partner3.write({'phone': '(0) 2 391 43 74'})
  43. partner3._onchange_phone_validation()
  44. self.assertEquals(partner3.phone, '+32 2 391 43 74')
  45. # Write on an existing partner with country at the same time
  46. partner3.write({
  47. 'phone': '04 72 89 32 43',
  48. 'country_id': fr_country_id,
  49. })
  50. partner3._onchange_phone_validation()
  51. self.assertEquals(partner3.phone, '+33 4 72 89 32 43')
  52. # Test get_name_from_phone_number
  53. pco = self.env['phone.common']
  54. name = pco.get_name_from_phone_number('0642774266')
  55. self.assertEquals(name, 'Pierre Paillet')
  56. name2 = pco.get_name_from_phone_number('0041216191010')
  57. self.assertEquals(name2, 'C2C, Joël Grand-Guillaume')
  58. # Test against the POS bug
  59. # https://github.com/OCA/connector-telephony/issues/113
  60. # When we edit/create a partner from the POS,
  61. # the country_id key in create(vals) is given as a string !
  62. partnerpos = rpo.create({
  63. 'name': 'POS customer',
  64. 'phone': '04-72-08-87-42',
  65. 'country_id': str(fr_country_id),
  66. })
  67. partnerpos._onchange_phone_validation()
  68. self.assertEquals(partnerpos.phone, '+33 4 72 08 87 42')
  69. self.assertEquals(partnerpos.country_id.id, fr_country_id)
  70. def test_crm_phone(self):
  71. clo = self.env['crm.lead']
  72. lead1 = clo.create({
  73. 'name': 'The super deal of the year !',
  74. 'partner_name': 'Ford',
  75. 'contact_name': 'Jacques Toufaux',
  76. 'mobile': '06.42.77.42.77',
  77. 'country_id': self.env.ref('base.fr').id,
  78. })
  79. lead1._onchange_mobile_validation()
  80. self.assertEquals(lead1.mobile, '+33 6 42 77 42 77')
  81. lead2 = clo.create({
  82. 'name': 'Automobile Odoo deployment',
  83. 'partner_name': 'Kia',
  84. 'contact_name': 'Mikaël Content',
  85. 'country_id': self.env.ref('base.ch').id,
  86. 'phone': '04 31 23 45 67',
  87. })
  88. lead2._onchange_phone_validation()
  89. self.assertEquals(lead2.phone, '+41 43 123 45 67')
  90. lead3 = clo.create({
  91. 'name': 'Angela Strasse',
  92. 'country_id': self.env.ref('base.de').id,
  93. 'phone': '08912345678',
  94. })
  95. lead3._onchange_phone_validation()
  96. self.assertEquals(lead3.phone, '+49 89 12345678')
  97. partner4 = self.env['res.partner'].create({
  98. 'name': 'Belgian Guy',
  99. 'country_id': self.env.ref('base.be').id,
  100. })
  101. lead4 = clo.create({
  102. 'name': 'Large Odoo deployment',
  103. 'partner_id': partner4.id,
  104. 'mobile': '(0) 2-391-43-75',
  105. })
  106. lead4._onchange_mobile_validation()
  107. self.assertEquals(lead4.mobile, '+32 2 391 43 75')
  108. pco = self.env['phone.common']
  109. name = pco.get_name_from_phone_number('0642774277')
  110. self.assertEquals(name, 'Jacques Toufaux (Ford)')
  111. name2 = pco.get_name_from_phone_number('0041431234567')
  112. self.assertEquals(name2, u'Mikaël Content (Kia)')