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.

61 lines
2.6 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (C) 2017 MuK IT GmbH
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU Affero General Public License as
  7. # published by the Free Software Foundation, either version 3 of the
  8. # License, or (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU Affero General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU Affero General Public License
  16. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. #
  18. ###################################################################################
  19. import logging
  20. from odoo import _, api, models
  21. _logger = logging.getLogger(__name__)
  22. class ResUsers(models.Model):
  23. _inherit = 'res.users'
  24. @api.multi
  25. def notify(self, **params):
  26. """ Informs the web client to refresh the views that belong to the
  27. corresponding model by sending a message to the bus.
  28. There are two ways to use this method. First by calling it
  29. without any parameters. In this case, the views are determined
  30. and updated using the current records in self. Alternatively,
  31. the method can also be called with corresponding parameters
  32. to explicitly update a view from another model.
  33. :param title: The notification title
  34. :param message: The notification main message
  35. :param type: Either 'notification' or 'warning'
  36. :param sticky: Determines if the notification is sticky
  37. :param buttons: List of buttons, which consists of:
  38. text: The buttons text
  39. primary: Determines if the button is primary
  40. icon: The buttons font-awsome className or image src
  41. action: Either an action id, a descriptor or False to
  42. just to close the notification on the button click
  43. """
  44. params.update({'user_ids': self.ids})
  45. self.env['bus.bus'].sendone('notify', params)
  46. @api.multi
  47. def notify_info(self, message, title=None, sticky=False):
  48. self.notify(type='info', title=title or _('Information'), message=message, sticky=sticky)
  49. @api.multi
  50. def notify_warning(self, message, title=None, sticky=False):
  51. self.notify(type='warning', title=title or _('Warning'), message=message, sticky=sticky)