Browse Source

Restore fix for partner creation from POS bug #113

Add test for POS partner bug
pull/109/head
Alexis de Lattre 8 years ago
parent
commit
6c68f3e7cf
  1. 8
      base_phone/common.py
  2. 16
      base_phone/tests/test_phone.py

8
base_phone/common.py

@ -42,12 +42,16 @@ def convert_all_phone_fields(self, vals, fields_to_convert):
country = False
if country_key:
if country_key in loc_vals:
country = self.env['res.country'].browse(vals[country_key])
# Warning: when we edit or create a partner from the
# POS frontend vals[country_key] is a string !
country = self.env['res.country'].browse(
int(vals[country_key]))
else:
country = self[country_key]
if partner_key and not country:
if partner_key in loc_vals:
partner = self.env['res.partner'].browse(vals[partner_key])
partner = self.env['res.partner'].browse(
int(vals[partner_key]))
else:
partner = self[partner_key]
if partner:

16
base_phone/tests/test_phone.py

@ -8,7 +8,8 @@ class TestPhone(TransactionCase):
def test_phone(self):
company = self.env.ref('base.main_company')
company.country_id = self.env.ref('base.fr').id
fr_country_id = self.env.ref('base.fr').id
company.country_id = fr_country_id
rpo = self.env['res.partner']
# Create an existing partner without country
partner1 = rpo.create({
@ -40,7 +41,7 @@ class TestPhone(TransactionCase):
# Write on an existing partner with country at the same time
agrolait.write({
'fax': '04 72 89 32 43',
'country_id': self.env.ref('base.fr').id,
'country_id': fr_country_id,
})
self.assertEquals(agrolait.fax, u'+33 4 72 89 32 43')
# Write an invalid phone number
@ -52,3 +53,14 @@ class TestPhone(TransactionCase):
self.assertEquals(name, 'Pierre Paillet')
name2 = pco.get_name_from_phone_number('0041216191010')
self.assertEquals(name2, u'Joël Grand-Guillaume (Camptocamp)')
# Test against the POS bug
# https://github.com/OCA/connector-telephony/issues/113
# When we edit/create a partner from the POS,
# the country_id key in create(vals) is given as a string !
partnerpos = rpo.create({
'name': u'POS customer',
'phone': '04-72-08-87-42',
'country_id': str(fr_country_id),
})
self.assertEquals(partnerpos.phone, u'+33 4 72 08 87 42')
self.assertEquals(partnerpos.country_id.id, fr_country_id)
Loading…
Cancel
Save