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.2 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. import logging
  7. logger = logging.getLogger(__name__)
  8. class PhoneCommon(models.AbstractModel):
  9. _inherit = 'phone.common'
  10. @api.model
  11. def _prepare_incall_pop_action(self, record_res, number):
  12. action = False
  13. if record_res:
  14. obj = self.env[record_res[0]]
  15. action = {
  16. 'name': obj._description,
  17. 'type': 'ir.actions.act_window',
  18. 'res_model': record_res[0],
  19. 'view_mode': 'form,tree',
  20. 'views': [[False, 'form']],
  21. 'res_id': record_res[1],
  22. }
  23. else:
  24. action = {
  25. 'name': _('Number Not Found'),
  26. 'type': 'ir.actions.act_window',
  27. 'res_model': 'number.not.found',
  28. 'view_mode': 'form',
  29. 'views': [[False, 'form']],
  30. 'target': 'new',
  31. 'context': {'default_calling_number': number}
  32. }
  33. return action
  34. @api.model
  35. def incall_notify_by_login(self, number, login_list):
  36. assert isinstance(login_list, list), 'login_list must be a list'
  37. res = self.get_record_from_phone_number(number)
  38. users = self.env['res.users'].search(
  39. [('login', 'in', login_list)])
  40. logger.info(
  41. 'Notify incoming call from number %s to users IDs %s'
  42. % (number, users.ids))
  43. action = self._prepare_incall_pop_action(res, number)
  44. if action:
  45. title = _('Incoming call')
  46. message = _('Call from %s') % number
  47. action_link_name = res and res[2] or action['name']
  48. users.notify_info(
  49. message, title=title, sticky=True, action=action,
  50. action_link_name=action_link_name)
  51. logger.debug(
  52. 'This action has been sent to users IDs %s: %s'
  53. % (users.ids, action))
  54. if res:
  55. callerid = res[2]
  56. else:
  57. callerid = False
  58. return callerid