Browse Source

Fix bug #17: don't raise by default on write/create

As a consequence, we can have non E.164 values inside the phone/mobile/fax fields: in this case, we don't display an href link on the field and we don't display the Dial button.
Fix show old number on paging for fax field
pull/18/head
Alexis de Lattre 10 years ago
parent
commit
779bd1e128
  1. 26
      base_phone/base_phone.py
  2. 25
      base_phone/static/src/js/phone_widget.js
  3. 6
      base_phone/static/src/xml/phone.xml

26
base_phone/base_phone.py

@ -61,6 +61,7 @@ class phone_common(orm.AbstractModel):
return result return result
def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=None, def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=None,
raise_if_parse_fails=False,
context=None): context=None):
"""Reformat phone numbers in E.164 format i.e. +33141981242""" """Reformat phone numbers in E.164 format i.e. +33141981242"""
if phonefields is None: if phonefields is None:
@ -89,6 +90,12 @@ class phone_common(orm.AbstractModel):
try: try:
res_parse = phonenumbers.parse( res_parse = phonenumbers.parse(
vals.get(field), user_countrycode) 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: except Exception, e:
# I do BOTH logger and raise, because: # I do BOTH logger and raise, because:
# raise is usefull when the record is created/written # 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 # logger is usefull when the record is created/written
# via the webservices # via the webservices
_logger.error( _logger.error(
"Cannot reformat the phone number %s to "
"Cannot reformat the phone number '%s' to "
"international format" % vals.get(field)) "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 return vals
def get_name_from_phone_number( def get_name_from_phone_number(

25
base_phone/static/src/js/phone_widget.js

@ -27,9 +27,15 @@ openerp.base_phone = function (instance) {
href = 'tel:' + phone_num; href = 'tel:' + phone_num;
href_text = formatInternational('', 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 = ''; var click2dial_text = '';
if (phone_num && !this.options.dial_button_invisible) {
if (href_text && !this.options.dial_button_invisible) {
click2dial_text = _t('Dial'); click2dial_text = _t('Dial');
} }
this.$el.find('#click2dial') this.$el.find('#click2dial')
@ -92,10 +98,19 @@ openerp.base_phone = function (instance) {
this._super(); this._super();
} else { } else {
var fax_num = this.get('value'); var fax_num = this.get('value');
//console.log('BASE_PHONE fax_num = %s', fax_num);
var href = '#';
var href_text = '';
if (fax_num) { 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 || '');
} }
} }
}, },

6
base_phone/static/src/xml/phone.xml

@ -10,7 +10,7 @@
<t t-name="FieldPhone"> <t t-name="FieldPhone">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style"> <span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<t t-if="widget.get('effective_readonly')"> <t t-if="widget.get('effective_readonly')">
<a href="#" class="oe_form_uri"/>
<a href="#" class="oe_form_uri"/><span class="oe_form_char_content"/>
<!-- <!--
You should add the following "<a .. />" in your IPBX-specific You should add the following "<a .. />" in your IPBX-specific
module (such as asterisk_click2dial) via <t t-extend="FieldPhone"> module (such as asterisk_click2dial) via <t t-extend="FieldPhone">
@ -33,7 +33,9 @@
<t t-name="FieldFax"> <t t-name="FieldFax">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style"> <span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri"/>
<t t-if="widget.get('effective_readonly')">
<a href="#" class="oe_form_uri"/><span class="oe_form_char_content"/>
</t>
<t t-if="!widget.get('effective_readonly')"> <t t-if="!widget.get('effective_readonly')">
<div> <div>
<input type="text" <input type="text"

Loading…
Cancel
Save