From 6e7a2b5c2feb5970c734deb26cb7a45f35756cf0 Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Thu, 11 Jul 2013 00:16:18 +0200 Subject: [PATCH] The regular "phone", "mobile" and "fax" fields now store the phone number in E164 format ; the special fields phone_e164, mobile_e164 and fax_164 are not used any more. Add phone widget that handle the "nice" display of phone number to the user. IMPORTANT : you need to restart the wizard "Reformat all phone numbers" in order to put the "phone", "mobile" and "fax" fields in E164 format (without spaces). --- asterisk_click2dial/__openerp__.py | 5 + asterisk_click2dial/asterisk_click2dial.py | 37 +- asterisk_click2dial/res_partner_view.xml | 24 +- .../static/lib/js/PhoneFormat.js | 1318 +++++++++++++++++ .../static/src/js/phone_widget.js | 33 + asterisk_click2dial/static/src/xml/phone.xml | 25 + .../wizard/reformat_all_phonenumbers_view.xml | 19 +- asterisk_click2dial_crm/__openerp__.py | 1 + .../asterisk_click2dial_crm.py | 17 - asterisk_click2dial_crm/crm_lead_view.xml | 16 +- .../crm_phonecall_view.xml | 26 + .../crm_claim_view.xml | 2 +- .../asterisk_click2dial_registration.py | 14 - .../registration_view.xml | 14 +- 14 files changed, 1459 insertions(+), 92 deletions(-) create mode 100644 asterisk_click2dial/static/lib/js/PhoneFormat.js create mode 100644 asterisk_click2dial/static/src/js/phone_widget.js create mode 100644 asterisk_click2dial/static/src/xml/phone.xml create mode 100644 asterisk_click2dial_crm/crm_phonecall_view.xml diff --git a/asterisk_click2dial/__openerp__.py b/asterisk_click2dial/__openerp__.py index f1b285e..d87518d 100644 --- a/asterisk_click2dial/__openerp__.py +++ b/asterisk_click2dial/__openerp__.py @@ -60,6 +60,11 @@ A detailed documentation for this module is available on the Akretion Web site : 'security/asterisk_server_security.xml', 'security/ir.model.access.csv', ], + 'js': [ + 'static/src/js/*.js', + 'static/lib/js/*.js', + ], + 'qweb': ['static/src/xml/*.xml'], 'demo': ['asterisk_click2dial_demo.xml'], 'images': [ 'images/sshot-click2dial.jpg', diff --git a/asterisk_click2dial/asterisk_click2dial.py b/asterisk_click2dial/asterisk_click2dial.py index ec6aa2d..b8776cc 100644 --- a/asterisk_click2dial/asterisk_click2dial.py +++ b/asterisk_click2dial/asterisk_click2dial.py @@ -210,7 +210,7 @@ class asterisk_server(osv.osv): def _connect_to_asterisk(self, cr, uid, context=None): ''' - Open the connection to the asterisk manager + Open the connection to the Asterisk Manager Returns an instance of the Asterisk Manager ''' @@ -386,18 +386,15 @@ class asterisk_common(orm.AbstractModel): '''Read the number to dial and call _connect_to_asterisk the right way''' if context is None: context = {} - if not isinstance(context.get('field2dial'), list): - raise osv.except_osv(_('Error :'), "The function action_dial must be called with a 'field2dial' key in the context containing a list ['', ''].") + if not isinstance(context.get('field2dial'), (unicode, str)): + raise osv.except_osv(_('Error :'), "The function action_dial must be called with a 'field2dial' key in the context containing a string ''.") else: phone_field = context.get('field2dial') - erp_number_read = self.read(cr, uid, ids[0], phone_field, context=context) - erp_number_e164 = erp_number_read[phone_field[1]] - erp_number_display = erp_number_read[phone_field[0]] + erp_number_read = self.read(cr, uid, ids[0], [phone_field], context=context) + erp_number_e164 = erp_number_read[phone_field] # Check if the number to dial is not empty - if not erp_number_display: + if not erp_number_e164: raise osv.except_osv(_('Error :'), _('There is no phone number !')) - elif erp_number_display and not erp_number_e164: - raise osv.except_osv(_('Error :'), _("The phone number isn't stored in the standard E.164 format. Try to run the wizard 'Reformat all phone numbers' from the menu Settings > Technical > Asterisk.")) return self.pool['asterisk.server']._dial_with_asterisk(cr, uid, erp_number_e164, context=context) @@ -424,7 +421,7 @@ class asterisk_common(orm.AbstractModel): return result def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=['phone', 'partner_phone', 'fax', 'mobile'], context=None): - """Reformat phone numbers in international format i.e. +33141981242""" + """Reformat phone numbers in E.164 format i.e. +33141981242""" if any([vals.get(field) for field in phonefields]): user = self.pool['res.users'].browse(cr, uid, uid, context=context) # country_id on res.company is a fields.function that looks at @@ -442,7 +439,7 @@ class asterisk_common(orm.AbstractModel): except Exception, e: raise osv.except_osv(_('Error :'), _("Cannot reformat the phone number '%s' to international format. Error message: %s" % (vals.get(field), e))) #print "res_parse=", res_parse - vals[field] = phonenumbers.format_number(res_parse, phonenumbers.PhoneNumberFormat.INTERNATIONAL) + vals[field] = phonenumbers.format_number(res_parse, phonenumbers.PhoneNumberFormat.E164) return vals @@ -452,22 +449,6 @@ class res_partner(osv.osv): _inherit = ['res.partner', 'asterisk.common'] - def format_phonenumber_to_e164(self, cr, uid, ids, name, arg, context=None): - return self.generic_phonenumber_to_e164(cr, uid, ids, [('phone', 'phone_e164'), ('mobile', 'mobile_e164'), ('fax', 'fax_e164')], context=context) - - _columns = { - 'phone_e164': fields.function(format_phonenumber_to_e164, type='char', size=64, string='Phone in E.164 format', readonly=True, multi="e164", store={ - 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['phone'], 10), - }), - 'mobile_e164': fields.function(format_phonenumber_to_e164, type='char', size=64, string='Mobile in E.164 format', readonly=True, multi="e164", store={ - 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['mobile'], 10), - }), - 'fax_e164': fields.function(format_phonenumber_to_e164, type='char', size=64, string='Fax in E.164 format', readonly=True, multi="e164", store={ - 'res.partner': (lambda self, cr, uid, ids, c={}: ids, ['fax'], 10), - }), - } - - def create(self, cr, uid, vals, context=None): vals_reformated = self._generic_reformat_phonenumbers(cr, uid, vals, context=context) return super(res_partner, self).create(cr, uid, vals_reformated, context=context) @@ -514,7 +495,7 @@ class res_partner(osv.osv): # We try to match a phone or mobile number with the same end pg_seach_number = str('%' + end_number_to_match) - res_ids = self.search(cr, uid, ['|', ('phone_e164', 'ilike', pg_seach_number), ('mobile_e164', 'ilike', pg_seach_number)], context=context) + res_ids = self.search(cr, uid, ['|', ('phone', 'ilike', pg_seach_number), ('mobile', 'ilike', pg_seach_number)], context=context) # TODO : use is_number_match() of the phonenumber lib ? if len(res_ids) > 1: _logger.warning(u"There are several partners (IDS = %s) with a phone number ending with '%s'" % (str(res_ids), end_number_to_match)) diff --git a/asterisk_click2dial/res_partner_view.xml b/asterisk_click2dial/res_partner_view.xml index 15d6811..ba7f5a7 100644 --- a/asterisk_click2dial/res_partner_view.xml +++ b/asterisk_click2dial/res_partner_view.xml @@ -19,14 +19,14 @@ - -