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.

69 lines
3.0 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo.tests.common import TransactionCase
  6. class TestPhone(TransactionCase):
  7. def test_phone(self):
  8. company = self.env.ref('base.main_company')
  9. fr_country_id = self.env.ref('base.fr').id
  10. company.country_id = fr_country_id
  11. rpo = self.env['res.partner']
  12. # Create an existing partner without country
  13. partner1 = rpo.create({
  14. 'name': u'Pierre Paillet',
  15. 'phone': '04-72-08-87-32',
  16. 'mobile': '06.42.77.42.66',
  17. 'fax': '(0) 1 45 42 12 42',
  18. })
  19. self.assertEquals(partner1.phone, u'+33 4 72 08 87 32')
  20. self.assertEquals(partner1.mobile, u'+33 6 42 77 42 66')
  21. self.assertEquals(partner1.fax, u'+33 1 45 42 12 42')
  22. # Create a partner with country
  23. self.env.ref('base.res_partner_12').country_id =\
  24. self.env.ref('base.ch').id
  25. partner2 = rpo.create({
  26. 'name': u'Joël Grand-Guillaume',
  27. 'parent_id': self.env.ref('base.res_partner_12').id,
  28. 'phone': '(0) 21 619 10 10',
  29. 'mobile': '(0) 79 606 42 42',
  30. })
  31. self.assertEquals(partner2.country_id, self.env.ref('base.ch'))
  32. self.assertEquals(partner2.phone, u'+41 21 619 10 10')
  33. self.assertEquals(partner2.mobile, u'+41 79 606 42 42')
  34. # Write on an existing partner
  35. agrolait = self.env.ref('base.res_partner_2')
  36. self.assertEquals(agrolait.country_id, self.env.ref('base.be'))
  37. agrolait.write({'phone': '(0) 2 391 43 74'})
  38. self.assertEquals(agrolait.phone, u'+32 2 391 43 74')
  39. # Write on an existing partner with country at the same time
  40. agrolait.write({
  41. 'fax': '04 72 89 32 43',
  42. 'country_id': fr_country_id,
  43. })
  44. self.assertEquals(agrolait.fax, u'+33 4 72 89 32 43')
  45. # Write an invalid phone number
  46. partner2.fax = '42'
  47. self.assertEquals(partner2.fax, u'42')
  48. # Test get_name_from_phone_number
  49. pco = self.env['phone.common']
  50. name = pco.get_name_from_phone_number('0642774266')
  51. self.assertEquals(name, 'Pierre Paillet')
  52. name2 = pco.get_name_from_phone_number('0041216191010')
  53. self.assertEquals(name2, u'Joël Grand-Guillaume (Camptocamp)')
  54. # Test against the POS bug
  55. # https://github.com/OCA/connector-telephony/issues/113
  56. # When we edit/create a partner from the POS,
  57. # the country_id key in create(vals) is given as a string !
  58. partnerpos = rpo.create({
  59. 'name': u'POS customer',
  60. 'phone': '04-72-08-87-42',
  61. 'country_id': str(fr_country_id),
  62. })
  63. self.assertEquals(partnerpos.phone, u'+33 4 72 08 87 42')
  64. self.assertEquals(partnerpos.country_id.id, fr_country_id)