diff --git a/asterisk_click2dial/__manifest__.py b/asterisk_click2dial/__manifest__.py index 33dd51d..f195c09 100644 --- a/asterisk_click2dial/__manifest__.py +++ b/asterisk_click2dial/__manifest__.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2018 Akretion (Alexis de Lattre ) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { - 'name': 'Asterisk Click2dial', - 'version': '10.0.1.0.0', + 'name': 'Asterisk connector', + 'version': '12.0.1.0.0', 'category': 'Phone', 'license': 'AGPL-3', 'summary': 'Asterisk-Odoo connector', @@ -83,11 +83,11 @@ http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector 'views/asterisk_server.xml', 'views/res_users.xml', 'security/ir.model.access.csv', - 'web_asterisk_click2dial.xml', + 'security/asterisk_security.xml', + 'views/web_asterisk_click2dial.xml', ], 'demo': ['demo/asterisk_click2dial_demo.xml'], - 'qweb': ['static/src/xml/*.xml'], - 'css': ['static/src/css/*.css'], + 'qweb': ['static/src/xml/asterisk_click2dial.xml'], 'application': True, 'installable': True, } diff --git a/asterisk_click2dial/controller.py b/asterisk_click2dial/controller.py index 3efd84b..7bc8d65 100644 --- a/asterisk_click2dial/controller.py +++ b/asterisk_click2dial/controller.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- -# © 2014-2016 Akretion (Alexis de Lattre ) -# © 2015-2016 Juris Malinens (port to v9) +# Copyright 2014-2018 Akretion France +# @author: Alexis de Lattre +# Copyright 2015-2018 Juris Malinens (port to v9) # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import http @@ -9,8 +10,8 @@ from odoo import http class AsteriskClick2dialController(http.Controller): @http.route( - '/asterisk_click2dial/get_record_from_my_channel/', - type='json', auth='public') + '/asterisk_click2dial/get_record_from_my_channel', type='json', + auth='user') def get_record_from_my_channel(self, **kw): res = http.request.env['asterisk.server'].get_record_from_my_channel() return res diff --git a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml index a3f5b05..bab5e7b 100644 --- a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml +++ b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml @@ -1,6 +1,6 @@ @@ -31,9 +31,5 @@ - - - - diff --git a/asterisk_click2dial/models/asterisk_server.py b/asterisk_click2dial/models/asterisk_server.py index d0d7b99..423bf1d 100644 --- a/asterisk_click2dial/models/asterisk_server.py +++ b/asterisk_click2dial/models/asterisk_server.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2018 Akretion France +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, fields, api, _ @@ -22,8 +23,7 @@ class AsteriskServer(models.Model): _description = "Asterisk Servers" name = fields.Char(string='Asterisk Server Name', required=True) - active = fields.Boolean( - string='Active', default=True) + active = fields.Boolean(string='Active', default=True) ip_address = fields.Char( string='Asterisk IP address or DNS', required=True) port = fields.Integer( @@ -70,7 +70,6 @@ class AsteriskServer(models.Model): 'asterisk.server'), help="Company who uses the Asterisk server.") - @api.multi @api.constrains( 'out_prefix', 'wait_time', 'extension_priority', 'port', 'context', 'alert_info', 'login', 'password') @@ -83,30 +82,30 @@ class AsteriskServer(models.Model): password = ('AMI password', server.password) if out_prefix[1] and not out_prefix[1].isdigit(): - raise ValidationError( - _("Only use digits for the '%s' on the Asterisk server " - "'%s'" % (out_prefix[0], server.name))) + raise ValidationError(_( + "Only use digits for the '%s' on the Asterisk server " + "'%s'" % (out_prefix[0], server.name))) if server.wait_time < 1 or server.wait_time > 120: - raise ValidationError( - _("You should set a 'Wait time' value between 1 and 120 " - "seconds for the Asterisk server '%s'" % server.name)) + raise ValidationError(_( + "You should set a 'Wait time' value between 1 and 120 " + "seconds for the Asterisk server '%s'" % server.name)) if server.extension_priority < 1: - raise ValidationError( - _("The 'extension priority' must be a positive value for " - "the Asterisk server '%s'" % server.name)) + raise ValidationError(_( + "The 'extension priority' must be a positive value for " + "the Asterisk server '%s'" % server.name)) if server.port > 65535 or server.port < 1: - raise ValidationError( - _("You should set a TCP port between 1 and 65535 for the " - "Asterisk server '%s'" % server.name)) + raise ValidationError(_( + "You should set a TCP port between 1 and 65535 for the " + "Asterisk server '%s'" % server.name)) for check_str in [dialplan_context, alert_info, login, password]: if check_str[1]: try: check_str[1].encode('ascii') except UnicodeEncodeError: - raise ValidationError( - _("The '%s' should only have ASCII caracters for " - "the Asterisk server '%s'" - % (check_str[0], server.name))) + raise ValidationError(_( + "The '%s' should only have ASCII caracters for " + "the Asterisk server '%s'" + % (check_str[0], server.name))) @api.model def _connect_to_asterisk(self): @@ -119,13 +118,13 @@ class AsteriskServer(models.Model): ast_server = user.get_asterisk_server_from_user() # We check if the current user has a chan type if not user.asterisk_chan_type: - raise UserError( - _('No channel type configured for the current user.')) + raise UserError(_( + 'No channel type configured for the current user.')) # We check if the current user has an internal number if not user.resource: - raise UserError( - _('No resource name configured for the current user')) + raise UserError(_( + 'No resource name configured for the current user')) _logger.debug( "User's phone: %s/%s", user.asterisk_chan_type, user.resource) @@ -137,18 +136,17 @@ class AsteriskServer(models.Model): ast_manager = Manager.Manager( (ast_server.ip_address, ast_server.port), ast_server.login, ast_server.password) - except Exception, e: + except Exception as e: _logger.error( "Error in the request to the Asterisk Manager Interface %s", ast_server.ip_address) _logger.error("Here is the error message: %s", e) - raise UserError( - _("Problem in the request from Odoo to Asterisk. " - "Here is the error message: %s" % e)) + raise UserError(_( + "Problem in the request from Odoo to Asterisk. " + "Here is the error message: %s" % e)) return (user, ast_server, ast_manager) - @api.multi def test_ami_connection(self): self.ensure_one() ast_manager = False @@ -157,9 +155,9 @@ class AsteriskServer(models.Model): (self.ip_address, self.port), self.login, self.password) - except Exception, e: - raise UserError( - _("Connection Test Failed! The error message is: %s" % e)) + except Exception as e: + raise UserError(_( + "Connection Test Failed! The error message is: %s" % e)) finally: if ast_manager: ast_manager.Logoff() @@ -207,15 +205,15 @@ class AsteriskServer(models.Model): chan, user) if calling_party_number: break - except Exception, e: + except Exception as e: _logger.error( "Error in the Status request to Asterisk server %s", ast_server.ip_address) _logger.error( - "Here are the details of the error: '%s'", unicode(e)) - raise UserError( - _("Can't get calling number from Asterisk.\nHere is the " - "error: '%s'" % unicode(e))) + "Here are the details of the error: '%s'", str(e)) + raise UserError(_( + "Can't get calling number from Asterisk.\nHere is the " + "error: '%s'" % str(e))) finally: ast_manager.Logoff() diff --git a/asterisk_click2dial/models/phone_common.py b/asterisk_click2dial/models/phone_common.py index a898f48..c3627f7 100644 --- a/asterisk_click2dial/models/phone_common.py +++ b/asterisk_click2dial/models/phone_common.py @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2018 Akretion France +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). from odoo import models, api, _ @@ -51,21 +52,20 @@ class PhoneCommon(models.AbstractModel): channel, context=ast_server.context, extension=ast_number, - priority=unicode(ast_server.extension_priority), - timeout=unicode(ast_server.wait_time * 1000), + 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: + except Exception as e: _logger.error( "Error in the Originate request to Asterisk server %s", ast_server.ip_address) _logger.error( - "Here are the details of the error: '%s'", unicode(e)) - raise UserError( - _("Click to dial with Asterisk failed.\nHere is the error: " - "'%s'") - % unicode(e)) + "Here are the details of the error: '%s'", str(e)) + raise UserError(_( + "Click to dial with Asterisk failed.\nHere is the error: " + "'%s'") % str(e)) finally: ast_manager.Logoff() diff --git a/asterisk_click2dial/models/res_users.py b/asterisk_click2dial/models/res_users.py index e6c9637..619d9f3 100644 --- a/asterisk_click2dial/models/res_users.py +++ b/asterisk_click2dial/models/res_users.py @@ -1,8 +1,9 @@ # -*- coding: utf-8 -*- -# © 2010-2016 Akretion (Alexis de Lattre ) +# Copyright 2010-2018 Akretion France +# @author: Alexis de Lattre # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -from odoo import models, fields, api, _ +from odoo import api, fields, models, _ from odoo.exceptions import UserError, ValidationError @@ -69,7 +70,6 @@ class ResUsers(models.Model): "If you leave this field empty, it will use the first Asterisk " "server of the user's company.") - @api.multi @api.constrains('resource', 'internal_number', 'callerid') def _check_validity(self): for user in self: @@ -88,7 +88,6 @@ class ResUsers(models.Model): "ASCII caracters") % (check_string[0], user.name)) - @api.multi def get_asterisk_server_from_user(self): '''Returns an asterisk.server recordset''' self.ensure_one() @@ -102,8 +101,8 @@ class ResUsers(models.Model): # If the user doesn't have an asterisk server, # we take the first one of the user's company if not asterisk_servers: - raise UserError( - _("No Asterisk server configured for the company '%s'.") + raise UserError(_( + "No Asterisk server configured for the company '%s'.") % self.company_id.name) else: ast_server = asterisk_servers[0] diff --git a/asterisk_click2dial/security/asterisk_security.xml b/asterisk_click2dial/security/asterisk_security.xml new file mode 100644 index 0000000..fec9a51 --- /dev/null +++ b/asterisk_click2dial/security/asterisk_security.xml @@ -0,0 +1,18 @@ + + + + + + + + + Asterisk server multi-company + + ['|', ('company_id', '=', False), ('company_id', 'child_of', [user.company_id.id])] + + + + diff --git a/asterisk_click2dial/static/src/css/asterisk_click2dial.css b/asterisk_click2dial/static/src/css/asterisk_click2dial.css deleted file mode 100644 index 6378c76..0000000 --- a/asterisk_click2dial/static/src/css/asterisk_click2dial.css +++ /dev/null @@ -1,26 +0,0 @@ -/* - © 2016 Akretion (Alexis de Lattre ) - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). -*/ - -.openerp .oe_topbar_item.oe_topbar_open_caller{ - padding: 0px; - width: 32px; - height: 32px; -} - -.openerp .oe_topbar_item.oe_topbar_open_caller 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; -} diff --git a/asterisk_click2dial/static/src/js/asterisk_click2dial.js b/asterisk_click2dial/static/src/js/asterisk_click2dial.js index 783eed4..a20a99f 100644 --- a/asterisk_click2dial/static/src/js/asterisk_click2dial.js +++ b/asterisk_click2dial/static/src/js/asterisk_click2dial.js @@ -1,20 +1,23 @@ -/* © 2014-2016 Akretion (Alexis de Lattre ) - © 2015-2016 Juris Malinens (port to v9) +/* Copyright 2014-2018 Akretion (Alexis de Lattre ) + Copyright 2015-2018 Juris Malinens (port to v9) License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ -odoo.define('asterisk_click2dial.click2dial', function (require) { +odoo.define('asterisk_click2dial.systray.OpenCaller', function (require) { "use strict"; +var core = require('web.core'); var SystrayMenu = require('web.SystrayMenu'); var web_client = require('web.web_client'); var Widget = require('web.Widget'); -var core = require('web.core'); + var _t = core._t; var click2dial = {}; -var click2dialOpenCaller = Widget.extend({ - template: 'asterisk_click2dial.OpenCaller', + +var OpenCallerMenu = Widget.extend({ + name: 'open_caller', + template: 'asterisk_click2dial.systray.OpenCaller', events: { 'click': 'on_open_caller', }, @@ -26,7 +29,11 @@ var click2dialOpenCaller = Widget.extend({ on_open_caller: function (event) { event.stopPropagation(); var self = this; - self.rpc('/asterisk_click2dial/get_record_from_my_channel', {}).done(function(r) { + var context = this.getSession().user_context; + self._rpc({ + route: '/asterisk_click2dial/get_record_from_my_channel', + params: {local_context: context, }, + }).done(function(r) { // console.log('RESULT RPC r='+r); // console.log('RESULT RPC type r='+typeof r); // console.log('RESULT RPC isNaN r='+isNaN(r)); @@ -82,6 +89,8 @@ var click2dialOpenCaller = Widget.extend({ }, }); -SystrayMenu.Items.push(click2dialOpenCaller); +SystrayMenu.Items.push(OpenCallerMenu); + +return OpenCallerMenu; }); diff --git a/asterisk_click2dial/static/src/scss/asterisk.scss b/asterisk_click2dial/static/src/scss/asterisk.scss new file mode 100644 index 0000000..9cea878 --- /dev/null +++ b/asterisk_click2dial/static/src/scss/asterisk.scss @@ -0,0 +1,14 @@ +/* + Copyright 2016-2018 Akretion (Alexis de Lattre ) + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +*/ + +.o_asterisk_systray_item { + > a { + opacity: 1; + > i { + font-size: larger; + } + } +} + diff --git a/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml b/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml index a5488c0..155aa9a 100644 --- a/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml +++ b/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml @@ -1,24 +1,27 @@ diff --git a/asterisk_click2dial/views/asterisk_server.xml b/asterisk_click2dial/views/asterisk_server.xml index 06e13bb..246d838 100644 --- a/asterisk_click2dial/views/asterisk_server.xml +++ b/asterisk_click2dial/views/asterisk_server.xml @@ -1,6 +1,6 @@ @@ -42,7 +42,7 @@ + + phone + @@ -36,6 +40,17 @@ + + + + + diff --git a/crm_phone/view/crm_phonecall.xml b/crm_phone/view/crm_phonecall.xml index 8ff93a0..0fb2ed6 100644 --- a/crm_phone/view/crm_phonecall.xml +++ b/crm_phone/view/crm_phonecall.xml @@ -1,6 +1,7 @@ @@ -32,13 +33,13 @@ - - + + - + @@ -66,11 +67,11 @@ - +