Skip to content

Commit

Permalink
Restore fix for partner creation from POS bug OCA#113
Browse files Browse the repository at this point in the history
Add test for POS partner bug
  • Loading branch information
alexis-via authored and mimusica committed Aug 1, 2020
1 parent 3dfe023 commit 1d7e041
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
8 changes: 6 additions & 2 deletions base_phone/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
16 changes: 14 additions & 2 deletions base_phone/tests/test_phone.py
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -40,7 +41,7 @@ def test_phone(self):
# 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
Expand All @@ -52,3 +53,14 @@ def test_phone(self):
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)

0 comments on commit 1d7e041

Please sign in to comment.