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.

56 lines
2.6 KiB

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