mirror of https://github.com/OCA/web.git
[REF] web_notify: Black python code
parent
d4f6c3ad50
commit
09a0fc41a4
|
@ -3,25 +3,15 @@
|
||||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
{
|
{
|
||||||
'name': 'Web Notify',
|
"name": "Web Notify",
|
||||||
'summary': """
|
"summary": """
|
||||||
Send notification messages to user""",
|
Send notification messages to user""",
|
||||||
'version': '12.0.1.0.0',
|
"version": "12.0.1.0.0",
|
||||||
'license': 'AGPL-3',
|
"license": "AGPL-3",
|
||||||
'author': 'ACSONE SA/NV,'
|
"author": "ACSONE SA/NV," "AdaptiveCity," "Odoo Community Association (OCA)",
|
||||||
'AdaptiveCity,'
|
"website": "https://github.com/OCA/web",
|
||||||
'Odoo Community Association (OCA)',
|
"depends": ["web", "bus", "base"],
|
||||||
'website': 'https://github.com/OCA/web',
|
"data": ["views/web_notify.xml"],
|
||||||
'depends': [
|
"demo": ["views/res_users_demo.xml"],
|
||||||
'web',
|
"installable": True,
|
||||||
'bus',
|
|
||||||
'base',
|
|
||||||
],
|
|
||||||
'data': [
|
|
||||||
'views/web_notify.xml'
|
|
||||||
],
|
|
||||||
'demo': [
|
|
||||||
'views/res_users_demo.xml'
|
|
||||||
],
|
|
||||||
'installable': True,
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,21 +32,15 @@ class ResUsers(models.Model):
|
||||||
notify_info_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")
|
notify_default_channel_name = fields.Char(compute="_compute_channel_names")
|
||||||
|
|
||||||
def notify_success(
|
def notify_success(self, message="Default message", title=None, sticky=False):
|
||||||
self, message="Default message", title=None, sticky=False
|
|
||||||
):
|
|
||||||
title = title or _("Success")
|
title = title or _("Success")
|
||||||
self._notify_channel(SUCCESS, message, title, sticky)
|
self._notify_channel(SUCCESS, message, title, sticky)
|
||||||
|
|
||||||
def notify_danger(
|
def notify_danger(self, message="Default message", title=None, sticky=False):
|
||||||
self, message="Default message", title=None, sticky=False
|
|
||||||
):
|
|
||||||
title = title or _("Danger")
|
title = title or _("Danger")
|
||||||
self._notify_channel(DANGER, message, title, sticky)
|
self._notify_channel(DANGER, message, title, sticky)
|
||||||
|
|
||||||
def notify_warning(
|
def notify_warning(self, message="Default message", title=None, sticky=False):
|
||||||
self, message="Default message", title=None, sticky=False
|
|
||||||
):
|
|
||||||
title = title or _("Warning")
|
title = title or _("Warning")
|
||||||
self._notify_channel(WARNING, message, title, sticky)
|
self._notify_channel(WARNING, message, title, sticky)
|
||||||
|
|
||||||
|
@ -54,18 +48,12 @@ class ResUsers(models.Model):
|
||||||
title = title or _("Information")
|
title = title or _("Information")
|
||||||
self._notify_channel(INFO, message, title, sticky)
|
self._notify_channel(INFO, message, title, sticky)
|
||||||
|
|
||||||
def notify_default(
|
def notify_default(self, message="Default message", title=None, sticky=False):
|
||||||
self, message="Default message", title=None, sticky=False
|
|
||||||
):
|
|
||||||
title = title or _("Default")
|
title = title or _("Default")
|
||||||
self._notify_channel(DEFAULT, message, title, sticky)
|
self._notify_channel(DEFAULT, message, title, sticky)
|
||||||
|
|
||||||
def _notify_channel(
|
def _notify_channel(
|
||||||
self,
|
self, type_message=DEFAULT, message=DEFAULT_MESSAGE, title=None, sticky=False
|
||||||
type_message=DEFAULT,
|
|
||||||
message=DEFAULT_MESSAGE,
|
|
||||||
title=None,
|
|
||||||
sticky=False,
|
|
||||||
):
|
):
|
||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
if not self.env.user._is_admin() and any(
|
if not self.env.user._is_admin() and any(
|
||||||
|
@ -81,7 +69,5 @@ class ResUsers(models.Model):
|
||||||
"title": title,
|
"title": title,
|
||||||
"sticky": sticky,
|
"sticky": sticky,
|
||||||
}
|
}
|
||||||
notifications = [
|
notifications = [(record[channel_name_field], bus_message) for record in self]
|
||||||
(record[channel_name_field], bus_message) for record in self
|
|
||||||
]
|
|
||||||
self.env["bus.bus"].sendmany(notifications)
|
self.env["bus.bus"].sendmany(notifications)
|
||||||
|
|
|
@ -4,21 +4,20 @@
|
||||||
import json
|
import json
|
||||||
|
|
||||||
import mock
|
import mock
|
||||||
|
|
||||||
from odoo import exceptions
|
from odoo import exceptions
|
||||||
from odoo.addons.bus.models.bus import json_dump
|
|
||||||
from ..models.res_users import SUCCESS, DANGER, WARNING, INFO, DEFAULT
|
|
||||||
from odoo.tests import common
|
from odoo.tests import common
|
||||||
|
|
||||||
|
from odoo.addons.bus.models.bus import json_dump
|
||||||
|
|
||||||
|
from ..models.res_users import DANGER, DEFAULT, INFO, SUCCESS, WARNING
|
||||||
|
|
||||||
|
|
||||||
class TestResUsers(common.TransactionCase):
|
class TestResUsers(common.TransactionCase):
|
||||||
def test_notify_success(self):
|
def test_notify_success(self):
|
||||||
bus_bus = self.env["bus.bus"]
|
bus_bus = self.env["bus.bus"]
|
||||||
domain = [
|
domain = [
|
||||||
(
|
("channel", "=", json_dump(self.env.user.notify_success_channel_name))
|
||||||
"channel",
|
|
||||||
"=",
|
|
||||||
json_dump(self.env.user.notify_success_channel_name),
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
existing = bus_bus.search(domain)
|
existing = bus_bus.search(domain)
|
||||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||||
|
@ -30,13 +29,7 @@ class TestResUsers(common.TransactionCase):
|
||||||
|
|
||||||
def test_notify_danger(self):
|
def test_notify_danger(self):
|
||||||
bus_bus = self.env["bus.bus"]
|
bus_bus = self.env["bus.bus"]
|
||||||
domain = [
|
domain = [("channel", "=", json_dump(self.env.user.notify_danger_channel_name))]
|
||||||
(
|
|
||||||
"channel",
|
|
||||||
"=",
|
|
||||||
json_dump(self.env.user.notify_danger_channel_name),
|
|
||||||
)
|
|
||||||
]
|
|
||||||
existing = bus_bus.search(domain)
|
existing = bus_bus.search(domain)
|
||||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||||
self.env.user.notify_danger(**test_msg)
|
self.env.user.notify_danger(**test_msg)
|
||||||
|
@ -48,11 +41,7 @@ class TestResUsers(common.TransactionCase):
|
||||||
def test_notify_warning(self):
|
def test_notify_warning(self):
|
||||||
bus_bus = self.env["bus.bus"]
|
bus_bus = self.env["bus.bus"]
|
||||||
domain = [
|
domain = [
|
||||||
(
|
("channel", "=", json_dump(self.env.user.notify_warning_channel_name))
|
||||||
"channel",
|
|
||||||
"=",
|
|
||||||
json_dump(self.env.user.notify_warning_channel_name),
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
existing = bus_bus.search(domain)
|
existing = bus_bus.search(domain)
|
||||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||||
|
@ -64,9 +53,7 @@ class TestResUsers(common.TransactionCase):
|
||||||
|
|
||||||
def test_notify_info(self):
|
def test_notify_info(self):
|
||||||
bus_bus = self.env["bus.bus"]
|
bus_bus = self.env["bus.bus"]
|
||||||
domain = [
|
domain = [("channel", "=", json_dump(self.env.user.notify_info_channel_name))]
|
||||||
("channel", "=", json_dump(self.env.user.notify_info_channel_name))
|
|
||||||
]
|
|
||||||
existing = bus_bus.search(domain)
|
existing = bus_bus.search(domain)
|
||||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||||
self.env.user.notify_info(**test_msg)
|
self.env.user.notify_info(**test_msg)
|
||||||
|
@ -78,11 +65,7 @@ class TestResUsers(common.TransactionCase):
|
||||||
def test_notify_default(self):
|
def test_notify_default(self):
|
||||||
bus_bus = self.env["bus.bus"]
|
bus_bus = self.env["bus.bus"]
|
||||||
domain = [
|
domain = [
|
||||||
(
|
("channel", "=", json_dump(self.env.user.notify_default_channel_name))
|
||||||
"channel",
|
|
||||||
"=",
|
|
||||||
json_dump(self.env.user.notify_default_channel_name),
|
|
||||||
)
|
|
||||||
]
|
]
|
||||||
existing = bus_bus.search(domain)
|
existing = bus_bus.search(domain)
|
||||||
test_msg = {"message": "message", "title": "title", "sticky": True}
|
test_msg = {"message": "message", "title": "title", "sticky": True}
|
||||||
|
@ -95,9 +78,7 @@ class TestResUsers(common.TransactionCase):
|
||||||
def test_notify_many(self):
|
def test_notify_many(self):
|
||||||
# check that the notification of a list of users is done with
|
# check that the notification of a list of users is done with
|
||||||
# a single call to the bus
|
# a single call to the bus
|
||||||
with mock.patch(
|
with mock.patch("odoo.addons.bus.models.bus.ImBus.sendmany") as mockedSendMany:
|
||||||
"odoo.addons.bus.models.bus.ImBus.sendmany"
|
|
||||||
) as mockedSendMany:
|
|
||||||
users = self.env.user.search([(1, "=", 1)])
|
users = self.env.user.search([(1, "=", 1)])
|
||||||
self.assertTrue(len(users) > 1)
|
self.assertTrue(len(users) > 1)
|
||||||
users.notify_warning(message="message")
|
users.notify_warning(message="message")
|
||||||
|
|
Loading…
Reference in New Issue