diff --git a/web_notify/__manifest__.py b/web_notify/__manifest__.py
index 4ee5bd93e540..46c130ff443e 100644
--- a/web_notify/__manifest__.py
+++ b/web_notify/__manifest__.py
@@ -6,13 +6,18 @@
"name": "Web Notify",
"summary": """
Send notification messages to user""",
- "version": "14.0.1.0.1",
+ "version": "15.0.1.0.0",
"license": "AGPL-3",
"author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)",
"development_status": "Production/Stable",
"website": "https://github.com/OCA/web",
"depends": ["web", "bus", "base"],
- "data": ["views/web_notify.xml"],
+ "data": [],
"demo": ["views/res_users_demo.xml"],
+ "assets": {
+ "web.assets_backend": [
+ "web_notify/static/src/js/services/web_notification_service.esm.js",
+ ],
+ },
"installable": True,
}
diff --git a/web_notify/models/res_users.py b/web_notify/models/res_users.py
index d973940eab42..201f1a66c3f1 100644
--- a/web_notify/models/res_users.py
+++ b/web_notify/models/res_users.py
@@ -2,7 +2,7 @@
# Copyright 2016 ACSONE SA/NV
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
-from odoo import _, api, exceptions, fields, models
+from odoo import _, exceptions, models
DEFAULT_MESSAGE = "Default message"
@@ -10,28 +10,11 @@
DANGER = "danger"
WARNING = "warning"
INFO = "info"
-DEFAULT = "default"
class ResUsers(models.Model):
_inherit = "res.users"
- @api.depends("create_date")
- def _compute_channel_names(self):
- for record in self:
- res_id = record.id
- record.notify_success_channel_name = "notify_success_%s" % res_id
- record.notify_danger_channel_name = "notify_danger_%s" % res_id
- record.notify_warning_channel_name = "notify_warning_%s" % res_id
- record.notify_info_channel_name = "notify_info_%s" % res_id
- record.notify_default_channel_name = "notify_default_%s" % res_id
-
- notify_success_channel_name = fields.Char(compute="_compute_channel_names")
- notify_danger_channel_name = fields.Char(compute="_compute_channel_names")
- notify_warning_channel_name = fields.Char(compute="_compute_channel_names")
- notify_info_channel_name = fields.Char(compute="_compute_channel_names")
- notify_default_channel_name = fields.Char(compute="_compute_channel_names")
-
def notify_success(self, message="Default message", title=None, sticky=False):
title = title or _("Success")
self._notify_channel(SUCCESS, message, title, sticky)
@@ -48,12 +31,8 @@ def notify_info(self, message="Default message", title=None, sticky=False):
title = title or _("Information")
self._notify_channel(INFO, message, title, sticky)
- def notify_default(self, message="Default message", title=None, sticky=False):
- title = title or _("Default")
- self._notify_channel(DEFAULT, message, title, sticky)
-
def _notify_channel(
- self, type_message=DEFAULT, message=DEFAULT_MESSAGE, title=None, sticky=False
+ self, type_message, message=DEFAULT_MESSAGE, title=None, sticky=False
):
# pylint: disable=protected-access
if not self.env.user._is_admin() and any(
@@ -62,12 +41,14 @@ def _notify_channel(
raise exceptions.UserError(
_("Sending a notification to another user is forbidden.")
)
- channel_name_field = "notify_{}_channel_name".format(type_message)
bus_message = {
"type": type_message,
"message": message,
"title": title,
"sticky": sticky,
}
- notifications = [(record[channel_name_field], bus_message) for record in self]
- self.env["bus.bus"].sendmany(notifications)
+ notifications = [
+ (self.partner_id, "web_notify_" + type_message, bus_message)
+ for record in self
+ ]
+ self.env["bus.bus"]._sendmany(notifications)
diff --git a/web_notify/static/src/js/services/web_notification_service.esm.js b/web_notify/static/src/js/services/web_notification_service.esm.js
new file mode 100644
index 000000000000..2d68fac42c43
--- /dev/null
+++ b/web_notify/static/src/js/services/web_notification_service.esm.js
@@ -0,0 +1,47 @@
+/** @odoo-module **/
+
+import {registry} from "@web/core/registry";
+
+export const webNotificationService = {
+ dependencies: ["notification"],
+
+ start(env, {notification}) {
+ const channel_success = "web_notify_success";
+ const channel_danger = "web_notify_danger";
+ const channel_warning = "web_notify_warning";
+ const channel_info = "web_notify_info";
+ const channel_default = "web_notify_default";
+ const all_channels = [
+ channel_success,
+ channel_danger,
+ channel_warning,
+ channel_info,
+ channel_default,
+ ];
+
+ function onMessage(message) {
+ return notification.add(message.message, {
+ type: message.type,
+ title: message.title,
+ sticky: message.sticky,
+ });
+ }
+
+ function onNotification(notifications) {
+ for (const {type, payload} of notifications) {
+ if (all_channels.indexOf(type) > -1) {
+ onMessage(payload);
+ }
+ }
+ }
+
+ env.bus.on("WEB_CLIENT_READY", null, async () => {
+ const legacyEnv = owl.Component.env;
+
+ legacyEnv.services.bus_service.startPolling();
+ legacyEnv.services.bus_service.onNotification(this, onNotification);
+ });
+ },
+};
+
+registry.category("services").add("webNotification", webNotificationService);
diff --git a/web_notify/static/src/js/web_client.js b/web_notify/static/src/js/web_client.js
deleted file mode 100644
index a576dcdd1a82..000000000000
--- a/web_notify/static/src/js/web_client.js
+++ /dev/null
@@ -1,61 +0,0 @@
-odoo.define("web_notify.WebClient", function (require) {
- "use strict";
-
- var WebClient = require("web.WebClient");
- var session = require("web.session");
- require("bus.BusService");
-
- WebClient.include({
- show_application: function () {
- var res = this._super();
- this.start_polling();
- return res;
- },
- start_polling: function () {
- this.channel_success = "notify_success_" + session.uid;
- this.channel_danger = "notify_danger_" + session.uid;
- this.channel_warning = "notify_warning_" + session.uid;
- this.channel_info = "notify_info_" + session.uid;
- this.channel_default = "notify_default_" + session.uid;
- this.all_channels = [
- this.channel_success,
- this.channel_danger,
- this.channel_warning,
- this.channel_info,
- this.channel_default,
- ];
- this.call("bus_service", "startPolling");
-
- if (this.call("bus_service", "isMasterTab")) {
- this.call("bus_service", "addChannel", this.channel_success);
- this.call("bus_service", "addChannel", this.channel_danger);
- this.call("bus_service", "addChannel", this.channel_warning);
- this.call("bus_service", "addChannel", this.channel_info);
- this.call("bus_service", "addChannel", this.channel_default);
- }
- this.call("bus_service", "on", "notification", this, this.bus_notification);
- },
- bus_notification: function (notifications) {
- var self = this;
- _.each(notifications, function (notification) {
- var channel = notification[0];
- var message = notification[1];
- if (
- self.all_channels !== null &&
- self.all_channels.indexOf(channel) > -1
- ) {
- self.on_message(message);
- }
- });
- },
- on_message: function (message) {
- return this.call("notification", "notify", {
- type: message.type,
- title: message.title,
- message: message.message,
- sticky: message.sticky,
- className: message.className,
- });
- },
- });
-});
diff --git a/web_notify/static/src/js/widgets/notification.js b/web_notify/static/src/js/widgets/notification.js
deleted file mode 100644
index 0c468ffb8db9..000000000000
--- a/web_notify/static/src/js/widgets/notification.js
+++ /dev/null
@@ -1,26 +0,0 @@
-odoo.define("web_notify.Notification", function (require) {
- "use strict";
-
- var Notification = require("web.Notification");
-
- Notification.include({
- icon_mapping: {
- success: "fa-thumbs-up",
- danger: "fa-exclamation-triangle",
- warning: "fa-exclamation",
- info: "fa-info",
- default: "fa-lightbulb-o",
- },
- init: function () {
- this._super.apply(this, arguments);
- // Delete default classes
- this.className = this.className.replace(" o_error", "");
- // Add custom icon and custom class
- this.icon =
- this.type in this.icon_mapping
- ? this.icon_mapping[this.type]
- : this.icon_mapping.default;
- this.className += " o_" + this.type;
- },
- });
-});
diff --git a/web_notify/static/src/scss/webclient.scss b/web_notify/static/src/scss/webclient.scss
deleted file mode 100644
index 82f3c1544bbe..000000000000
--- a/web_notify/static/src/scss/webclient.scss
+++ /dev/null
@@ -1,24 +0,0 @@
-.o_notification_manager {
- .o_notification {
- &.o_success {
- color: white;
- background-color: theme-color("success");
- }
- &.o_danger {
- color: white;
- background-color: theme-color("danger");
- }
- &.o_warning {
- color: white;
- background-color: theme-color("warning");
- }
- &.o_info {
- color: white;
- background-color: theme-color("info");
- }
- &.o_default {
- color: black;
- background-color: theme-color("default");
- }
- }
-}
diff --git a/web_notify/views/res_users_demo.xml b/web_notify/views/res_users_demo.xml
index 65bc72a03b6a..65424ed7dd20 100644
--- a/web_notify/views/res_users_demo.xml
+++ b/web_notify/views/res_users_demo.xml
@@ -42,14 +42,6 @@
class="oe_highlight"
/>
-
-
-
diff --git a/web_notify/views/web_notify.xml b/web_notify/views/web_notify.xml
deleted file mode 100644
index 70fca12cb980..000000000000
--- a/web_notify/views/web_notify.xml
+++ /dev/null
@@ -1,31 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-