Browse Source

The "Dial" button is now inside the phone widget : this is great because it avoids the double inherit of views with phone fields (4 view XML files are removed in asterisk_click2dial* modules thanks to this !)

The "Open Calling Partner" feature is now located in the top right menu, next to the Preferences (instead of the Sales menu)
A click on tel: and fax: links doesn't open a new tab any more
Update description and copyrights of asterisk_click2dial_crm
pull/7/head
Alexis de Lattre 10 years ago
parent
commit
8f3040d085
  1. 4
      asterisk_click2dial/__openerp__.py
  2. 101
      asterisk_click2dial/asterisk_click2dial.py
  3. 70
      asterisk_click2dial/res_partner_view.xml
  4. 27
      asterisk_click2dial/static/src/css/asterisk_click2dial.css
  5. 44
      asterisk_click2dial/static/src/js/asterisk_click2dial.js
  6. 26
      asterisk_click2dial/static/src/xml/asterisk_click2dial.xml
  7. 10
      asterisk_click2dial/wizard/open_calling_partner_view.xml
  8. 4
      asterisk_click2dial_crm/__init__.py
  9. 9
      asterisk_click2dial_crm/__openerp__.py
  10. 46
      asterisk_click2dial_crm/asterisk_click2dial_crm.py
  11. 57
      asterisk_click2dial_crm/crm_lead_view.xml
  12. 26
      asterisk_click2dial_crm/crm_phonecall_view.xml
  13. 2
      asterisk_click2dial_crm/wizard/create_crm_phonecall.py
  14. 9
      asterisk_click2dial_crm/wizard/open_calling_partner_view.xml
  15. 1
      asterisk_click2dial_crm_claim/__openerp__.py
  16. 29
      asterisk_click2dial_crm_claim/crm_claim_view.xml
  17. 2
      asterisk_click2dial_event/__openerp__.py
  18. 47
      asterisk_click2dial_event/registration_view.xml
  19. 1
      base_phone/__init__.py
  20. 2
      base_phone/__openerp__.py
  21. 5
      base_phone/base_phone.py
  22. 35
      base_phone/controller.py
  23. 63
      base_phone/static/src/js/phone_widget.js
  24. 13
      base_phone/static/src/xml/phone.xml

4
asterisk_click2dial/__openerp__.py

@ -57,7 +57,6 @@ A detailed documentation for this module is available on the Akretion Web site :
'data': [
'asterisk_server_view.xml',
'res_users_view.xml',
'res_partner_view.xml',
'wizard/open_calling_partner_view.xml',
'security/ir.model.access.csv',
],
@ -66,6 +65,9 @@ A detailed documentation for this module is available on the Akretion Web site :
'images/sshot-click2dial.jpg',
'images/sshot-open_calling_party.jpg',
],
'qweb': ['static/src/xml/*.xml'],
'js': ['static/src/js/*.js'],
'css': ['static/src/css/*.css'],
'application': True,
'installable': True,
'active': False,

101
asterisk_click2dial/asterisk_click2dial.py

@ -258,49 +258,6 @@ class asterisk_server(orm.Model):
_("OpenERP can successfully login to the Asterisk Manager "
"Interface."))
def _dial_with_asterisk(self, cr, uid, erp_number, context=None):
#print "_dial_with_asterisk erp_number=", erp_number
if not erp_number:
raise orm.except_orm(_('Error :'), "Hara kiri : you must call the function with erp_number")
user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context)
ast_number = self._reformat_number(cr, uid, erp_number, ast_server, context=context)
# The user should have a CallerID
if not user.callerid:
raise orm.except_orm(_('Error :'), _('No callerID configured for the current user'))
variable = []
if user.asterisk_chan_type == 'SIP':
# We can only have one alert-info header in a SIP request
if user.alert_info:
variable.append('SIPAddHeader=Alert-Info: ' + user.alert_info)
elif ast_server.alert_info:
variable.append('SIPAddHeader=Alert-Info: ' + ast_server.alert_info)
if user.variable:
for user_variable in user.variable.split('|'):
variable.append(user_variable.strip())
try:
ast_manager.Originate(
user.asterisk_chan_type + '/' + user.resource + ( ('/' + user.dial_suffix) if user.dial_suffix else ''),
context = ast_server.context,
extension = ast_number,
priority = str(ast_server.extension_priority),
timeout = str(ast_server.wait_time*1000),
caller_id = user.callerid,
account = user.cdraccount,
variable = variable)
except Exception, e:
_logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : '%s'" % unicode(e))
raise orm.except_orm(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e)))
finally:
ast_manager.Logoff()
return True
def _get_calling_number(self, cr, uid, context=None):
user, ast_server, ast_manager = self._connect_to_asterisk(cr, uid, context=context)
@ -397,20 +354,50 @@ class res_users(orm.Model):
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def action_dial(self, cr, uid, ids, context=None):
'''Read the number to dial and call _connect_to_asterisk the right way'''
if context is None:
context = {}
if not isinstance(context.get('field2dial'), (unicode, str)):
raise orm.except_orm(_('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]
# Check if the number to dial is not empty
if not erp_number_e164:
raise orm.except_orm(_('Error :'), _('There is no phone number !'))
return self.pool['asterisk.server']._dial_with_asterisk(cr, uid, erp_number_e164, context=context)
def click2dial(self, cr, uid, erp_number, context=None):
if not erp_number:
orm.except_orm(
_('Error:'),
_('Missing phone number'))
user, ast_server, ast_manager = self.pool['asterisk.server']._connect_to_asterisk(cr, uid, context=context)
ast_number = self.pool['asterisk.server']._reformat_number(
cr, uid, erp_number, ast_server, context=context)
# The user should have a CallerID
if not user.callerid:
raise orm.except_orm(_('Error :'), _('No callerID configured for the current user'))
variable = []
if user.asterisk_chan_type == 'SIP':
# We can only have one alert-info header in a SIP request
if user.alert_info:
variable.append('SIPAddHeader=Alert-Info: ' + user.alert_info)
elif ast_server.alert_info:
variable.append('SIPAddHeader=Alert-Info: ' + ast_server.alert_info)
if user.variable:
for user_variable in user.variable.split('|'):
variable.append(user_variable.strip())
try:
ast_manager.Originate(
user.asterisk_chan_type + '/' + user.resource + ( ('/' + user.dial_suffix) if user.dial_suffix else ''),
context = ast_server.context,
extension = ast_number,
priority = str(ast_server.extension_priority),
timeout = str(ast_server.wait_time*1000),
caller_id = user.callerid,
account = user.cdraccount,
variable = variable)
except Exception, e:
_logger.error("Error in the Originate request to Asterisk server %s" % ast_server.ip_address)
_logger.error("Here is the detail of the error : '%s'" % unicode(e))
raise orm.except_orm(_('Error :'), _("Click to dial with Asterisk failed.\nHere is the error: '%s'" % unicode(e)))
finally:
ast_manager.Logoff()
return True
def _prepare_incall_pop_action(
self, cr, uid, record_res, number, context=None):

70
asterisk_click2dial/res_partner_view.xml

@ -1,70 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial module for Odoo/OpenERP
Copyright (C) 2010-2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
Inherit partner views to add 'Dial' button next to 'phone'
and 'mobile' fields
-->
<openerp>
<data>
<record id="asterisk_res_partner_simplified_form_dial" model="ir.ui.view">
<field name="name">asterisk.res.partner.simplified.form.dial</field>
<field name="model">res.partner</field>
<field name="priority">15</field>
<field name="inherit_id" ref="base_phone.view_partner_simple_form"/>
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="8">
<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" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</field>
</field>
</record>
<record id="asterisk_res_partner_form_dial" model="ir.ui.view">
<field name="name">asterisk.res.partner.form.dial</field>
<field name="model">res.partner</field>
<field name="priority">15</field>
<field name="inherit_id" ref="base_phone.view_partner_form"/>
<field name="arch" type="xml">
<xpath expr="//group/group/field[@name='phone']" position="replace">
<group colspan="2" col="8">
<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" 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" 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" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</xpath>
</field>
</record>
</data>
</openerp>

27
asterisk_click2dial/static/src/css/asterisk_click2dial.css

@ -0,0 +1,27 @@
/*
Asterisk Click2dial module for OpenERP
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
*/
.openerp .oe_topbar_item.oe_topbar_open_calling_partner{
padding: 0px;
width: 32px;
height: 32px;
}
.openerp .oe_topbar_item.oe_topbar_open_calling_partner button{
position: relative;
top: -3px;
box-sizing: border-box;
border: none;
box-shadow: none;
color: white;
background: none;
text-shadow: 0px 1px 2px black;
width: 32px;
height: 32px;
padding: 0px;
margin: 0px
border-radius: 0px;
}

44
asterisk_click2dial/static/src/js/asterisk_click2dial.js

@ -0,0 +1,44 @@
/* Asterisk_click2dial module for OpenERP
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py */
openerp.asterisk_click2dial = function (instance) {
var _t = instance.web._t;
instance.web.OpenCallingPartner = instance.web.Widget.extend({
template:'asterisk_click2dial.OpenCallingPartner',
start: function () {
this.$('button').on('click', this.on_open_calling_partner);
this._super();
},
on_open_calling_partner: function (event) {
event.stopPropagation();
var action = {
name: _t('Open Calling Partner'),
type: 'ir.actions.act_window',
res_model: 'wizard.open.calling.partner',
view_mode: 'form',
views: [[false, 'form']],
target: 'new',
context: {},
};
instance.client.action_manager.do_action(action);
},
});
instance.web.UserMenu.include({
do_update: function(){
this._super.apply(this, arguments);
this.update_promise.then(function() {
var asterisk_button = new instance.web.OpenCallingPartner();
asterisk_button.appendTo(instance.webclient.$el.find('.oe_systray'));
});
},
});
};

26
asterisk_click2dial/static/src/xml/asterisk_click2dial.xml

@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Asterisk Click2dial module for OpenERP
Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
-->
<template>
<!-- Add phone button in top right menu for "Open Calling Partner" -->
<t t-name="asterisk_click2dial.OpenCallingPartner">
<div title="Open Calling Partner"
class="oe_topbar_item oe_topbar_open_calling_partner">
<button class="oe_i">A</button>
<!-- oe_i is a special icon font : 'A' represents a phone -->
</div>
</t>
<!-- Add Dial button in phone widget for click2dial feature -->
<t t-extend="FieldPhone">
<t t-jquery="a.oe_form_uri" t-operation="after">
<a id="click2dial" href="#" class="oe_bold"/>
</t>
</t>
</template>

10
asterisk_click2dial/wizard/open_calling_partner_view.xml

@ -47,15 +47,5 @@
</record>
<record id="action_open_calling_partner" model="ir.actions.act_window">
<field name="name">Open calling partner</field>
<field name="res_model">wizard.open.calling.partner</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="target">new</field>
</record>
<menuitem id="menu_open_calling_partner_sales" parent="base.menu_sales" action="action_open_calling_partner" sequence="50" />
</data>
</openerp>

4
asterisk_click2dial_crm/__init__.py

@ -2,9 +2,7 @@
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
# Copyright (c) 2012-2013 Akretion (http://www.akretion.com)
# @author: Jesús Martín <jmartin@zikzakmedia.com>
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify

9
asterisk_click2dial_crm/__openerp__.py

@ -2,9 +2,7 @@
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# @author: Jesús Martín <jmartin@zikzakmedia.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
@ -25,8 +23,8 @@
{
"name": "Asterisk Click2dial CRM",
"version": "0.1",
"author": "Zikzakmedia SL, Akretion",
"website": "http://www.zikzakmedia.com",
"author": "Akretion",
"website": "http://www.akretion.com",
"license": "AGPL-3",
"category": "Phone",
"description": """
@ -41,7 +39,7 @@ First, when you do a click2dial, OpenERP will propose you to create an outbound
Second, when you receive a phone call and run the wizard "Open calling partner", if the partner is found in OpenERP, you will see a button that proposes to create an inbound phone call in the CRM.
This module has been initially developped by Zikzakmedia and has been enhanced by Akretion.
This module has been initially developped by Zikzakmedia and has been completely re-written by Akretion.
A detailed documentation for the OpenERP-Asterisk connector is available on the Akretion Web site : http://www.akretion.com/en/products-and-services/openerp-asterisk-voip-connector
""",
@ -54,7 +52,6 @@ A detailed documentation for the OpenERP-Asterisk connector is available on the
'wizard/open_calling_partner_view.xml',
'wizard/create_crm_phonecall_view.xml',
'res_users_view.xml',
'crm_lead_view.xml',
],
"installable": True,
"application": True,

46
asterisk_click2dial_crm/asterisk_click2dial_crm.py

@ -2,10 +2,7 @@
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# Copyright (C) 2013 Invitu <contact@invitu.com>
# @author: Jesús Martín <jmartin@zikzakmedia.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify
@ -24,37 +21,32 @@
##############################################################################
from openerp.osv import orm, fields
from openerp.tools.translate import _
class res_partner(orm.Model):
_name = 'res.partner'
_inherit = ['res.partner', 'phone.common']
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def action_dial(self, cr, uid, ids, context=None):
def click2dial(self, cr, uid, erp_number, context=None):
'''
This method open the phone call history when the phone click2dial
button of asterisk_click2dial module is pressed
:return the phone call history view of the partner
Inherit the native click2dial function to trigger
a wizard "Create Call in CRM" via the Javascript code
of base_phone
'''
if context is None:
context = {}
super(res_partner, self).action_dial(cr, uid, ids, context=context)
res = super(phone_common, self).click2dial(
cr, uid, erp_number, context=context)
user = self.pool['res.users'].browse(cr, uid, uid, context=context)
context['partner_id'] = ids[0]
action_start_wizard = {
'name': 'Create phone call in CRM',
'type': 'ir.actions.act_window',
'res_model': 'wizard.create.crm.phonecall',
'view_type': 'form',
'view_mode': 'form',
'nodestroy': True,
'target': 'new',
'context': context,
}
if user.context_propose_creation_crm_call:
return action_start_wizard
if (
context.get('click2dial_model') == 'res.partner'
and user.context_propose_creation_crm_call):
return {
'name': _('Create Call in CRM'),
'res_model': 'wizard.create.crm.phonecall',
}
else:
return True
return res
class res_users(orm.Model):
@ -62,8 +54,8 @@ class res_users(orm.Model):
_columns = {
# Field name starts with 'context_' to allow modification by the user
# in his preferences, cf server-61/openerp/addons/base/res/res_users.py
# line 377 in "def write" of "class users"
# in his preferences, cf server/openerp/addons/base/res/res_users.py
# in "def write()" of "class res_users(osv.osv)"
'context_propose_creation_crm_call': fields.boolean(
'Propose to create a call in CRM after a click2dial'),
}

57
asterisk_click2dial_crm/crm_lead_view.xml

@ -1,57 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial module for OpenERP
Copyright (C) 2010-2013 Alexis de Lattre <alexis@via.ecp.fr>
Copyright (C) 2010-2013 Invitu <contact@invitu.com>
The licence is in the file __openerp__.py
Inherit lead views to add 'Dial' button next to 'phone'
and 'mobile' fields
-->
<openerp>
<data>
<record id="asterisk_crm_lead_simplified_form_dial" model="ir.ui.view">
<field name="name">asterisk.crm_lead.form.dial</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_leads"/>
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="8">
<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" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</field>
</field>
</record>
<record id="asterisk_crm_case_form_view_oppor_dial" model="ir.ui.view">
<field name="name">asterisk.crm_case.form.view_oppor.dial</field>
<field name="model">crm.lead</field>
<field name="inherit_id" ref="crm.crm_case_form_view_oppor"/>
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="8">
<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" widget="phone" colspan="7" />
<button name="action_dial" context="{'field2dial': 'mobile'}" string="Dial" type="object" attrs="{'invisible':[('mobile','=',False)]}"/>
</group>
</field>
</field>
</record>
</data>
</openerp>

26
asterisk_click2dial_crm/crm_phonecall_view.xml

@ -1,26 +0,0 @@
<?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/wizard/create_crm_phonecall.py

@ -2,9 +2,7 @@
##############################################################################
#
# Asterisk click2dial CRM module for OpenERP
# Copyright (c) 2011 Zikzakmedia S.L. (http://zikzakmedia.com)
# Copyright (c) 2012-2014 Akretion (http://www.akretion.com)
# @author: Jesús Martín <jmartin@zikzakmedia.com>
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
#
# This program is free software: you can redistribute it and/or modify

9
asterisk_click2dial_crm/wizard/open_calling_partner_view.xml

@ -20,14 +20,5 @@
</field>
</record>
<!-- Move "Open calling partner" menu entry to "Phone calls" menu -->
<delete model="ir.ui.menu" id="asterisk_click2dial.menu_open_calling_partner_sales" />
<menuitem id="menu_open_calling_partner_phone"
parent="crm.menu_crm_case_phone"
action="asterisk_click2dial.action_open_calling_partner"
sequence="1" />
</data>
</openerp>

1
asterisk_click2dial_crm_claim/__openerp__.py

@ -40,7 +40,6 @@
"demo": [],
"data": [
'wizard/open_calling_partner_view.xml',
'crm_claim_view.xml',
],
"installable": True,
"application": True,

29
asterisk_click2dial_crm_claim/crm_claim_view.xml

@ -1,29 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial CRM Claim module for OpenERP
Copyright (C) 2013 Invitu <contact@invitu.com>
The licence is in the file __openerp__.py
Inherit crm_claim view to add 'Dial' button next to 'phone'
field
-->
<openerp>
<data>
<record id="asterisk_crm_claim_form_dial" model="ir.ui.view">
<field name="name">asterisk.crm_claim.form.dial</field>
<field name="model">crm.claim</field>
<field name="inherit_id" ref="crm_claim_phone.crm_case_claims_form_view"/>
<field name="arch" type="xml">
<field name="partner_phone" position="replace">
<group colspan="2" col="3">
<field name="partner_phone" colspan="2" widget="phone"/>
<button name="action_dial" context="{'field2dial': 'partner_phone'}" string="Dial" type="object" attrs="{'invisible':[('partner_phone','=',False)]}"/>
</group>
</field>
</field>
</record>
</data>
</openerp>

2
asterisk_click2dial_event/__openerp__.py

@ -35,10 +35,8 @@
'asterisk_click2dial',
'event_phone',
],
"demo": [],
"data": [
'wizard/open_calling_partner_view.xml',
'registration_view.xml',
],
"installable": True,
"application": True,

47
asterisk_click2dial_event/registration_view.xml

@ -1,47 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Asterisk Click2dial CRM Claim module for OpenERP
Copyright (C) 2013 Invitu <contact@invitu.com>
The licence is in the file __openerp__.py
Inherit event registration view to add 'Dial' button next to 'phone'
field
-->
<openerp>
<data>
<record id="view_event_registration_form" model="ir.ui.view">
<field name="name">asterisk.event.registration.form.dial</field>
<field name="model">event.registration</field>
<field name="inherit_id" ref="event_phone.view_event_registration_form"/>
<field name="arch" type="xml">
<field name="phone" position="replace">
<group colspan="2" col="3">
<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>
</record>
<record id="view_event_form" model="ir.ui.view">
<field name="name">asterisk.event.form.registration.tree.dial</field>
<field name="model">event.event</field>
<field name="inherit_id" ref="event_phone.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'}" string="Dial" type="object" icon="terp-call-start" attrs="{'invisible':[('phone','=',False)]}"/>
</xpath>
<xpath expr="//field[@name='registration_ids']/form//field[@name='phone']" position="replace">
<group colspan="2" col="3">
<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>

1
base_phone/__init__.py

@ -22,3 +22,4 @@
from . import base_phone
from . import wizard
from . import report_sxw_format
from . import controller

2
base_phone/__openerp__.py

@ -50,7 +50,7 @@ Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com> for
""",
'author': 'Akretion',
'website': 'http://www.akretion.com/',
'depends': ['base'],
'depends': ['base', 'web'],
'external_dependencies': {'python': ['phonenumbers']},
'data': [
'security/phone_security.xml',

5
base_phone/base_phone.py

@ -200,6 +200,11 @@ class phone_common(orm.AbstractModel):
}
return res
def click2dial(self, cr, uid, erp_number, context=None):
'''This function is designed to be overridden in IPBX-specific
modules, such as asterisk_click2dial'''
return True
class res_partner(orm.Model):
_name = 'res.partner'

35
base_phone/controller.py

@ -0,0 +1,35 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial module for OpenERP
# Copyright (C) 2014 Alexis de Lattre (alexis@via.ecp.fr)
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Affero General Public License for more details.
#
# You should have received a copy of the GNU Affero General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import openerp
class BasePhoneController(openerp.addons.web.http.Controller):
_cp_path = '/base_phone'
@openerp.addons.web.http.jsonrequest
def click2dial(self, req, phone_number, click2dial_model, click2dial_id):
res = req.session.model('phone.common').click2dial(
phone_number, {
'click2dial_model': click2dial_model,
'click2dial_id': click2dial_id,
})
return res

63
base_phone/static/src/js/phone_widget.js

@ -1,9 +1,10 @@
// Base phone module for OpenERP
// Copyright (C) 2013-2014 Alexis de Lattre <alexis@via.ecp.fr>
// The licence is in the file __openerp__.py
/* Base phone module for OpenERP
Copyright (C) 2013-2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py */
openerp.base_phone = function (instance) {
var _t = instance.web._t;
instance.base_phone.FieldPhone = instance.web.form.FieldChar.extend({
template: 'FieldPhone',
@ -14,13 +15,49 @@ openerp.base_phone = function (instance) {
this.setupFocus($button);
},
render_value: function() {
if (!this.get("effective_readonly")) {
if (!this.get('effective_readonly')) {
this._super();
} else {
var formatted_number = formatInternational('', this.get('value'));
this.$el.find('a')
.attr('href', 'tel:' + this.get('value'))
.text(formatted_number || '');
var self = this;
var phone_num = this.get('value');
this.$el.find('a.oe_form_uri')
.attr('href', 'tel:' + phone_num)
.text(phone_num && formatInternational('', phone_num) || '');
this.$el.find('#click2dial')
.text(phone_num && 'Dial' || '')
.on('click', function(ev) {
self.do_notify(
_t('Click2dial started'),
_t('Unhook your ringing phone'));
var arg = {
'phone_number': phone_num,
'click2dial_model': self.view.dataset.model,
'click2dial_id': self.view.datarecord.id};
self.rpc('/base_phone/click2dial', arg).done(function(r) {
if (r === false) {
self.do_warn("Click2dial failed");
} else {
self.do_notify(_t('Click2dial successfull'), '');
if (typeof r === 'object') {
var context = {};
if (self.view.dataset.model == 'res.partner') {
context = {
'partner_id': self.view.datarecord.id};
}
var action = {
name: r.name,
type: 'ir.actions.act_window',
res_model: r.res_model,
view_mode: 'form',
views: [[false, 'form']],
target: 'new',
context: context,
};
instance.client.action_manager.do_action(action);
}
}
});
});
}
},
on_button_clicked: function() {
@ -39,13 +76,13 @@ openerp.base_phone = function (instance) {
this.setupFocus($button);
},
render_value: function() {
if (!this.get("effective_readonly")) {
if (!this.get('effective_readonly')) {
this._super();
} else {
var formatted_number = formatInternational('', this.get('value'));
this.$el.find('a')
.attr('href', 'fax:' + this.get('value'))
.text(formatted_number || '');
var fax_num = this.get('value');
this.$el.find('a.oe_form_uri')
.attr('href', 'fax:' + fax_num)
.text(fax_num && formatInternational('', fax_num) || '');
}
},
on_button_clicked: function() {

13
base_phone/static/src/xml/phone.xml

@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Base phone module for OpenERP
Copyright (C) 2013 Alexis de Lattre <alexis@via.ecp.fr>
Copyright (C) 2013-2014 Alexis de Lattre <alexis@via.ecp.fr>
The licence is in the file __openerp__.py
-->
@ -9,7 +9,14 @@
<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')">
<a href="#" class="oe_form_uri"/>
<!--
You should add the following "<a .. />" in your IPBX-specific
module (such as asterisk_click2dial) via <t t-extend="FieldPhone">
<a id="click2dial" href="#" class="oe_bold"/>
-->
</t>
<t t-if="!widget.get('effective_readonly')">
<div>
<input type="text"
@ -26,7 +33,7 @@
<t t-name="FieldFax">
<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"/>
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri"/>
<t t-if="!widget.get('effective_readonly')">
<div>
<input type="text"

Loading…
Cancel
Save