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.

46 lines
1.5 KiB

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