Skip to content

Commit

Permalink
[MIG] asterisk_click2dial: Migration to 16.0
Browse files Browse the repository at this point in the history
  • Loading branch information
luisDIXMIT committed Apr 16, 2024
1 parent 6bd81eb commit e899cc2
Show file tree
Hide file tree
Showing 13 changed files with 137 additions and 185 deletions.
2 changes: 1 addition & 1 deletion asterisk_click2dial/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 8 additions & 2 deletions asterisk_click2dial/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
],
},
}
4 changes: 2 additions & 2 deletions asterisk_click2dial/demo/asterisk_click2dial_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


<record id="demo_ast_server" model="asterisk.server">
<field name="name">Akretion Asterisk IPBX</field>
<field name="ip_address">asterisk.akretion.com</field>
<field name="name">My Asterisk</field>
<field name="ip_address">localhost</field>
<field name="login">odoo</field>
<field name="password">mypassword</field>
<field name="context">from-internal</field>
Expand Down
34 changes: 18 additions & 16 deletions asterisk_click2dial/models/asterisk_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
)
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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}"
)
)

Expand All @@ -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):
Expand Down Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion asterisk_click2dial/models/phone_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions asterisk_click2dial/models/res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
)

Expand All @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion asterisk_click2dial/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Asterisk connector</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:0ca90c5f1213086d6d8b02e06bcc36a064c5251ca38ee261aefaae3d173696db
!! source digest: sha256:70c4fbe57dbcfd18cf15685ed8361c0af932e8f5c65668c39a947eeccfd1cc1e
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Beta" src="https://img.shields.io/badge/maturity-Beta-yellow.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/connector-telephony/tree/16.0/asterisk_click2dial"><img alt="OCA/connector-telephony" src="https://img.shields.io/badge/github-OCA%2Fconnector--telephony-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/connector-telephony-16-0/connector-telephony-16-0-asterisk_click2dial"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/connector-telephony&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>The technical name of this module is <strong>asterisk_click2dial</strong>, but this module
Expand Down
Original file line number Diff line number Diff line change
@@ -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,
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8" ?>
<templates xml:space="preserve">

<t t-name="asterisk_click2dial.Click2DialSystray" owl="1">
<div
class="o-dropdown dropdown o-dropdown--no-caret o-mail-DiscussSystray-class"
>
<button class="dropdown-toggle " t-on-click="() => this.onOpenCaller()">
<i class="fa fa-phone" />
</button>
</div>
</t>
</templates>
103 changes: 0 additions & 103 deletions asterisk_click2dial/static/src/js/asterisk_click2dial.js

This file was deleted.

Loading

0 comments on commit e899cc2

Please sign in to comment.