[MIG] web_notify: Migration to 18.0

pull/2956/head
trisdoan 2024-10-07 15:19:30 +07:00
parent 6997e5940e
commit 51616198d9
8 changed files with 62 additions and 64 deletions

View File

@ -154,6 +154,12 @@ Contributors
- Nikul Chaudhary <nchaudhary@opensourceintegrators.com> - Nikul Chaudhary <nchaudhary@opensourceintegrators.com>
- Tris Doan <tridm@trobz.com> - Tris Doan <tridm@trobz.com>
Other credits
-------------
The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.
Maintainers Maintainers
----------- -----------

View File

@ -6,7 +6,7 @@
"name": "Web Notify", "name": "Web Notify",
"summary": """ "summary": """
Send notification messages to user""", Send notification messages to user""",
"version": "17.0.1.0.0", "version": "18.0.1.0.0",
"license": "AGPL-3", "license": "AGPL-3",
"author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)", "author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)",
"development_status": "Production/Stable", "development_status": "Production/Stable",

View File

@ -130,6 +130,8 @@ class ResUsers(models.Model):
"action": action, "action": action,
"params": dict(params or []), "params": dict(params or []),
} }
for partner in target:
notifications = [[partner, "web.notify", [bus_message]] for partner in target] partner._bus_send(
self.env["bus.bus"]._sendmany(notifications) "web_notify",
bus_message,
)

View File

@ -0,0 +1 @@
The migration of this module from 17.0 to 18.0 was financially supported by Camptocamp.

View File

@ -390,7 +390,8 @@ supported.</p>
<li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul> <li><a class="reference internal" href="#credits" id="toc-entry-4">Credits</a><ul>
<li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li> <li><a class="reference internal" href="#authors" id="toc-entry-5">Authors</a></li>
<li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li> <li><a class="reference internal" href="#contributors" id="toc-entry-6">Contributors</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-7">Maintainers</a></li> <li><a class="reference internal" href="#other-credits" id="toc-entry-7">Other credits</a></li>
<li><a class="reference internal" href="#maintainers" id="toc-entry-8">Maintainers</a></li>
</ul> </ul>
</li> </li>
</ul> </ul>
@ -483,8 +484,13 @@ If you spotted it first, help us to smash it by providing a detailed and welcome
<li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li> <li>Tris Doan &lt;<a class="reference external" href="mailto:tridm&#64;trobz.com">tridm&#64;trobz.com</a>&gt;</li>
</ul> </ul>
</div> </div>
<div class="section" id="other-credits">
<h2><a class="toc-backref" href="#toc-entry-7">Other credits</a></h2>
<p>The migration of this module from 17.0 to 18.0 was financially supported
by Camptocamp.</p>
</div>
<div class="section" id="maintainers"> <div class="section" id="maintainers">
<h2><a class="toc-backref" href="#toc-entry-7">Maintainers</a></h2> <h2><a class="toc-backref" href="#toc-entry-8">Maintainers</a></h2>
<p>This module is maintained by the OCA.</p> <p>This module is maintained by the OCA.</p>
<a class="reference external image-reference" href="https://odoo-community.org"> <a class="reference external image-reference" href="https://odoo-community.org">
<img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" /> <img alt="Odoo Community Association" src="https://odoo-community.org/logo.png" />

View File

@ -1,4 +1,3 @@
/** @odoo-module */
import {Notification} from "@web/core/notifications/notification"; import {Notification} from "@web/core/notifications/notification";
import {patch} from "@web/core/utils/patch"; import {patch} from "@web/core/utils/patch";

View File

@ -1,64 +1,48 @@
/** @odoo-module **/
import {markup} from "@odoo/owl"; import {markup} from "@odoo/owl";
import {browser} from "@web/core/browser/browser";
import {registry} from "@web/core/registry"; import {registry} from "@web/core/registry";
export const webNotificationService = { export const webNotificationService = {
dependencies: ["bus_service", "notification", "action"], dependencies: ["bus_service", "notification", "action"],
start(env, {bus_service, notification, action}) { start(env, {bus_service, notification: notificationService, action}) {
let webNotifTimeouts = {}; function displayWebNotification(notification) {
/** let buttons = [];
* Displays the web notification on user's screen if (notification.action) {
* @param {*} notifications const params = notification.action.context?.params || {};
*/
function displaywebNotification(notifications) { buttons = [
Object.values(webNotifTimeouts).forEach((notif) => {
browser.clearTimeout(notif) name: params.button_name || env._t("Open"),
primary: true,
onClick: async () => {
await action.doAction(notification.action);
},
...(params.button_icon && {icon: params.button_icon}),
},
];
}
const notificationRemove = notificationService.add(
markup(notification.message),
{
title: notification.title,
type: notification.type,
sticky: notification.sticky,
className: notification.className,
buttons: buttons.map((button) => {
const onClick = button.onClick;
button.onClick = async () => {
await onClick();
notificationRemove();
};
return button;
}),
}
); );
webNotifTimeouts = {};
notifications.forEach((notif) => {
browser.setTimeout(() => {
var buttons = [];
if (notif.action) {
const params =
(notif.action.context && notif.action.context.params) || {};
buttons = [
{
name: params.button_name || env._t("Open"),
primary: true,
onClick: async () => {
await action.doAction(notif.action);
},
...(params.button_icon && {icon: params.button_icon}),
},
];
}
const notificationRemove = notification.add(markup(notif.message), {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
className: notif.className,
buttons: buttons.map((button) => {
const onClick = button.onClick;
button.onClick = async () => {
await onClick();
notificationRemove();
};
return button;
}),
});
});
});
} }
bus_service.addEventListener("notification", ({detail: notifications}) => { bus_service.subscribe("web_notify", (payload) => {
for (const {payload, type} of notifications) { displayWebNotification(payload);
if (type === "web.notify") {
displaywebNotification(payload);
}
}
}); });
bus_service.start(); bus_service.start();
}, },

View File

@ -26,7 +26,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
test_msg.update({"type": SUCCESS}) test_msg.update({"type": SUCCESS})
payload = json.loads(news.message)["payload"][0] payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload) self.assertDictEqual(test_msg, payload)
def test_notify_danger(self): def test_notify_danger(self):
@ -45,7 +45,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
test_msg.update({"type": DANGER}) test_msg.update({"type": DANGER})
payload = json.loads(news.message)["payload"][0] payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload) self.assertDictEqual(test_msg, payload)
def test_notify_warning(self): def test_notify_warning(self):
@ -64,7 +64,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
test_msg.update({"type": WARNING}) test_msg.update({"type": WARNING})
payload = json.loads(news.message)["payload"][0] payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload) self.assertDictEqual(test_msg, payload)
def test_notify_info(self): def test_notify_info(self):
@ -83,7 +83,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
test_msg.update({"type": INFO}) test_msg.update({"type": INFO})
payload = json.loads(news.message)["payload"][0] payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload) self.assertDictEqual(test_msg, payload)
def test_notify_default(self): def test_notify_default(self):
@ -102,7 +102,7 @@ class TestResUsers(common.TransactionCase):
news = bus_bus.search(domain) - existing news = bus_bus.search(domain) - existing
self.assertEqual(1, len(news)) self.assertEqual(1, len(news))
test_msg.update({"type": DEFAULT}) test_msg.update({"type": DEFAULT})
payload = json.loads(news.message)["payload"][0] payload = json.loads(news.message)["payload"]
self.assertDictEqual(test_msg, payload) self.assertDictEqual(test_msg, payload)
def test_notify_many(self): def test_notify_many(self):