diff --git a/base_phone/base_phone.py b/base_phone/base_phone.py index 91309d7..6b9b789 100644 --- a/base_phone/base_phone.py +++ b/base_phone/base_phone.py @@ -61,6 +61,7 @@ class phone_common(orm.AbstractModel): return result def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=None, + raise_if_parse_fails=False, context=None): """Reformat phone numbers in E.164 format i.e. +33141981242""" if phonefields is None: @@ -89,6 +90,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 +103,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 raise_if_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/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 @@ - +