Browse Source

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).
pull/7/head
Alexis de Lattre 11 years ago
parent
commit
6e7a2b5c2f
  1. 5
      asterisk_click2dial/__openerp__.py
  2. 37
      asterisk_click2dial/asterisk_click2dial.py
  3. 24
      asterisk_click2dial/res_partner_view.xml
  4. 1318
      asterisk_click2dial/static/lib/js/PhoneFormat.js
  5. 33
      asterisk_click2dial/static/src/js/phone_widget.js
  6. 25
      asterisk_click2dial/static/src/xml/phone.xml
  7. 19
      asterisk_click2dial/wizard/reformat_all_phonenumbers_view.xml
  8. 1
      asterisk_click2dial_crm/__openerp__.py
  9. 17
      asterisk_click2dial_crm/asterisk_click2dial_crm.py
  10. 16
      asterisk_click2dial_crm/crm_lead_view.xml
  11. 26
      asterisk_click2dial_crm/crm_phonecall_view.xml
  12. 2
      asterisk_click2dial_crm_claim/crm_claim_view.xml
  13. 14
      asterisk_click2dial_registration/asterisk_click2dial_registration.py
  14. 14
      asterisk_click2dial_registration/registration_view.xml

5
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',

37
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 ['<phone_field_displayed>', '<phone_field_e164>'].")
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 '<phone_field>'.")
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))

24
asterisk_click2dial/res_partner_view.xml

@ -19,14 +19,14 @@
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="8">
<field name="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</field>
<field name="mobile" position="replace">
<group colspan="2" col="8">
<field name="mobile" colspan="7" />
<button name="action_dial" context="{'field2dial': ['mobile', 'mobile_e164']}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
<field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</field>
</field>
@ -40,26 +40,26 @@
<field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<group colspan="2" col="8">
<field name="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</xpath>
<xpath expr="//group/group/field[@name='mobile']" position="replace">
<group colspan="2" col="8">
<field name="mobile" colspan="7" />
<button name="action_dial" context="{'field2dial': ['mobile', 'mobile_e164']}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
<field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/group/field[@name='phone']" position="replace">
<group colspan="2" col="8">
<field name="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</xpath>
<xpath expr="//form[@string='Contact']/sheet/group/field[@name='mobile']" position="replace">
<group colspan="2" col="8">
<field name="mobile" colspan="7" />
<button name="action_dial" context="{'field2dial': ['mobile', 'mobile_e164']}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
<field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</xpath>
</field>

1318
asterisk_click2dial/static/lib/js/PhoneFormat.js
File diff suppressed because it is too large
View File

33
asterisk_click2dial/static/src/js/phone_widget.js

@ -0,0 +1,33 @@
// Base phone module for OpenERP
// Copyright (C) 2013 Alexis de Lattre <alexis@via.ecp.fr>
// The licence is in the file __openerp__.py
openerp.asterisk_click2dial = function (instance) {
instance.asterisk_click2dial.FieldPhone = instance.web.form.FieldChar.extend({
template: 'FieldPhone',
initialize_content: function() {
this._super();
var $button = this.$el.find('button');
$button.click(this.on_button_clicked);
this.setupFocus($button);
},
render_value: function() {
if (!this.get("effective_readonly")) {
this._super();
} else {
var formatted_number = formatInternational('', this.get('value'))
this.$el.find('a')
.attr('href', 'callto:' + this.get('value'))
.text(formatted_number || '');
}
},
on_button_clicked: function() {
location.href = 'callto:' + this.get('value');
}
});
instance.web.form.widgets.add('phone', 'instance.asterisk_click2dial.FieldPhone');
}

25
asterisk_click2dial/static/src/xml/phone.xml

@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Base phone module for OpenERP
Copyright (C) 2013 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
-->
<templates id="template" xml:space="preserve">
<t t-name="FieldPhone">
<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" target="_blank"/>
<t t-if="!widget.get('effective_readonly')">
<div>
<input type="text"
t-att-id="widget.id_for_label"
t-att-tabindex="widget.node.attrs.tabindex"
t-att-autofocus="widget.node.attrs.autofocus"
t-att-placeholder="widget.node.attrs.placeholder"
t-att-maxlength="widget.field.size"
/>
</div>
</t>
</span>
</t>
</templates>

19
asterisk_click2dial/wizard/reformat_all_phonenumbers_view.xml

@ -12,12 +12,19 @@
<field name="name">reformat_all_phonenumbers.form</field>
<field name="model">reformat.all.phonenumbers</field>
<field name="arch" type="xml">
<form string="Reformat all phone numbers">
<label string="This wizard reformats the phone, mobile and fax numbers of all partners in standard international format e.g. +33141981242" colspan="4"/>
<button special="cancel" icon="gtk-cancel" string="Close" />
<button name="run_reformat_all_phonenumbers" icon="gtk-ok" string="Reformat all phone numbers" type="object" />
<label colspan="4" string="Phone numbers that couldn't be reformatted:"/>
<field name="phonenumbers_not_reformatted" colspan="4" nolabel="1"/>
<form string="Reformat all phone numbers" version="7.0">
<!-- TODO : add a "state" and display fields accordingly -->
<group>
<label string="This wizard reformats the phone, mobile and fax numbers of all partners in standard international format e.g. +33141981242" colspan="4"/>
</group>
<group>
<button name="run_reformat_all_phonenumbers" string="Reformat all phone numbers" type="object" class="oe_highlight"/>
<button special="cancel" string="Cancel" class="oe_link" />
</group>
<group>
<label colspan="4" string="Phone numbers that couldn't be reformatted:"/>
<field name="phonenumbers_not_reformatted" colspan="4" nolabel="1"/>
</group>
</form>
</field>
</record>

1
asterisk_click2dial_crm/__openerp__.py

@ -59,6 +59,7 @@
'wizard/create_crm_phonecall_view.xml',
'res_users_view.xml',
'crm_lead_view.xml',
'crm_phonecall_view.xml',
],
"installable": True,
"application": True,

17
asterisk_click2dial_crm/asterisk_click2dial_crm.py

@ -89,23 +89,6 @@ class crm_lead(osv.osv):
_inherit = ['crm.lead', '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="e164lead", store={
'crm.lead': (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="e164lead", store={
'crm.lead': (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="e164lead", store={
'crm.lead': (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(crm_lead, self).create(cr, uid, vals_reformated, context=context)

16
asterisk_click2dial_crm/crm_lead_view.xml

@ -19,14 +19,14 @@
<field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<group colspan="2" col="8">
<field name="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</xpath>
<xpath expr="//group/group/field[@name='mobile']" position="replace">
<group colspan="2" col="8">
<field name="mobile" colspan="7" />
<button name="action_dial" context="{'field2dial': ['mobile', 'mobile_e164']}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
<field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</xpath>
</field>
@ -40,14 +40,14 @@
<field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<group colspan="2" col="8">
<field name="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</xpath>
<xpath expr="//group/group/field[@name='mobile']" position="replace">
<group colspan="2" col="8">
<field name="mobile" colspan="7" />
<button name="action_dial" context="{'field2dial': ['mobile', 'mobile_e164']}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
<field name="mobile" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</xpath>
</field>

26
asterisk_click2dial_crm/crm_phonecall_view.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial module for OpenERP
Copyright (C) 2013 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
-->
<openerp>
<data>
<record id="asterisk_crm_phonecall_form_view" model="ir.ui.view">
<field name="name">asterisk.crm_phonecall_form_view</field>
<field name="model">crm.phonecall</field>
<field name="inherit_id" ref="crm.crm_case_phone_form_view"/>
<field name="arch" type="xml">
<field name="partner_phone" position="attributes">
<attribute name="widget">phone</attribute>
</field>
<field name="partner_mobile" position="attributes">
<attribute name="widget">phone</attribute>
</field>
</field>
</record>
</data>
</openerp>

2
asterisk_click2dial_crm_claim/crm_claim_view.xml

@ -19,7 +19,7 @@
<field name="partner_phone" position="replace">
<group colspan="2" col="3">
<field name="partner_phone" colspan="2" />
<button name="action_dial" context="{'field2dial': ['partner_phone', 'partner_phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('partner_phone','=',False)]}"/>
<button name="action_dial" context="{'field2dial': 'partner_phone'}" string="Dial" type="object" attrs="{'invisible':[('partner_phone','=',False)]}"/>
</group>
</field>
</field>

14
asterisk_click2dial_registration/asterisk_click2dial_registration.py

@ -27,20 +27,6 @@ class event_registration(osv.osv):
_inherit = ['event.registration', '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')], context=context)
_columns = {
# Note : even if we only have 1 field, we keep multi='..'
# because the generic function generic_phonenumber_to_e164() is designed
# to return the result as multi
'phone_e164': fields.function(format_phonenumber_to_e164, type='char', size=64, string='Phone in E.164 format', readonly=True, multi='e164registration', store={
'event.registration': (lambda self, cr, uid, ids, c={}: ids, ['phone'], 10),
}),
}
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(cr, uid, vals, context=context)
return super(event_registration, self).create(cr, uid, vals_reformated, context=context)

14
asterisk_click2dial_registration/registration_view.xml

@ -18,8 +18,8 @@
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="3">
<field name="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</field>
</field>
@ -31,11 +31,12 @@
<field name="inherit_id" ref="event.view_event_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='registration_ids']/tree/field[@name='phone']" position="replace">
<field name="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" icon="terp-call-start" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" icon="terp-call-start" attrs="{'invisible':[('phone','=',False)]}"/>
</xpath>
</field>
</record>
<record id="asterisk_event_form_registration_form_dial" model="ir.ui.view">
<field name="name">asterisk.event.form.registration.form.dial</field>
<field name="model">event.event</field>
@ -43,11 +44,12 @@
<field name="arch" type="xml">
<xpath expr="//field[@name='registration_ids']/form/group/field[@name='phone']" position="replace">
<group colspan="2" col="3">
<field name="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': ['phone', 'phone_e164']}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
<field name="phone" widget="phone" colspan="2" />
<button name="action_dial" context="{'field2dial': 'phone'}" string="Dial" type="object" attrs="{'invisible':[('phone','=',False)]}"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>
Loading…
Cancel
Save