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.

73 lines
2.5 KiB

  1. # -*- coding: utf-8 -*-
  2. # Copyright 2014-2018 Akretion France
  3. # @author: Alexis de Lattre <alexis.delattre@akretion.com>
  4. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  5. from odoo import api, models, _
  6. from odoo.addons.web.controllers.main import clean_action
  7. import logging
  8. logger = logging.getLogger(__name__)
  9. class PhoneCommon(models.AbstractModel):
  10. _inherit = 'phone.common'
  11. @api.model
  12. def _prepare_incall_pop_action(self, record_res, number):
  13. action = False
  14. if record_res:
  15. obj = self.env[record_res[0]]
  16. action = {
  17. 'name': obj._description,
  18. 'type': 'ir.actions.act_window',
  19. 'res_model': record_res[0],
  20. 'view_mode': 'form,tree',
  21. 'views': [[False, 'form']],
  22. # 'target': 'new',
  23. 'res_id': record_res[1],
  24. }
  25. else:
  26. action = {
  27. 'name': _('Number Not Found'),
  28. 'type': 'ir.actions.act_window',
  29. 'res_model': 'number.not.found',
  30. 'view_mode': 'form',
  31. 'views': [[False, 'form']],
  32. # 'target': 'new',
  33. 'context': {'default_calling_number': number}
  34. }
  35. return action
  36. @api.model
  37. def incall_notify_by_login(self, number, login_list):
  38. assert isinstance(login_list, list), 'login_list must be a list'
  39. res = self.get_record_from_phone_number(number)
  40. users = self.env['res.users'].search(
  41. [('login', 'in', login_list)])
  42. logger.info(
  43. 'Notify incoming call from number %s to user IDs %s'
  44. % (number, users.ids))
  45. action = self._prepare_incall_pop_action(res, number)
  46. action = clean_action(action)
  47. if action:
  48. for user in users:
  49. channel = 'notify_info_%s' % user.id
  50. bus_message = {
  51. 'message': _('Here is my message'),
  52. 'title': _('Incoming call'),
  53. 'action': action,
  54. # 'sticky': True,
  55. 'action_link_name': 'action_link_name',
  56. }
  57. self.sudo().env['bus.bus'].sendone(
  58. channel, bus_message)
  59. logger.debug(
  60. 'This action has been sent to user ID %d: %s'
  61. % (user.id, action))
  62. if res:
  63. callerid = res[2]
  64. else:
  65. callerid = False
  66. return callerid