Skip to content

Commit

Permalink
[MIG] web_notify: Migrated in v17
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikul-OSI committed Feb 14, 2024
1 parent edec7a1 commit 1e7ddfe
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 20 deletions.
7 changes: 7 additions & 0 deletions web_notify/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,21 @@ Contributors
------------

- Laurent Mignon <[email protected]>

- Serpent Consulting Services Pvt. Ltd.<[email protected]>

- Aitor Bouzas <[email protected]>

- Shepilov Vladislav <[email protected]>

- Kevin Khao <[email protected]>

- `Tecnativa <https://www.tecnativa.com>`__:

- David Vidal

- Nikul Chaudhary <[email protected]>

Maintainers
-----------

Expand Down
3 changes: 3 additions & 0 deletions web_notify/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[build-system]
requires = ["whool"]
build-backend = "whool.buildapi"
9 changes: 9 additions & 0 deletions web_notify/readme/CONTRIBUTORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
- Laurent Mignon \<<[email protected]>\>
- Serpent Consulting Services Pvt. Ltd.\<<[email protected]>\>
- Aitor Bouzas \<<[email protected]>\>
- Shepilov Vladislav \<<[email protected]>\>
- Kevin Khao \<<[email protected]>\>
- [Tecnativa](https://www.tecnativa.com):
- David Vidal

- Nikul Chaudhary \<<[email protected]>\>
11 changes: 11 additions & 0 deletions web_notify/readme/DESCRIPTION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Send instant notification messages to the user in live.

This technical module allows you to send instant notification messages
from the server to the user in live. Two kinds of notification are
supported.

- Success: Displayed in a success theme color flying popup div
- Danger: Displayed in a danger theme color flying popup div
- Warning: Displayed in a warning theme color flying popup div
- Information: Displayed in a info theme color flying popup div
- Default: Displayed in a default theme color flying popup div
2 changes: 2 additions & 0 deletions web_notify/readme/INSTALL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
This module is based on the Instant Messaging Bus. To work properly, the
server must be launched in gevent mode.
39 changes: 39 additions & 0 deletions web_notify/readme/USAGE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
To send a notification to the user you just need to call one of the new
methods defined on res.users:

``` python
self.env.user.notify_success(message='My success message')
```

or

``` python
self.env.user.notify_danger(message='My danger message')
```

or

``` python
self.env.user.notify_warning(message='My warning message')
```

or

``` python
self.env.user.notify_info(message='My information message')
```

or

``` python
self.env.user.notify_default(message='My default message')
```

![](static/description/notifications_screenshot.gif)

You can test the behaviour of the notifications by installing this
module in a demo database. Access the users form through Settings -\>
Users & Companies. You'll see a tab called "Test web notify", here
you'll find two buttons that'll allow you test the module.

![](static/description/test_notifications_demo.png)
1 change: 1 addition & 0 deletions web_notify/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@ <h2><a class="toc-backref" href="#toc-entry-6">Contributors</a></h2>
<li>David Vidal</li>
</ul>
</li>
<li>Nikul Chaudhary &lt;<a class="reference external" href="mailto:nchaudhary&#64;opensourceintegrators.com">nchaudhary&#64;opensourceintegrators.com</a>&gt;</li>
</ul>
</div>
<div class="section" id="maintainers">
Expand Down
4 changes: 2 additions & 2 deletions web_notify/static/src/js/services/notification.esm.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
/** @odoo-module */
import {Notification} from "@web/core/notifications/notification";
import {patch} from "web.utils";
import {patch} from "@web/core/utils/patch";

patch(Notification.props, "webNotifyProps", {
patch(Notification.props, {
type: {
type: String,
optional: true,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/** @odoo-module **/
import {Markup} from "web.utils";

import {markup} from "@odoo/owl";
import {browser} from "@web/core/browser/browser";
import {registry} from "@web/core/registry";

Expand All @@ -20,7 +21,7 @@ export const webNotificationService = {

notifications.forEach(function (notif) {
browser.setTimeout(function () {
notification.add(Markup(notif.message), {
notification.add(markup(notif.message), {
title: notif.title,
type: notif.type,
sticky: notif.sticky,
Expand Down
8 changes: 7 additions & 1 deletion web_notify/tests/test_res_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

import json

from odoo import exceptions
from odoo import SUPERUSER_ID, exceptions
from odoo.tests import common

from ..models.res_users import DANGER, DEFAULT, INFO, SUCCESS, WARNING
Expand Down Expand Up @@ -84,6 +84,12 @@ def test_notify_other_user(self):
with self.assertRaises(exceptions.UserError):
other_user_model.browse(self.env.uid).notify_info(message="hello")

def test_notify_sudo_user(self):
other_user = self.env.ref("base.user_demo")
other_user_model = self.env["res.users"].with_user(other_user)
with self.assertRaises(exceptions.UserError):
other_user_model.browse(SUPERUSER_ID).notify_info(message="hello")

def test_notify_admin_allowed_other_user(self):
other_user = self.env.ref("base.user_demo")
other_user.notify_info(message="hello")
30 changes: 15 additions & 15 deletions web_notify/views/res_users_demo.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,52 +9,52 @@
<field name="arch" type="xml">
<xpath expr="//notebook/page[1]" position="after">
<page string="Test web notify" name="test_web_notify">
<group>
<group>
<button
<group>
<button
name="notify_success"
type="object"
string="Test success notification"
class="oe_highlight"
/>
</group>
<group>
<button
</group>
<group>
<button
name="notify_danger"
type="object"
string="Test danger notification"
class="oe_highlight"
/>
</group>
</group>
</group>
<group>
<group>
<button
<group>
<button
name="notify_warning"
type="object"
string="Test warning notification"
class="oe_highlight"
/>
</group>
<group>
<button
</group>
<group>
<button
name="notify_info"
type="object"
string="Test info notification"
class="oe_highlight"
/>
</group>
</group>
</group>
<group>
<group>
<button
<group>
<button
name="notify_default"
type="object"
string="Test default notification"
class="oe_highlight"
/>
</group>
</group>
</group>
</page>
</xpath>
</field>
Expand Down

0 comments on commit 1e7ddfe

Please sign in to comment.