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.

54 lines
2.3 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. company.country_id = self.env.ref('base.fr').id
  8. rpo = self.env['res.partner']
  9. # Create an existing partner without country
  10. partner1 = rpo.create({
  11. 'name': u'Pierre Paillet',
  12. 'phone': '04-72-08-87-32',
  13. 'mobile': '06.42.77.42.66',
  14. 'fax': '(0) 1 45 42 12 42',
  15. })
  16. self.assertEquals(partner1.phone, u'+33 4 72 08 87 32')
  17. self.assertEquals(partner1.mobile, u'+33 6 42 77 42 66')
  18. self.assertEquals(partner1.fax, u'+33 1 45 42 12 42')
  19. # Create a partner with country
  20. self.env.ref('base.res_partner_12').country_id =\
  21. self.env.ref('base.ch').id
  22. partner2 = rpo.create({
  23. 'name': u'Joël Grand-Guillaume',
  24. 'parent_id': self.env.ref('base.res_partner_12').id,
  25. 'phone': '(0) 21 619 10 10',
  26. 'mobile': '(0) 79 606 42 42',
  27. })
  28. self.assertEquals(partner2.country_id, self.env.ref('base.ch'))
  29. self.assertEquals(partner2.phone, u'+41 21 619 10 10')
  30. self.assertEquals(partner2.mobile, u'+41 79 606 42 42')
  31. # Write on an existing partner
  32. agrolait = self.env.ref('base.res_partner_2')
  33. self.assertEquals(agrolait.country_id, self.env.ref('base.be'))
  34. agrolait.write({'phone': '(0) 2 391 43 74'})
  35. self.assertEquals(agrolait.phone, u'+32 2 391 43 74')
  36. # Write on an existing partner with country at the same time
  37. agrolait.write({
  38. 'fax': '04 72 89 32 43',
  39. 'country_id': self.env.ref('base.fr').id,
  40. })
  41. self.assertEquals(agrolait.fax, u'+33 4 72 89 32 43')
  42. # Write an invalid phone number
  43. partner2.fax = '42'
  44. self.assertEquals(partner2.fax, u'42')
  45. # Test get_name_from_phone_number
  46. pco = self.env['phone.common']
  47. name = pco.get_name_from_phone_number('0642774266')
  48. self.assertEquals(name, 'Pierre Paillet')
  49. name2 = pco.get_name_from_phone_number('0041216191010')
  50. self.assertEquals(name2, u'Joël Grand-Guillaume (Camptocamp)')