From 17fa4c8c1d85edf8fd4fed71e3d2708db6b40cec Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Mon, 27 Jun 2016 00:51:21 +0200 Subject: [PATCH] Phone numbers are now clickable in tree view Replace spaces by non-breaking-spaces --- base_phone/fields.py | 2 ++ base_phone/static/src/js/phone_widget.js | 28 ++++++++++-------------- base_phone/tests/test_phone.py | 16 +++++++------- crm_phone/tests/test_crm_phone.py | 10 ++++----- 4 files changed, 27 insertions(+), 29 deletions(-) diff --git a/base_phone/fields.py b/base_phone/fields.py index 0e3d409..495c358 100644 --- a/base_phone/fields.py +++ b/base_phone/fields.py @@ -45,6 +45,8 @@ class Phone(fields.Char): res_parse = phonenumbers.parse(res) res = phonenumbers.format_number( res_parse, phonenumbers.PhoneNumberFormat.INTERNATIONAL) + narrow_no_break_space = u'\u202f' + res = res.replace(' ', narrow_no_break_space) except: pass # print 'cache value', res diff --git a/base_phone/static/src/js/phone_widget.js b/base_phone/static/src/js/phone_widget.js index 3126b3d..52679f4 100644 --- a/base_phone/static/src/js/phone_widget.js +++ b/base_phone/static/src/js/phone_widget.js @@ -131,30 +131,26 @@ if(!core.form_widget_registry.get('phone')){ core.form_widget_registry.add('phone', FieldPhone); } -/* -var Column = require('web.ListView'); -var ColumnPhone = Column.extend({ +var treewidgets = require('web.ListView'); + +var ColumnPhone = treewidgets.Column.extend({ // ability to add widget="phone" in TREE view _format: function(row_data, options) { - console.log('row_data=' + row_data); - console.log('options='); - console.log(options); - var value = row_data[this.id].value; - if (value) { - readable_space = formatInternational('', value); - readable_no_break_space = readable_space.replace(/\s/g, ' '); - console('special return'); - return readable_no_break_space; - } - console.log('return normal'); + var value = row_data[this.id].value; + if (value) { + return _.template("<%-text%>")({ + href: value.replace(' ', ''), + text: value + }); + } return this._super(row_data, options); } }); + if (!core.list_widget_registry.get('phone')) { core.list_widget_registry.add('field.phone', ColumnPhone); -// a mon avis, il y a une mauvaise compréhension : fields.phone signifiera fields.Phone dans le python -} */ +} }); diff --git a/base_phone/tests/test_phone.py b/base_phone/tests/test_phone.py index 9986890..59cec5e 100644 --- a/base_phone/tests/test_phone.py +++ b/base_phone/tests/test_phone.py @@ -17,9 +17,9 @@ class TestPhone(TransactionCase): 'mobile': '06.42.77.42.66', 'fax': '(0) 1 45 42 12 42', }) - self.assertEquals(partner1.phone, '+33 4 72 08 87 32') - self.assertEquals(partner1.mobile, '+33 6 42 77 42 66') - self.assertEquals(partner1.fax, '+33 1 45 42 12 42') + self.assertEquals(partner1.phone, u'+33 4 72 08 87 32') + self.assertEquals(partner1.mobile, u'+33 6 42 77 42 66') + self.assertEquals(partner1.fax, u'+33 1 45 42 12 42') # Create a partner with country self.env.ref('base.res_partner_12').country_id =\ self.env.ref('base.ch').id @@ -31,22 +31,22 @@ class TestPhone(TransactionCase): 'mobile': '(0) 79 606 42 42', }) self.assertEquals(partner2.country_id, self.env.ref('base.ch')) - self.assertEquals(partner2.phone, '+41 21 619 10 10') - self.assertEquals(partner2.mobile, '+41 79 606 42 42') + self.assertEquals(partner2.phone, u'+41 21 619 10 10') + self.assertEquals(partner2.mobile, u'+41 79 606 42 42') # Write on an existing partner agrolait = self.env.ref('base.res_partner_2') self.assertEquals(agrolait.country_id, self.env.ref('base.be')) agrolait.write({'phone': '(0) 2 391 43 74'}) - self.assertEquals(agrolait.phone, '+32 2 391 43 74') + self.assertEquals(agrolait.phone, u'+32 2 391 43 74') # 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, }) - self.assertEquals(agrolait.fax, '+33 4 72 89 32 43') + self.assertEquals(agrolait.fax, u'+33 4 72 89 32 43') # Write an invalid phone number partner2.fax = '42' - self.assertEquals(partner2.fax, '42') + self.assertEquals(partner2.fax, u'42') # Test get_name_from_phone_number pco = self.env['phone.common'] name = pco.get_name_from_phone_number('0642774266') diff --git a/crm_phone/tests/test_crm_phone.py b/crm_phone/tests/test_crm_phone.py index 2bda8dc..5df13be 100644 --- a/crm_phone/tests/test_crm_phone.py +++ b/crm_phone/tests/test_crm_phone.py @@ -17,8 +17,8 @@ class TestCRMPhone(TransactionCase): 'fax': '(0) 1 45 44 42 43', 'country_id': self.env.ref('base.fr').id, }) - self.assertEquals(lead1.mobile, '+33 6 42 77 42 77') - self.assertEquals(lead1.fax, '+33 1 45 44 42 43') + self.assertEquals(lead1.mobile, u'+33 6 42 77 42 77') + self.assertEquals(lead1.fax, u'+33 1 45 44 42 43') lead2 = clo.create({ 'name': u'Automobile Odoo deployment', 'partner_name': u'Kia', @@ -26,19 +26,19 @@ class TestCRMPhone(TransactionCase): 'country_id': self.env.ref('base.ch').id, 'phone': '04 31 23 45 67', }) - self.assertEquals(lead2.phone, '+41 43 123 45 67') + self.assertEquals(lead2.phone, u'+41 43 123 45 67') lead3 = clo.create({ 'name': 'Angela Strasse', 'country_id': self.env.ref('base.de').id, }) lead3.write({'phone': '08912345678'}) - self.assertEquals(lead3.phone, '+49 89 12345678') + self.assertEquals(lead3.phone, u'+49 89 12345678') lead4 = clo.create({ 'name': 'Large Odoo deployment', 'partner_id': self.env.ref('base.res_partner_2').id, }) lead4.write({'mobile': '(0) 2-391-43-75'}) - self.assertEquals(lead4.mobile, '+32 2 391 43 75') + self.assertEquals(lead4.mobile, u'+32 2 391 43 75') pco = self.env['phone.common'] name = pco.get_name_from_phone_number('0642774277') self.assertEquals(name, 'Jacques Toufaux (Ford)')