Add possibility to return an action in a notification

This commit is contained in:
Guewen Baconnier
2018-06-27 15:52:14 +02:00
committed by trisdoan
parent aa5d0a6785
commit b61c8b8256
5 changed files with 126 additions and 22 deletions

View File

@@ -3,6 +3,7 @@
from odoo import _, api, exceptions, fields, models
from odoo.addons.bus.models.bus import channel_with_db, json_dump
from odoo.addons.web.controllers.main import clean_action
DEFAULT_MESSAGE = "Default message"
@@ -42,34 +43,59 @@ class ResUsers(models.Model):
notify_default_channel_name = fields.Char(compute="_compute_channel_names")
def notify_success(
self, message="Default message", title=None, sticky=False, target=None
self,
message="Default message",
title=None,
sticky=False,
target=None,
action=None,
):
title = title or _("Success")
self._notify_channel(SUCCESS, message, title, sticky, target)
self._notify_channel(SUCCESS, message, title, sticky, target, action)
def notify_danger(
self, message="Default message", title=None, sticky=False, target=None
self,
message="Default message",
title=None,
sticky=False,
target=None,
action=None,
):
title = title or _("Danger")
self._notify_channel(DANGER, message, title, sticky, target)
self._notify_channel(DANGER, message, title, sticky, target, action)
def notify_warning(
self, message="Default message", title=None, sticky=False, target=None
self,
message="Default message",
title=None,
sticky=False,
target=None,
action=None,
):
title = title or _("Warning")
self._notify_channel(WARNING, message, title, sticky, target)
self._notify_channel(WARNING, message, title, sticky, target, action)
def notify_info(
self, message="Default message", title=None, sticky=False, target=None
self,
message="Default message",
title=None,
sticky=False,
target=None,
action=None,
):
title = title or _("Information")
self._notify_channel(INFO, message, title, sticky, target)
self._notify_channel(INFO, message, title, sticky, target, action)
def notify_default(
self, message="Default message", title=None, sticky=False, target=None
self,
message="Default message",
title=None,
sticky=False,
target=None,
action=None,
):
title = title or _("Default")
self._notify_channel(DEFAULT, message, title, sticky, target)
self._notify_channel(DEFAULT, message, title, sticky, target, action)
def _notify_channel(
self,
@@ -78,6 +104,7 @@ class ResUsers(models.Model):
title=None,
sticky=False,
target=None,
action=None,
):
if not self.env.user._is_admin() and any(
user.id != self.env.uid for user in self
@@ -87,11 +114,14 @@ class ResUsers(models.Model):
)
if not target:
target = self.partner_id
if action:
action = clean_action(action, self.env)
bus_message = {
"type": type_message,
"message": message,
"title": title,
"sticky": sticky,
"action": action,
}
notifications = [[partner, "web.notify", [bus_message]] for partner in target]