diff --git a/asterisk_click2dial/asterisk_click2dial.py b/asterisk_click2dial/asterisk_click2dial.py index 5be18fe..125f910 100644 --- a/asterisk_click2dial/asterisk_click2dial.py +++ b/asterisk_click2dial/asterisk_click2dial.py @@ -347,7 +347,8 @@ class res_users(orm.Model): help="Caller ID used for the calls initiated by this user."), # You'd probably think: Asterisk should reuse the callerID of sip.conf! # But it cannot, cf - # http://lists.digium.com/pipermail/asterisk-users/2012-January/269787.html + # http://lists.digium.com/pipermail/asterisk-users/ + # 2012-January/269787.html 'cdraccount': fields.char( 'CDR Account', size=50, help="Call Detail Record (CDR) account used for billing this " diff --git a/base_phone/__openerp__.py b/base_phone/__openerp__.py index 7c46812..67fcb24 100644 --- a/base_phone/__openerp__.py +++ b/base_phone/__openerp__.py @@ -77,6 +77,7 @@ for any help or question about this module. ], 'qweb': ['static/src/xml/*.xml'], 'demo': ['base_phone_demo.xml'], + 'test': ['test/phonenum.yml'], 'images': [], 'installable': True, } diff --git a/base_phone/base_phone.py b/base_phone/base_phone.py index 91309d7..51a70ee 100644 --- a/base_phone/base_phone.py +++ b/base_phone/base_phone.py @@ -63,6 +63,8 @@ class phone_common(orm.AbstractModel): def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=None, context=None): """Reformat phone numbers in E.164 format i.e. +33141981242""" + if context is None: + context = {} if phonefields is None: phonefields = [ 'phone', 'partner_phone', 'work_phone', 'fax', @@ -89,6 +91,12 @@ class phone_common(orm.AbstractModel): try: res_parse = phonenumbers.parse( vals.get(field), user_countrycode) + vals[field] = phonenumbers.format_number( + res_parse, phonenumbers.PhoneNumberFormat.E164) + if init_value != vals[field]: + _logger.info( + "%s initial value: '%s' updated value: '%s'" + % (field, init_value, vals[field])) except Exception, e: # I do BOTH logger and raise, because: # raise is usefull when the record is created/written @@ -96,19 +104,14 @@ class phone_common(orm.AbstractModel): # logger is usefull when the record is created/written # via the webservices _logger.error( - "Cannot reformat the phone number %s to " + "Cannot reformat the phone number '%s' to " "international format" % vals.get(field)) - raise orm.except_orm( - _('Error:'), - _("Cannot reformat the phone number '%s' to " - "international format. Error message: %s") - % (vals.get(field), e)) - vals[field] = phonenumbers.format_number( - res_parse, phonenumbers.PhoneNumberFormat.E164) - if init_value != vals[field]: - _logger.info( - "%s initial value: '%s' updated value: '%s'" - % (field, init_value, vals[field])) + if context.get('raise_if_phone_parse_fails'): + raise orm.except_orm( + _('Error:'), + _("Cannot reformat the phone number '%s' to " + "international format. Error message: %s") + % (vals.get(field), e)) return vals def get_name_from_phone_number( diff --git a/base_phone/res_partner_view.xml b/base_phone/res_partner_view.xml index fdc1996..28bf5e5 100644 --- a/base_phone/res_partner_view.xml +++ b/base_phone/res_partner_view.xml @@ -56,5 +56,9 @@ + + {'search_default_customer':1, 'raise_if_phone_parse_fails': True} + + diff --git a/base_phone/static/src/js/phone_widget.js b/base_phone/static/src/js/phone_widget.js index 07f358d..478a30f 100644 --- a/base_phone/static/src/js/phone_widget.js +++ b/base_phone/static/src/js/phone_widget.js @@ -27,9 +27,15 @@ openerp.base_phone = function (instance) { href = 'tel:' + phone_num; href_text = formatInternational('', phone_num) || ''; } - this.$el.find('a.oe_form_uri').attr('href', href).text(href_text); + if (href_text) { + this.$el.find('a.oe_form_uri').attr('href', href).text(href_text); + this.$el.find('span.oe_form_char_content').text(''); + } else { + this.$el.find('a.oe_form_uri').attr('href', '').text(''); + this.$el.find('span.oe_form_char_content').text(phone_num || ''); + } var click2dial_text = ''; - if (phone_num && !this.options.dial_button_invisible) { + if (href_text && !this.options.dial_button_invisible) { click2dial_text = _t('Dial'); } this.$el.find('#click2dial') @@ -92,10 +98,19 @@ openerp.base_phone = function (instance) { this._super(); } else { var fax_num = this.get('value'); + //console.log('BASE_PHONE fax_num = %s', fax_num); + var href = '#'; + var href_text = ''; if (fax_num) { - this.$el.find('a.oe_form_uri') - .attr('href', 'fax:' + fax_num) - .text(formatInternational('', fax_num) || ''); + href = 'fax:' + fax_num; + href_text = formatInternational('', fax_num) || ''; + } + if (href_text) { + this.$el.find('a.oe_form_uri').attr('href', href).text(href_text); + this.$el.find('span.oe_form_char_content').text(''); + } else { + this.$el.find('a.oe_form_uri').attr('href', '').text(''); + this.$el.find('span.oe_form_char_content').text(fax_num || ''); } } }, diff --git a/base_phone/static/src/xml/phone.xml b/base_phone/static/src/xml/phone.xml index 0cd269c..d1d4a59 100644 --- a/base_phone/static/src/xml/phone.xml +++ b/base_phone/static/src/xml/phone.xml @@ -10,7 +10,7 @@ - +