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.

66 lines
2.9 KiB

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