Skip to content

Commit 05490c9

Browse files
committed
Add a sticky notification in the webclient
1 parent 2eafb6a commit 05490c9

File tree

4 files changed

+57
-9
lines changed

4 files changed

+57
-9
lines changed

base_notification/__init__.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
1-
# from . import models
1+
from . import models
2+
23
# from .hooks import post_init_hook

base_notification/__manifest__.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
"version": "16.0.1.0.0",
66
"author": "Kencove, Odoo Community Association (OCA)",
77
"website": "https://github.com/OCA/server-tools",
8-
# "category": "Tools",
8+
"category": "Tools",
99
"license": "LGPL-3",
10-
# "depends": ["base", "mail"],
11-
# "data": [
12-
# "security/ir.model.access.csv",
13-
# "data/base_notification_data.xml",
14-
# "views/base_notification_rule_views.xml",
15-
# ],
10+
"depends": ["base", "mail"],
11+
"data": [
12+
"security/ir.model.access.csv",
13+
"data/base_notification_data.xml",
14+
"views/base_notification_rule_views.xml",
15+
],
16+
"assets": {
17+
"web.assets_backend": [
18+
"base_notification/static/src/js/base_notification_service.esm.js",
19+
],
20+
},
1621
# "post_init_hook": "post_init_hook",
1722
# "installable": True,
1823
# "application": False,

base_notification/models/base_notification_rule.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import logging
22

3-
from odoo import fields, models
3+
from odoo import _, api, fields, models
44
from odoo.tools.safe_eval import safe_eval
55

66
_logger = logging.getLogger(__name__)
@@ -41,6 +41,15 @@ class BaseNotificationRule(models.Model):
4141
partner_ids = fields.Many2many("res.partner", string="Recipients")
4242
template_id = fields.Many2one("mail.template", string="Mail Template")
4343

44+
@api.model
45+
def notify_changes(self, partner_recs):
46+
# send notification to partner_ids
47+
channel = "base_notification_updates"
48+
for partner_id in partner_recs:
49+
self.env["bus.bus"]._sendone(
50+
partner_id, channel, {"message": _("base_notification updated")}
51+
)
52+
4453
def _execute_notification(self, records):
4554
"""Send the configured notification."""
4655
if not self.active or not records:
@@ -66,6 +75,7 @@ def _execute_notification(self, records):
6675
body=f"🔔 Notification: {self.name}",
6776
partner_ids=self.partner_ids.ids,
6877
)
78+
self.notify_changes(self.partner_ids)
6979

7080
def _apply_trigger(self, event_type, records):
7181
"""Called by create/write/unlink hooks."""
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/** @odoo-module **/
2+
/* Copyright 2025 Kencove - Mohamed Alkobrosli
3+
* License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). */
4+
5+
import {registry} from "@web/core/registry";
6+
7+
export const watchBaseNotificationsService = {
8+
dependencies: ["bus_service", "notification"],
9+
async start(env, {bus_service, notification}) {
10+
bus_service.addEventListener("notification", ({detail: notifications}) => {
11+
for (const notif of notifications) {
12+
if (notif.type === "base_notification_updates") {
13+
const message =
14+
notif.payload && notif.payload.message
15+
? notif.payload.message
16+
: notif.payload;
17+
notification.add(message, {
18+
title: env._t("Base Notification"),
19+
type: "info",
20+
sticky: true,
21+
});
22+
}
23+
}
24+
});
25+
await bus_service.addChannel("base_notification_updates");
26+
await bus_service.start();
27+
},
28+
};
29+
30+
registry
31+
.category("services")
32+
.add("watchBaseNotifications", watchBaseNotificationsService);

0 commit comments

Comments
 (0)