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.

45 lines
1.4 KiB

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