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.

64 lines
2.7 KiB

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