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.

55 lines
2.4 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. 'use_parent_address': True,
  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': self.env.ref('base.fr').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)')