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.

69 lines
2.3 KiB

  1. # -*- coding: utf-8 -*-
  2. # © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
  3. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  4. from openerp import models, fields, api, _
  5. import logging
  6. logger = logging.getLogger(__name__)
  7. class PhoneCommon(models.AbstractModel):
  8. _inherit = 'phone.common'
  9. @api.model
  10. def _prepare_incall_pop_action(self, record_res, number):
  11. action = False
  12. if record_res:
  13. obj = self.env[record_res[0]]
  14. action = {
  15. 'name': obj._description,
  16. 'type': 'ir.actions.act_window',
  17. 'res_model': record_res[0],
  18. 'view_mode': 'form,tree',
  19. 'views': [[False, 'form']], # Beurk, but needed
  20. 'target': 'new',
  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']], # Beurk, but needed
  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.debug(
  41. 'Notify incoming call from number %s to users %s'
  42. % (number, users.ids))
  43. action = self._prepare_incall_pop_action(res, number)
  44. if action:
  45. for user in users:
  46. if user.context_incall_popup:
  47. self.sudo(user.id).env['action.request'].notify(action)
  48. logger.debug(
  49. 'This action has been sent to user ID %d: %s'
  50. % (user.id, action))
  51. if res:
  52. callerid = res[2]
  53. else:
  54. callerid = False
  55. return callerid
  56. class ResUsers(models.Model):
  57. _inherit = 'res.users'
  58. context_incall_popup = fields.Boolean(
  59. string='Pop-up on Incoming Calls', default=True)