From e899cc2f5ac42468b528952ba9b9403d115e9249 Mon Sep 17 00:00:00 2001 From: Luis Rodriguez Date: Fri, 12 Apr 2024 14:01:24 +0200 Subject: [PATCH] [MIG] asterisk_click2dial: Migration to 16.0 --- asterisk_click2dial/README.rst | 2 +- asterisk_click2dial/__manifest__.py | 10 +- .../demo/asterisk_click2dial_demo.xml | 4 +- asterisk_click2dial/models/asterisk_server.py | 34 +++--- asterisk_click2dial/models/phone_common.py | 2 +- asterisk_click2dial/models/res_users.py | 6 +- .../static/description/index.html | 2 +- .../asterisk_click2dial.esm.js | 89 +++++++++++++++ .../asterisk_click2dial.xml | 13 +++ .../static/src/js/asterisk_click2dial.js | 103 ------------------ .../static/src/xml/asterisk_click2dial.xml | 23 ---- asterisk_click2dial/views/asterisk_server.xml | 2 +- .../views/web_asterisk_click2dial.xml | 32 ------ 13 files changed, 137 insertions(+), 185 deletions(-) create mode 100644 asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js create mode 100644 asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml delete mode 100644 asterisk_click2dial/static/src/js/asterisk_click2dial.js delete mode 100644 asterisk_click2dial/static/src/xml/asterisk_click2dial.xml delete mode 100644 asterisk_click2dial/views/web_asterisk_click2dial.xml diff --git a/asterisk_click2dial/README.rst b/asterisk_click2dial/README.rst index f58182667..77273baf2 100644 --- a/asterisk_click2dial/README.rst +++ b/asterisk_click2dial/README.rst @@ -7,7 +7,7 @@ Asterisk connector !! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! - !! source digest: sha256:0ca90c5f1213086d6d8b02e06bcc36a064c5251ca38ee261aefaae3d173696db + !! source digest: sha256:70c4fbe57dbcfd18cf15685ed8361c0af932e8f5c65668c39a947eeccfd1cc1e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! .. |badge1| image:: https://img.shields.io/badge/maturity-Beta-yellow.png diff --git a/asterisk_click2dial/__manifest__.py b/asterisk_click2dial/__manifest__.py index 8f7ddd036..b42b6c85a 100644 --- a/asterisk_click2dial/__manifest__.py +++ b/asterisk_click2dial/__manifest__.py @@ -4,7 +4,7 @@ { "name": "Asterisk connector", - "version": "14.0.2.0.0", + "version": "16.0.1.0.0", "category": "Phone", "license": "AGPL-3", "summary": "Asterisk-Odoo connector", @@ -18,10 +18,16 @@ "views/res_users.xml", "security/ir.model.access.csv", "security/asterisk_security.xml", - "views/web_asterisk_click2dial.xml", ], "demo": ["demo/asterisk_click2dial_demo.xml"], "qweb": ["static/src/xml/asterisk_click2dial.xml"], "application": True, "installable": True, + "assets": { + "web.assets_backend": [ + "asterisk_click2dial/static/src/scss/*.scss", + "asterisk_click2dial/static/src/components/**/*.js", + "asterisk_click2dial/static/src/components/**/*.xml", + ], + }, } diff --git a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml index f0921499f..2d6c28a9b 100644 --- a/asterisk_click2dial/demo/asterisk_click2dial_demo.xml +++ b/asterisk_click2dial/demo/asterisk_click2dial_demo.xml @@ -8,8 +8,8 @@ - Akretion Asterisk IPBX - asterisk.akretion.com + My Asterisk + localhost odoo mypassword from-internal diff --git a/asterisk_click2dial/models/asterisk_server.py b/asterisk_click2dial/models/asterisk_server.py index 25571eb47..fbc5f3c6c 100644 --- a/asterisk_click2dial/models/asterisk_server.py +++ b/asterisk_click2dial/models/asterisk_server.py @@ -25,7 +25,7 @@ class AsteriskServer(models.Model): ip_address = fields.Char(string="Asterisk IP address or DNS", required=True) port = fields.Integer( required=True, - default=5038, + default=8088, help="TCP port on which the Asterisk REST Interface listens. " "Defined in /etc/asterisk/ari.conf on Asterisk.", ) @@ -104,8 +104,8 @@ def _check_validity(self): if out_prefix[1] and not out_prefix[1].isdigit(): raise ValidationError( _( - "Only use digits for the '%(out_prefix[0])s' on the Asterisk server " - "'%(server.name)s'" + f"Only use digits for the {out_prefix[0]} on the Asterisk server " + f"{server.name}" ) ) if server.wait_time < 1 or server.wait_time > 120: @@ -136,8 +136,8 @@ def _check_validity(self): except UnicodeEncodeError: raise ValidationError from None( _( - "The '%(check_str[0])s' should only have ASCII caracters for " - "the Asterisk server '%(server.name)s'" + f"The {check_str[0]} should only have ASCII caracters for " + f"the Asterisk server {server.name}" ) ) @@ -146,29 +146,33 @@ def _get_connect_info(self, url_path): user = self.env.user ast_server = user.get_asterisk_server_from_user() auth = (ast_server.login, ast_server.password) - url = "http://%s:%s%s" % (ast_server.ip_address, ast_server.port, url_path) + url = f"http://{ast_server.ip_address}:{ast_server.port}{url_path}" return ast_server, auth, url def test_ari_connection(self): self.ensure_one() auth = (self.login, self.password) - url = "http://%s:%s/ari/asterisk/info" % (self.ip_address, self.port) + url = f"http://{self.ip_address}:{self.port}/ari/asterisk/info" try: res = requests.get(url, auth=auth, timeout=TIMEOUT) except Exception as e: raise UserError from None( - _("Connection Test Failed! The error message is: %s" % e) + _(f"Connection Test Failed! The error message is: {e}") ) if res.status_code != 200: raise UserError( _("Connection Test Failed! HTTP error code: %s" % res.status_code) ) - raise UserError( - _( - "Connection Test Successfull! Odoo can successfully login to " - "the Asterisk Manager Interface." - ) - ) + + return { + "type": "ir.actions.client", + "tag": "display_notification", + "params": { + "type": "success", + "message": _("Your request has been successfully sent"), + "next": {"type": "ir.actions.act_window_close"}, + }, + } @api.model def _get_calling_number_from_channel(self, chan, user): @@ -204,9 +208,7 @@ def _get_calling_number(self): ) return False list_chan = res_req.json() - from pprint import pprint - pprint(list_chan) _logger.debug("Result of Status ARI request:") _logger.debug(pformat(list_chan)) for chan in list_chan: diff --git a/asterisk_click2dial/models/phone_common.py b/asterisk_click2dial/models/phone_common.py index 85aa10cfb..f21e2a6e3 100644 --- a/asterisk_click2dial/models/phone_common.py +++ b/asterisk_click2dial/models/phone_common.py @@ -77,7 +77,7 @@ def click2dial(self, erp_number): if res_req.status_code != 200: raise UserError( _("Click to dial with Asterisk failed.\nHTTP error code: %s.") - % res.status_code + % res_req.status_code ) res["dialed_number"] = ast_number diff --git a/asterisk_click2dial/models/res_users.py b/asterisk_click2dial/models/res_users.py index bb67de6ac..40ae2c879 100644 --- a/asterisk_click2dial/models/res_users.py +++ b/asterisk_click2dial/models/res_users.py @@ -101,8 +101,8 @@ def _check_validity(self): except UnicodeEncodeError: raise ValidationError from None( _( - "The '%(check_string[0])s' for the user '%(user.name)s'" - " should only have ASCII caracters" + f"The {check_string[0]} for the user {user.name} " + "should only have ASCII caracters" ) ) @@ -111,7 +111,7 @@ def _compute_asterisk_chan_name(self): for user in self: chan_name = False if user.asterisk_chan_type and user.resource: - chan_name = "%s/%s" % (user.asterisk_chan_type, user.resource) + chan_name = f"{user.asterisk_chan_type}/{user.resource}" user.asterisk_chan_name = chan_name def get_asterisk_server_from_user(self): diff --git a/asterisk_click2dial/static/description/index.html b/asterisk_click2dial/static/description/index.html index 52e9af954..05de829a4 100644 --- a/asterisk_click2dial/static/description/index.html +++ b/asterisk_click2dial/static/description/index.html @@ -367,7 +367,7 @@

Asterisk connector

!! This file is generated by oca-gen-addon-readme !! !! changes will be overwritten. !! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -!! source digest: sha256:0ca90c5f1213086d6d8b02e06bcc36a064c5251ca38ee261aefaae3d173696db +!! source digest: sha256:70c4fbe57dbcfd18cf15685ed8361c0af932e8f5c65668c39a947eeccfd1cc1e !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->

Beta License: AGPL-3 OCA/connector-telephony Translate me on Weblate Try me on Runboat

The technical name of this module is asterisk_click2dial, but this module diff --git a/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js new file mode 100644 index 000000000..3f2b128fe --- /dev/null +++ b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.esm.js @@ -0,0 +1,89 @@ +/** @odoo-module **/ + +/* + Copyright 2024 Dixmit + License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +*/ + +import {Component} from "@odoo/owl"; +import {_t} from "@web/core/l10n/translation"; +import {registry} from "@web/core/registry"; +import {useService} from "@web/core/utils/hooks"; + +const systrayRegistry = registry.category("systray"); + +export class Click2DialSystray extends Component { + setup() { + this.rpc = useService("rpc"); + this.action = useService("action"); + this.notification = useService("notification"); + this.user = useService("user"); + } + + async onOpenCaller() { + // Var session = require('web.session'); + + const r = await this.rpc("/asterisk_click2dial/get_record_from_my_channel", { + context: this.user.context, + }); + if (r === false) { + this.notification.add( + _t( + "Calling party number not retreived from IPBX or IPBX unreachable by Odoo" + ), + { + title: _t("IPBX error"), + } + ); + } else if (typeof r === "string" && isNaN(r)) { + this.notification.add(_t("The calling number is not a phone number!"), { + title: r, + }); + } else if (typeof r === "string") { + var action = { + name: _t("Number Not Found"), + type: "ir.actions.act_window", + res_model: "number.not.found", + view_mode: "form", + views: [[false, "form"]], + target: "new", + context: {default_calling_number: r}, + }; + this.action.doAction(action); + } else if (typeof r === "object" && r.length === 3) { + this.notification.add( + `${_("Moving to form view of ")}${r[2]}${_("(")}${r[0]}${_(" ID ")}${ + r[1] + }${_(")")}`, + { + title: `${_("On the phone with ")}${r[2]}`, + } + ); + var action_suc = { + type: "ir.actions.act_window", + res_model: r[0], + res_id: r[1], + view_mode: "form,tree", + views: [[false, "form"]], + /* If you want to make it work with the 'web' module + of Odoo Enterprise edition, you have to change the line + target: 'current', + to: + target: 'new', + If you want to use target: 'current', with web/enterprise, + you have to reload the Web page just after */ + target: "current", + context: {}, + }; + this.action.doAction(action_suc); + } + } +} + +Click2DialSystray.template = "asterisk_click2dial.Click2DialSystray"; + +export const systrayItem = {Component: Click2DialSystray}; + +systrayRegistry.add("asterisk_click2dial.Click2DialSystray", systrayItem, { + sequence: 99, +}); diff --git a/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml new file mode 100644 index 000000000..cda997699 --- /dev/null +++ b/asterisk_click2dial/static/src/components/asterisk_click2dial/asterisk_click2dial.xml @@ -0,0 +1,13 @@ + + + + +

+ + diff --git a/asterisk_click2dial/static/src/js/asterisk_click2dial.js b/asterisk_click2dial/static/src/js/asterisk_click2dial.js deleted file mode 100644 index 5758b5abd..000000000 --- a/asterisk_click2dial/static/src/js/asterisk_click2dial.js +++ /dev/null @@ -1,103 +0,0 @@ -/* eslint-disable */ - -/* Copyright 2014-2021 Akretion (Alexis de Lattre ) - Copyright 2015-2021 Juris Malinens (port to v9) - License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */ - -odoo.define("asterisk_click2dial.systray.OpenCaller", function (require) { - "use strict"; - - var core = require("web.core"); - var SystrayMenu = require("web.SystrayMenu"); - var Widget = require("web.Widget"); - - var _t = core._t; - - var FieldPhone = require("base_phone.updatedphone_widget").FieldPhone; - - FieldPhone.include({ - showDialButton: function () { - return true; - }, - }); - - var OpenCallerMenu = Widget.extend({ - name: "open_caller", - template: "asterisk_click2dial.systray.OpenCaller", - events: { - click: "on_open_caller", - }, - - on_open_caller: function (event) { - event.stopPropagation(); - var self = this; - var context = this.getSession().user_context; - self._rpc({ - route: "/asterisk_click2dial/get_record_from_my_channel", - params: {local_context: context}, - }).then(function (r) { - // Console.log('RESULT RPC r='+r); - // console.log('RESULT RPC type r='+typeof r); - // console.log('RESULT RPC isNaN r='+isNaN(r)); - if (r === false) { - self.do_warn( - _t("IPBX error"), - _t( - "Calling party number not retreived from IPBX or IPBX unreachable by Odoo" - ), - false - ); - } else if (typeof r === "string" && isNaN(r)) { - self.do_warn( - r, - _t("The calling number is not a phone number!"), - false - ); - } else if (typeof r === "string") { - var action = { - name: _t("Number Not Found"), - type: "ir.actions.act_window", - res_model: "number.not.found", - view_mode: "form", - views: [[false, "form"]], - target: "new", - context: {default_calling_number: r}, - }; - self.do_action(action); - } else if (typeof r === "object" && r.length === 3) { - self.do_notify( - _.str.sprintf(_t("On the phone with '%s'"), r[2]), - _.str.sprintf( - _t("Moving to form view of %s (%s ID %d)"), - r[2], - r[0], - r[1] - ), - false - ); - var action = { - type: "ir.actions.act_window", - res_model: r[0], - res_id: r[1], - view_mode: "form,tree", - views: [[false, "form"]], - /* If you want to make it work with the 'web' module - of Odoo Enterprise edition, you have to change the line - target: 'current', - to: - target: 'new', - If you want to use target: 'current', with web/enterprise, - you have to reload the Web page just after */ - target: "current", - context: {}, - }; - self.do_action(action); - } - }); - }, - }); - - SystrayMenu.Items.push(OpenCallerMenu); - - return OpenCallerMenu; -}); diff --git a/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml b/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml deleted file mode 100644 index 4ecec30c2..000000000 --- a/asterisk_click2dial/static/src/xml/asterisk_click2dial.xml +++ /dev/null @@ -1,23 +0,0 @@ - - - diff --git a/asterisk_click2dial/views/asterisk_server.xml b/asterisk_click2dial/views/asterisk_server.xml index 8186d9419..4df1f122b 100644 --- a/asterisk_click2dial/views/asterisk_server.xml +++ b/asterisk_click2dial/views/asterisk_server.xml @@ -81,7 +81,7 @@ asterisk.server.tree asterisk.server - + diff --git a/asterisk_click2dial/views/web_asterisk_click2dial.xml b/asterisk_click2dial/views/web_asterisk_click2dial.xml deleted file mode 100644 index 4aceaceeb..000000000 --- a/asterisk_click2dial/views/web_asterisk_click2dial.xml +++ /dev/null @@ -1,32 +0,0 @@ - - - - - - -