Browse Source

More PEP8 related cleanups.

pull/96/head
Trever L. Adams 8 years ago
parent
commit
a09a0d2476
  1. 144
      asterisk_click2dial/README.rst
  2. 67
      asterisk_click2dial/__openerp__.py
  3. 10
      asterisk_click2dial/asterisk_click2dial.py
  4. 1
      asterisk_click2dial/scripts/set_name_agi.py
  5. 20
      asterisk_click2dial/static/src/js/asterisk_click2dial.js
  6. 8
      base_phone/fields.py
  7. 10
      base_phone/models/phone_common.py
  8. 2
      base_phone/models/res_partner.py
  9. 10
      base_phone/static/src/js/phone_widget.js
  10. 6
      base_phone/wizard/number_not_found.py
  11. 86
      base_phone_popup/README.rst
  12. 26
      base_phone_popup/__openerp__.py
  13. 70
      crm_phone/README.rst
  14. 14
      crm_phone/__openerp__.py
  15. 8
      crm_phone/crm_phone.py
  16. 5
      crm_phone/wizard/create_crm_phonecall.py
  17. 8
      freeswitch_click2dial/README.rst
  18. 2
      freeswitch_click2dial/__openerp__.py
  19. 4
      freeswitch_click2dial/controller.py
  20. 21
      freeswitch_click2dial/freeswitch_click2dial.py
  21. 16
      freeswitch_click2dial/scripts/get_caller_name.py
  22. 20
      freeswitch_click2dial/static/src/js/freeswitch_click2dial.js

144
asterisk_click2dial/README.rst

@ -0,0 +1,144 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=======================
Asterisk-Odoo connector
=======================
The technical name of this module is *asterisk_click2dial*, but this module
implements much more than a simple *click2dial*! This module adds 3
functionalities:
1) It adds a *Dial* button in the partner form view so that users can directly
dial a phone number through Asterisk. This feature is usually known as
*click2dial*.
2) It adds the ability to show the name of the calling party on the screen of
your IP phone on incoming phone calls if the presented phone number is
present in the partner/leads/employees/... of Odoo.
3) It adds a phone icon (*Open Caller*) in the top menu bar
(next to the Preferences) to get the partner/lead/candidate/registrations
corresponding to the calling party in one click.
Installation
============
To install this module, you need to:
* Click on the module and install it
Configuration
=============
To configure this module, you need to:
* Settings > Technical > Asterisk Servers.
* Setup you server.
* Configure users under Settings > Users > $USER > Telephony tab.
Usage
=====
To use this module, you need to:
* See scripts/* (as mentioned below in section 2 of Usage) to see how to set
caller and callee name.
* Click on Dial next to any phone number covered by associated modules.
1) *click2dial*. Here is how it works :
* In Odoo, the user clicks on the *Dial* button next to a phone number
field in the partner view.
* Odoo connects to the Asterisk Manager Interface and Asterisk makes the
user's phone ring.
* The user answers his own phone (if he doesn't, the process stops here).
* Asterisk dials the phone number found in Odoo in place of the user.
* If the remote party answers, the user can talk to his correspondent.
2) Using Odoo to provide Caller ID Name in Asterisk. To understand how to
use this, please see the scripts mentioned below, which should be installed
per the instructions in the script on the Odoo/Odoo server. This works for
incoming and outgoing calls, per instructions in the script.
* On incoming phone calls, the Asterisk dialplan executes an AGI script
"set_name_incoming_timeout.sh".
* The "set_name_incoming_timeout.sh" script calls the "set_name_agi.py"
script with a short timeout.
* The "set_name_agi.py" script will make an XML-RPC request on the Odoo
server to try to find the name of the person corresponding to the phone
number presented by the calling party.
* If it finds the name, it is set as the CallerID name of the call, so as
to be presented on the IP phone of the user.
It also works on outgoing calls, so as to display the name of the callee on
the SIP phone of the caller. For that, you should use the script
"set_name_outgoing_timeout.sh".
3) *Open Caller* Here is how it works :
* When the user clicks on the phone icon, Odoo sends a query to the
Asterisk Manager Interface to get a list of the current phone calls.
* If it finds a phone call involving the user's phone, it gets the phone
number of the calling party.
* It searches the phone number of the calling party in the
Partners/Leads/Candidates/Registrations of Odoo. If a record matches,
it takes you to the form view of this record. If no record matchs, it
opens a wizard which proposes to create a new Partner with the presented
phone number as *Phone* or *Mobile* number or update an existing Partner.
It is possible to get a pop-up of the record corresponding to the calling
party without any action from the user via the module *base_phone_popup*.
A detailed documentation for this module is available on the Akretion Web site:
http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector
Known issues / Roadmap
======================
* None
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/connector-telephony/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Akretion
* Odoo Community Association (OCA)
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

67
asterisk_click2dial/__openerp__.py

@ -8,73 +8,6 @@
'category': 'Phone', 'category': 'Phone',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Asterisk-Odoo connector', 'summary': 'Asterisk-Odoo connector',
'description': """
Asterisk-Odoo connector
==========================
The technical name of this module is *asterisk_click2dial*, but this module
implements much more than a simple *click2dial* ! This module adds 3
functionalities:
1) It adds a *Dial* button in the partner form view so that users can directly
dial a phone number through Asterisk. This feature is usually known as
*click2dial*. Here is how it works :
* In Odoo, the user clicks on the *Dial* button next to a phone number
field in the partner view.
* Odoo connects to the Asterisk Manager Interface and Asterisk makes the
user's phone ring.
* The user answers his own phone (if he doesn't, the process stops here).
* Asterisk dials the phone number found in Odoo in place of the user.
* If the remote party answers, the user can talk to his correspondent.
2) It adds the ability to show the name of the calling party on the screen of
your IP phone on incoming phone calls if the presented phone number is
present in the partner/leads/employees/... of Odoo. Here is how it works:
* On incoming phone calls, the Asterisk dialplan executes an AGI script
"set_name_incoming_timeout.sh".
* The "set_name_incoming_timeout.sh" script calls the "set_name_agi.py"
script with a short timeout.
* The "set_name_agi.py" script will make an XML-RPC request on the Odoo
server to try to find the name of the person corresponding to the phone
number presented by the calling party.
* If it finds the name, it is set as the CallerID name of the call, so as
to be presented on the IP phone of the user.
It also works on outgoing calls, so as to display the name of the callee on
the SIP phone of the caller. For that, you should use the script
"set_name_outgoing_timeout.sh".
3) It adds a phone icon (*Open Caller*) in the top menu bar
(next to the Preferences) to get the partner/lead/candidate/registrations
corresponding to the calling party in one click. Here is how it works :
* When the user clicks on the phone icon, Odoo sends a query to the
Asterisk Manager Interface to get a list of the current phone calls
* If it finds a phone call involving the user's phone, it gets the phone
number of the calling party
* It searches the phone number of the calling party in the
Partners/Leads/Candidates/Registrations of Odoo. If a record matches,
it takes you to the form view of this record. If no record matchs, it
opens a wizard which proposes to create a new Partner with the presented
phone number as *Phone* or *Mobile* number or update an existing Partner.
It is possible to get a pop-up of the record corresponding to the calling
party without any action from the user via the module *base_phone_popup*.
A detailed documentation for this module is available on the Akretion Web site:
http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector
""",
'author': "Akretion,Odoo Community Association (OCA)", 'author': "Akretion,Odoo Community Association (OCA)",
'website': 'http://www.akretion.com/', 'website': 'http://www.akretion.com/',
'depends': ['base_phone'], 'depends': ['base_phone'],

10
asterisk_click2dial/asterisk_click2dial.py

@ -76,11 +76,11 @@ class AsteriskServer(models.Model):
'context', 'alert_info', 'login', 'password') 'context', 'alert_info', 'login', 'password')
def _check_validity(self): def _check_validity(self):
for server in self: for server in self:
out_prefix = ('Out prefix', server.out_prefix)
dialplan_context = ('Dialplan context', server.context)
alert_info = ('Alert-Info SIP header', server.alert_info)
login = ('AMI login', server.login)
password = ('AMI password', server.password)
out_prefix = (_('Out prefix'), server.out_prefix)
dialplan_context = (_('Dialplan context'), server.context)
alert_info = (_('Alert-Info SIP header'), server.alert_info)
login = (_('AMI login'), server.login)
password = (_('AMI password'), server.password)
if out_prefix[1] and not out_prefix[1].isdigit(): if out_prefix[1] and not out_prefix[1].isdigit():
raise ValidationError( raise ValidationError(

1
asterisk_click2dial/scripts/set_name_agi.py

@ -387,6 +387,7 @@ def main(options, arguments):
stdout_write('SET CALLERID "%s"<%s>\n' % (res, phone_number)) stdout_write('SET CALLERID "%s"<%s>\n' % (res, phone_number))
return True return True
if __name__ == '__main__': if __name__ == '__main__':
usage = "Usage: get_name_agi.py [options] login1 login2 login3 ..." usage = "Usage: get_name_agi.py [options] login1 login2 login3 ..."
epilog = "Script written by Alexis de Lattre. " epilog = "Script written by Alexis de Lattre. "

20
asterisk_click2dial/static/src/js/asterisk_click2dial.js

@ -35,14 +35,12 @@ click2dial.OpenCaller = Widget.extend({
_t('Failure'), _t('Failure'),
_t('Problem in the connection to Asterisk'), _t('Problem in the connection to Asterisk'),
false); false);
}
else if (typeof r == 'string' && isNaN(r)) {
} else if (typeof r == 'string' && isNaN(r)) {
self.do_warn( self.do_warn(
r, r,
_t('The calling number is not a phone number!'), _t('The calling number is not a phone number!'),
false); false);
}
else if (typeof r == 'string') {
} else if (typeof r == 'string') {
var action = { var action = {
name: _t('Number Not Found'), name: _t('Number Not Found'),
type: 'ir.actions.act_window', type: 'ir.actions.act_window',
@ -50,13 +48,13 @@ click2dial.OpenCaller = Widget.extend({
view_mode: 'form', view_mode: 'form',
views: [[false, 'form']], views: [[false, 'form']],
target: 'new', target: 'new',
context: {'default_calling_number': r},
context: {'default_calling_number': r}
}; };
web_client.action_manager.do_action(action); web_client.action_manager.do_action(action);
}
else if (typeof r == 'object' && r.length == 3) {
self.do_notify( // Not working
} else if (typeof r == 'object' && r.length == 3) {
// self.do_notify Not working
self.do_notify(
_t('Success'), _t('Success'),
_t('Moving to %s ID %d', r[0], r[1]), _t('Moving to %s ID %d', r[0], r[1]),
false); false);
@ -74,12 +72,12 @@ click2dial.OpenCaller = Widget.extend({
If you want to use target: 'current', with web/enterprise, If you want to use target: 'current', with web/enterprise,
you have to reload the Web page just after */ you have to reload the Web page just after */
target: 'current', target: 'current',
context: {},
context: {}
}; };
web_client.action_manager.do_action(action); web_client.action_manager.do_action(action);
} }
}); });
},
}
}); });
UserMenu.include({ UserMenu.include({
@ -90,7 +88,7 @@ click2dial.OpenCaller = Widget.extend({
// attach the phone logo/button to the systray // attach the phone logo/button to the systray
asterisk_button.appendTo($('.oe_systray')); asterisk_button.appendTo($('.oe_systray'));
}); });
},
}
}); });
}); });

8
base_phone/fields.py

@ -7,11 +7,15 @@
from openerp import api, fields, models from openerp import api, fields, models
from operator import attrgetter from operator import attrgetter
import phonenumbers
import logging import logging
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try:
import phonenumbers
except (ImportError, IOError) as err:
_logger.debug(err)
class Phone(fields.Char): class Phone(fields.Char):
@ -108,6 +112,7 @@ def get_phone_fields(self, vals):
fields_to_convert.append(key) fields_to_convert.append(key)
return fields_to_convert return fields_to_convert
original_write = models.BaseModel.write original_write = models.BaseModel.write
original_create = models.BaseModel.create original_create = models.BaseModel.create
@ -133,5 +138,6 @@ def create(self, vals):
vals = convert_all_phone_fields(self, vals, fields_to_convert) vals = convert_all_phone_fields(self, vals, fields_to_convert)
return original_create(self, vals) return original_create(self, vals)
models.BaseModel.write = write models.BaseModel.write = write
models.BaseModel.create = create models.BaseModel.create = create

10
base_phone/models/phone_common.py

@ -3,13 +3,17 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, api from openerp import models, api
from openerp.addons.base_phone.fields import Phone
from ..fields import Phone
import logging import logging
# Lib for phone number reformating -> pip install phonenumbers
import phonenumbers
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
# Lib for phone number reformating -> pip install phonenumbers
try:
import phonenumbers
except (ImportError, IOError) as err:
_logger.debug(err)
class PhoneCommon(models.AbstractModel): class PhoneCommon(models.AbstractModel):
_name = 'phone.common' _name = 'phone.common'

2
base_phone/models/res_partner.py

@ -4,7 +4,7 @@
from openerp import models, api from openerp import models, api
from openerp.addons.base_phone import fields
from .. import fields
class ResPartner(models.Model): class ResPartner(models.Model):

10
base_phone/static/src/js/phone_widget.js

@ -31,8 +31,7 @@ var FieldPhone = formwidgets.FieldChar.extend({
raw_phone_num = phone_num.replace(/ /g, ''); raw_phone_num = phone_num.replace(/ /g, '');
raw_phone_num = raw_phone_num.replace(/-/g, ''); raw_phone_num = raw_phone_num.replace(/-/g, '');
this.$el.find('a.oe_form_uri').attr('href', 'tel:' + raw_phone_num).text(phone_num); this.$el.find('a.oe_form_uri').attr('href', 'tel:' + raw_phone_num).text(phone_num);
}
else {
} else {
this.$el.find('a.oe_form_uri').attr('href', '').text(''); this.$el.find('a.oe_form_uri').attr('href', '').text('');
} }
var click2dial_text = ''; var click2dial_text = '';
@ -64,7 +63,7 @@ var FieldPhone = formwidgets.FieldChar.extend({
var context = { var context = {
'click2dial_model': self.view.dataset.model, 'click2dial_model': self.view.dataset.model,
'click2dial_id': self.view.datarecord.id, 'click2dial_id': self.view.datarecord.id,
'phone_number': raw_phone_num,
'phone_number': raw_phone_num
}; };
var action = { var action = {
name: r.action_name, name: r.action_name,
@ -73,7 +72,7 @@ var FieldPhone = formwidgets.FieldChar.extend({
view_mode: 'form', view_mode: 'form',
views: [[false, 'form']], views: [[false, 'form']],
target: 'new', target: 'new',
context: context,
context: context
}; };
web_client.action_manager.do_action(action); web_client.action_manager.do_action(action);
} }
@ -106,8 +105,7 @@ var FieldFax = formwidgets.FieldChar.extend({
var raw_fax_num = fax_num.replace(/ /g, ''); var raw_fax_num = fax_num.replace(/ /g, '');
raw_fax_num = raw_fax_num.replace(/-/g, ''); raw_fax_num = raw_fax_num.replace(/-/g, '');
this.$el.find('a').attr('href', 'fax:' + raw_fax_num).text(fax_num); this.$el.find('a').attr('href', 'fax:' + raw_fax_num).text(fax_num);
}
else {
} else {
this.$el.find('a').attr('href', '').text(''); this.$el.find('a').attr('href', '').text('');
} }
} }

6
base_phone/wizard/number_not_found.py

@ -5,9 +5,11 @@
from openerp import models, fields, api, _ from openerp import models, fields, api, _
from openerp.exceptions import UserError from openerp.exceptions import UserError
import logging import logging
import phonenumbers
_logger = logging.getLogger(__name__) _logger = logging.getLogger(__name__)
try:
import phonenumbers
except (ImportError, IOError) as err:
_logger.debug(err)
class NumberNotFound(models.TransientModel): class NumberNotFound(models.TransientModel):

86
base_phone_popup/README.rst

@ -0,0 +1,86 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=================
Base Phone Pop-up
=================
When the user receives a phone call, Odoo can automatically open the
corresponding partner/lead/employee/... in a pop-up without any action from
the user.
Installation
============
To install this module, you need to:
* Click on the module and install it
The module *web_action_request* can be downloaded with Mercurial:
hg clone http://bitbucket.org/anybox/web_action_request
It depends on 2 other modules, *web_longpolling* and *web_socketio*, that can
be downloaded with this command:
hg clone http://bitbucket.org/anybox/web_socketio
You will find some hints in this documentation :
https://bitbucket.org/anybox/web_action_request
Warning : proxying WebSockets is only supported since Nginx 1.3.13 ; the
feature provided by this module won't work with older versions of Nginx.
TODO : document this new feature on the Akretion Web site :
http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector
Configuration
=============
To configure this module, you need to:
* Configure users under Settings > Users > $USER
Usage
=====
* Install, configure user, use.
Known issues / Roadmap
======================
* None
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/connector-telephony/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Akretion
* Odoo Community Association (OCA)
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

26
base_phone_popup/__openerp__.py

@ -9,32 +9,6 @@
'category': 'Phone', 'category': 'Phone',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Pop-up the related form view to the user on incoming calls', 'summary': 'Pop-up the related form view to the user on incoming calls',
'description': """
Base Phone Pop-up
=================
When the user receives a phone call, OpenERP can automatically open the
corresponding partner/lead/employee/... in a pop-up without any action from the
user.
The module *web_action_request* can be downloaded with Mercurial:
hg clone http://bitbucket.org/anybox/web_action_request
It depends on 2 other modules, *web_longpolling* and *web_socketio*, that can
be downloaded with this command:
hg clone http://bitbucket.org/anybox/web_socketio
You will find some hints in this documentation :
https://bitbucket.org/anybox/web_action_request
Warning : proxying WebSockets is only supported since Nginx 1.3.13 ; the
feature provided by this module won't work with older versions of Nginx.
TODO : document this new feature on the Akretion Web site :
http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector
""",
'author': "Akretion,Odoo Community Association (OCA)", 'author': "Akretion,Odoo Community Association (OCA)",
'website': 'http://www.akretion.com/', 'website': 'http://www.akretion.com/',
'depends': ['base_phone', 'web_action_request'], 'depends': ['base_phone', 'web_action_request'],

70
crm_phone/README.rst

@ -0,0 +1,70 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
=========
CRM Phone
=========
This module validate phone numbers in the CRM module, just like the
*base_phone* module valide phone numbers in the Partner form. Please refer to
the description of the *base_phone* module for more information.
This module is independant from the Asterisk and FreeSWITCH connectors.
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com>
for any help or question about this module.
Installation
============
To install this module, you need to:
* Click on the module and install it
Configuration
=============
* None beyond *base_phone* configuration.
Usage
=====
Known issues / Roadmap
======================
* None
Bug Tracker
===========
Bugs are tracked on `GitHub Issues
<https://github.com/OCA/connector-telephony/issues>`_. In case of trouble, please
check there if your issue has already been reported. If you spotted it first,
help us smashing it by providing a detailed and welcomed feedback.
Credits
=======
Contributors
------------
* Akretion
* Odoo Community Association (OCA)
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose
mission is to support the collaborative development of Odoo features and
promote its widespread use.
To contribute to this module, please visit http://odoo-community.org.

14
crm_phone/__openerp__.py

@ -8,23 +8,11 @@
'category': 'Phone', 'category': 'Phone',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'Validate phone numbers in CRM', 'summary': 'Validate phone numbers in CRM',
'description': """
CRM Phone
=========
This module validate phone numbers in the CRM module, just like the
*base_phone* module valide phone numbers in the Partner form. Please refer to
the description of the *base_phone* module for more information.
This module is independant from the Asterisk connector.
Please contact Alexis de Lattre from Akretion <alexis.delattre@akretion.com>
for any help or question about this module.
""",
'author': "Akretion,Odoo Community Association (OCA)", 'author': "Akretion,Odoo Community Association (OCA)",
'website': 'http://www.akretion.com/', 'website': 'http://www.akretion.com/',
'depends': ['base_phone', 'crm'], 'depends': ['base_phone', 'crm'],
'conflicts': ['crm_voip'], 'conflicts': ['crm_voip'],
'external_dependencies': {'python': ['phonenumbers']},
'data': [ 'data': [
'security/phonecall_security.xml', 'security/phonecall_security.xml',
'security/ir.model.access.csv', 'security/ir.model.access.csv',

8
crm_phone/crm_phone.py

@ -16,7 +16,7 @@ class CrmLead(models.Model):
phonecall_ids = fields.One2many( phonecall_ids = fields.One2many(
'crm.phonecall', 'opportunity_id', string='Phone Calls') 'crm.phonecall', 'opportunity_id', string='Phone Calls')
phonecall_count = fields.Integer( phonecall_count = fields.Integer(
compute='_count_phonecalls', string='Number of Phonecalls',
compute='_compute_count_phonecalls', string='Number of Phonecalls',
readonly=True) readonly=True)
@api.multi @api.multi
@ -39,7 +39,7 @@ class CrmLead(models.Model):
@api.multi @api.multi
@api.depends('phonecall_ids') @api.depends('phonecall_ids')
def _count_phonecalls(self):
def _compute_count_phonecalls(self):
cpo = self.env['crm.phonecall'] cpo = self.env['crm.phonecall']
for lead in self: for lead in self:
try: try:
@ -142,12 +142,12 @@ class ResPartner(models.Model):
phonecall_ids = fields.One2many( phonecall_ids = fields.One2many(
'crm.phonecall', 'partner_id', string='Phone Calls') 'crm.phonecall', 'partner_id', string='Phone Calls')
phonecall_count = fields.Integer( phonecall_count = fields.Integer(
compute='_count_phonecalls', string='Number of Phonecalls',
compute='_compute_count_phonecalls', string='Number of Phonecalls',
readonly=True) readonly=True)
@api.multi @api.multi
@api.depends('phonecall_ids') @api.depends('phonecall_ids')
def _count_phonecalls(self):
def _compute_count_phonecalls(self):
cpo = self.env['crm.phonecall'] cpo = self.env['crm.phonecall']
for partner in self: for partner in self:
try: try:

5
crm_phone/wizard/create_crm_phonecall.py

@ -3,7 +3,12 @@
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from openerp import models, api, _ from openerp import models, api, _
import logging
_logger = logging.getLogger(__name__)
try:
import phonenumbers import phonenumbers
except (ImportError, IOError) as err:
_logger.debug(err)
class WizardCreateCrmPhonecall(models.TransientModel): class WizardCreateCrmPhonecall(models.TransientModel):

8
freeswitch_click2dial/README.rst

@ -54,7 +54,7 @@ Usage
To use this module, you need to: To use this module, you need to:
* See scripts/get_caller_name.py to see how to set caller and callee name
* See scripts/get_caller_name.py to see how to set caller and callee name.
* Click on Dial next to any phone number covered by associated modules. * Click on Dial next to any phone number covered by associated modules.
@ -77,13 +77,13 @@ To use this module, you need to:
instructions in the script on the Odoo/Odoo server. This works for instructions in the script on the Odoo/Odoo server. This works for
incoming and outgoing calls, per instructions in the script. incoming and outgoing calls, per instructions in the script.
3) *Open Caller* Here is how it works :
3) *Open Caller*. Here is how it works :
* When the user clicks on the phone icon, Odoo sends a query to the * When the user clicks on the phone icon, Odoo sends a query to the
FreeSWITCH Manager Interface to get a list of the current phone calls
FreeSWITCH Manager Interface to get a list of the current phone calls.
* If it finds a phone call involving the user's phone, it gets the phone * If it finds a phone call involving the user's phone, it gets the phone
number of the calling party
number of the calling party.
* It searches the phone number of the calling party in the * It searches the phone number of the calling party in the
Partners/Leads/Candidates/Registrations of Odoo. If a record matches, Partners/Leads/Candidates/Registrations of Odoo. If a record matches,

2
freeswitch_click2dial/__openerp__.py

@ -6,7 +6,7 @@
{ {
'name': 'FreeSWITCH Click2dial', 'name': 'FreeSWITCH Click2dial',
'version': '9.0.1.0.0',
'version': '9.0.1.0.1',
'category': 'Phone', 'category': 'Phone',
'license': 'AGPL-3', 'license': 'AGPL-3',
'summary': 'FreeSWITCH-Odoo connector', 'summary': 'FreeSWITCH-Odoo connector',

4
freeswitch_click2dial/controller.py

@ -14,5 +14,5 @@ class FreeSWITCHClick2dialController(http.Controller):
'/freeswitch_click2dial/get_record_from_my_channel/', '/freeswitch_click2dial/get_record_from_my_channel/',
type='json', auth='public') type='json', auth='public')
def get_record_from_my_channel(self, **kw): def get_record_from_my_channel(self, **kw):
res = http.request.env['freeswitch.server'].get_record_from_my_channel()
return res
FreeswitchServer = http.request.env['freeswitch.server']
return FreeswitchServer.get_record_from_my_channel()

21
freeswitch_click2dial/freeswitch_click2dial.py

@ -19,7 +19,8 @@ _logger = logging.getLogger(__name__)
class FreeSWITCHServer(models.Model): class FreeSWITCHServer(models.Model):
'''FreeSWITCH server object, stores the parameters of the FreeSWITCH Servers'''
'''FreeSWITCH server object, stores the parameters of the FreeSWITCH
Servers'''
_name = "freeswitch.server" _name = "freeswitch.server"
_description = "FreeSWITCH Servers" _description = "FreeSWITCH Servers"
name = fields.Char(string='FreeSWITCH Server Name', required=True) name = fields.Char(string='FreeSWITCH Server Name', required=True)
@ -72,10 +73,10 @@ class FreeSWITCHServer(models.Model):
'out_prefix', 'wait_time', 'port', 'context', 'alert_info', 'password') 'out_prefix', 'wait_time', 'port', 'context', 'alert_info', 'password')
def _check_validity(self): def _check_validity(self):
for server in self: for server in self:
out_prefix = ('Out prefix', server.out_prefix)
dialplan_context = ('Dialplan context', server.context)
alert_info = ('Alert-Info SIP header', server.alert_info)
password = ('Event Socket password', server.password)
out_prefix = (_('Out prefix'), server.out_prefix)
dialplan_context = (_('Dialplan context'), server.context)
alert_info = (_('Alert-Info SIP header'), server.alert_info)
password = (_('Event Socket password'), server.password)
if out_prefix[1] and not out_prefix[1].isdigit(): if out_prefix[1] and not out_prefix[1].isdigit():
raise ValidationError( raise ValidationError(
@ -130,7 +131,7 @@ class FreeSWITCHServer(models.Model):
fs_manager = ESL.ESLconnection( fs_manager = ESL.ESLconnection(
str(fs_server.ip_address), str(fs_server.ip_address),
str(fs_server.port), str(fs_server.password)) str(fs_server.port), str(fs_server.password))
except Exception, e:
except Exception as e:
_logger.error( _logger.error(
"Error in the request to the FreeSWITCH Event Socket %s", "Error in the request to the FreeSWITCH Event Socket %s",
fs_server.ip_address) fs_server.ip_address)
@ -148,7 +149,7 @@ class FreeSWITCHServer(models.Model):
fs_manager = ESL.ESLconnection( fs_manager = ESL.ESLconnection(
str(self.ip_address), str(self.ip_address),
str(self.port), str(self.password)) str(self.port), str(self.password))
except Exception, e:
except Exception as e:
raise UserError( raise UserError(
_("Connection Test Failed! The error message is: %s" % e)) _("Connection Test Failed! The error message is: %s" % e))
finally: finally:
@ -159,7 +160,7 @@ class FreeSWITCHServer(models.Model):
"Password.")) "Password."))
else: else:
fs_manager.disconnect() fs_manager.disconnect()
except Exception, e:
except Exception as e:
pass pass
raise UserError(_( raise UserError(_(
"Connection Test Successfull! Odoo can successfully login to " "Connection Test Successfull! Odoo can successfully login to "
@ -190,7 +191,7 @@ class FreeSWITCHServer(models.Model):
calling_party_number = f['rows'][x]['dest'] calling_party_number = f['rows'][x]['dest']
else: else:
calling_party_number = f['rows'][x]['cid_num'] calling_party_number = f['rows'][x]['cid_num']
except Exception, e:
except Exception as e:
_logger.error( _logger.error(
"Error in the Status request to FreeSWITCH server %s", "Error in the Status request to FreeSWITCH server %s",
fs_server.ip_address) fs_server.ip_address)
@ -398,7 +399,7 @@ class PhoneCommon(models.AbstractModel):
'\'' + self.get_name_from_phone_number(fs_number) + '\' ' + \ '\'' + self.get_name_from_phone_number(fs_number) + '\' ' + \
fs_number fs_number
fs_manager.api('originate', dial_string.encode('utf-8')) fs_manager.api('originate', dial_string.encode('utf-8'))
except Exception, e:
except Exception as e:
_logger.error( _logger.error(
"Error in the Originate request to FreeSWITCH server %s", "Error in the Originate request to FreeSWITCH server %s",
fs_server.ip_address) fs_server.ip_address)

16
freeswitch_click2dial/scripts/get_caller_name.py

@ -3,6 +3,7 @@
# (c) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com> # (c) 2010-2014 Alexis de Lattre <alexis.delattre@akretion.com>
# (c) 2014-2016 Trever L. Adams <trever.adams@gmail.com> # (c) 2014-2016 Trever L. Adams <trever.adams@gmail.com>
# License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html
# flake8: noqa: E501
""" """
Name lookup in OpenERP for incoming and outgoing calls with an Name lookup in OpenERP for incoming and outgoing calls with an
FreeSWITCH system FreeSWITCH system
@ -36,9 +37,7 @@
Notify should be the internal number of the called parties. This should be Notify should be the internal number of the called parties. This should be
comma (,) delimited, not :_: delimited. It is up to you to format the comma (,) delimited, not :_: delimited. It is up to you to format the
extensions list appropriately. The persons who are at extensions in the extensions list appropriately. The persons who are at extensions in the
notify list will receive a poppup if so configured and if they are logged in.
The notify list actually shouldn't be in the cidlookup.conf, but should be
used when doing notify (in an on answer hook for example).
notify list will receive a pop-up if so configured and if they are logged in.
From the dialplan, do something like this <action application="set" From the dialplan, do something like this <action application="set"
data="effective_caller_id_name=${cidlookup(${caller_id_number})}"/>. data="effective_caller_id_name=${cidlookup(${caller_id_number})}"/>.
@ -57,11 +56,10 @@
""" """
__author__ = "Trever Adams <trever.adams@gmail.com>" __author__ = "Trever Adams <trever.adams@gmail.com>"
__date__ = "August 2016"
__version__ = "0.5"
__date__ = "June 2017"
__version__ = "0.6"
import sys import sys
sys.path.append('.')
import xmlrpclib import xmlrpclib
from cgi import parse_qs, escape from cgi import parse_qs, escape
import unicodedata import unicodedata
@ -69,7 +67,7 @@ import unicodedata
# Name that will be displayed if there is no match # Name that will be displayed if there is no match
# and no geolocalisation # and no geolocalisation
not_found_name = "Not in OpenERP"
not_found_name = "Not in Odoo"
# Name used if name and number are both empty # Name used if name and number are both empty
unknown_name = "unknown" unknown_name = "unknown"
@ -99,7 +97,7 @@ def geolocate_phone_number(number, my_country_code, lang):
res = '' res = ''
phonenum = phonenumbers.parse(number, my_country_code.upper()) phonenum = phonenumbers.parse(number, my_country_code.upper())
city = phonenumbers.geocoder.description_for_number(phonenum, lang.lower())
city = geocoder.description_for_number(phonenum, lang.lower())
country_code = phonenumbers.region_code_for_number(phonenum) country_code = phonenumbers.region_code_for_number(phonenum)
# We don't display the country name when it's my own country # We don't display the country name when it's my own country
if country_code == my_country_code.upper(): if country_code == my_country_code.upper():
@ -107,7 +105,7 @@ def geolocate_phone_number(number, my_country_code, lang):
res = city res = city
else: else:
# Convert country code to country name # Convert country code to country name
country = phonenumbers.geocoder._region_display_name(
country = geocoder._region_display_name(
country_code, lang.lower()) country_code, lang.lower())
if country and city: if country and city:
res = country + ' ' + city res = country + ' ' + city

20
freeswitch_click2dial/static/src/js/freeswitch_click2dial.js

@ -32,14 +32,12 @@ click2dial.OpenCaller = Widget.extend({
_t('Failure'), _t('Failure'),
_t('Problem in the connection to FreeSWITCH'), _t('Problem in the connection to FreeSWITCH'),
false); false);
}
else if (typeof r == 'string' && isNaN(r)) {
} else if (typeof r == 'string' && isNaN(r)) {
self.do_warn( self.do_warn(
r, r,
_t('The calling number is not a phone number!'), _t('The calling number is not a phone number!'),
false); false);
}
else if (typeof r == 'string') {
} else if (typeof r == 'string') {
var action = { var action = {
name: _t('Number Not Found'), name: _t('Number Not Found'),
type: 'ir.actions.act_window', type: 'ir.actions.act_window',
@ -47,13 +45,13 @@ click2dial.OpenCaller = Widget.extend({
view_mode: 'form', view_mode: 'form',
views: [[false, 'form']], views: [[false, 'form']],
target: 'new', target: 'new',
context: {'default_calling_number': r},
context: {'default_calling_number': r}
}; };
web_client.action_manager.do_action(action); web_client.action_manager.do_action(action);
}
else if (typeof r == 'object' && r.length == 3) {
self.do_notify( // Not working
} else if (typeof r == 'object' && r.length == 3) {
// self.do_notify Not working
self.do_notify(
_t('Success'), _t('Success'),
_t('Moving to %s ID %d', r[0], r[1]), _t('Moving to %s ID %d', r[0], r[1]),
false); false);
@ -71,12 +69,12 @@ click2dial.OpenCaller = Widget.extend({
If you want to use target: 'current', with web/enterprise, If you want to use target: 'current', with web/enterprise,
you have to reload the Web page just after */ you have to reload the Web page just after */
target: 'current', target: 'current',
context: {},
context: {}
}; };
web_client.action_manager.do_action(action); web_client.action_manager.do_action(action);
} }
}); });
},
}
}); });
UserMenu.include({ UserMenu.include({
@ -87,7 +85,7 @@ click2dial.OpenCaller = Widget.extend({
// attach the phone logo/button to the systray // attach the phone logo/button to the systray
freeswitch_button.appendTo($('.oe_systray')); freeswitch_button.appendTo($('.oe_systray'));
}); });
},
}
}); });
}); });
Loading…
Cancel
Save