You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.9 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2016 ACSONE SA/NV
  3. # Copyright 2018 Camptocamp
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, fields, models, _
  6. from odoo.addons.web.controllers.main import clean_action
  7. class ResUsers(models.Model):
  8. _inherit = 'res.users'
  9. @api.multi
  10. @api.depends('create_date')
  11. def _compute_channel_names(self):
  12. for record in self:
  13. res_id = record.id
  14. record.notify_info_channel_name = 'notify_info_%s' % res_id
  15. record.notify_warning_channel_name = 'notify_warning_%s' % res_id
  16. notify_info_channel_name = fields.Char(
  17. compute='_compute_channel_names')
  18. notify_warning_channel_name = fields.Char(
  19. compute='_compute_channel_names')
  20. @api.multi
  21. def notify_info(self, message, title=None, sticky=False,
  22. show_reload=False, action=None):
  23. title = title or _('Information')
  24. self._notify_channel(
  25. 'notify_info_channel_name', message, title,
  26. sticky, show_reload, action)
  27. @api.multi
  28. def notify_warning(self, message, title=None, sticky=False,
  29. show_reload=False, action=None):
  30. title = title or _('Warning')
  31. self._notify_channel(
  32. 'notify_warning_channel_name', message, title,
  33. sticky, show_reload, action)
  34. @api.multi
  35. def _notify_channel(self, channel_name_field, message, title, sticky,
  36. show_reload, action):
  37. if action:
  38. action = clean_action(action)
  39. bus_message = {
  40. 'message': message,
  41. 'title': title,
  42. 'sticky': sticky,
  43. 'show_reload': show_reload,
  44. 'action': action,
  45. }
  46. notifications = [(getattr(record, channel_name_field), bus_message)
  47. for record in self]
  48. self.env['bus.bus'].sendmany(notifications)