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.

59 lines
2.6 KiB

  1. ###################################################################################
  2. #
  3. # Copyright (c) 2017-2019 MuK IT GmbH.
  4. #
  5. # This file is part of MuK Web Refresh
  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, fields
  24. _logger = logging.getLogger(__name__)
  25. class Base(models.AbstractModel):
  26. _inherit = 'base'
  27. @api.multi
  28. def refresh_views(self, model=None, ids=None, user=None, create=False):
  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 model: The model of the records is used to find the
  37. corresponding views
  38. :param ids: IDs of the records are used to determine which
  39. records have been updated
  40. :param user: The user (res.users) is used to determine whether
  41. the current one has caused the refresh
  42. :param create: Indicates whether the record has been newly
  43. created or updated
  44. """
  45. if self.exists() or ids:
  46. record = next(iter(self)) if len(self) > 1 else self
  47. self.env['bus.bus'].sendone('refresh', {
  48. 'create': create if ids else record.exists() and record.create_date == record.write_date or False,
  49. 'model': model or self._name,
  50. 'uid': user and user.id or False if ids else self.env.user.id,
  51. 'ids': ids or self.mapped('id')})