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.

89 lines
3.3 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Asterisk Pop-up module for OpenERP
  5. # Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr>
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU Affero General Public License as
  9. # published by the Free Software Foundation, either version 3 of the
  10. # License, or (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU Affero General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU Affero General Public License
  18. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. #
  20. ##############################################################################
  21. from openerp.osv import orm, fields
  22. import logging
  23. logger = logging.getLogger(__name__)
  24. class res_partner(orm.Model):
  25. _inherit = 'res.partner'
  26. def _prepare_incall_pop_action(
  27. self, cr, uid, partner_res, number, context=None):
  28. if partner_res:
  29. action = {
  30. 'name': 'Partner',
  31. 'type': 'ir.actions.act_window',
  32. 'res_model': 'res.partner',
  33. 'view_mode': 'form,tree,kanban',
  34. 'views': [[False, 'form']], # Beurk, but needed
  35. 'target': 'new',
  36. 'res_id': partner_res[0],
  37. }
  38. else:
  39. action = {
  40. 'name': 'No Partner Found',
  41. 'type': 'ir.actions.act_window',
  42. 'res_model': 'wizard.open.calling.partner',
  43. 'view_mode': 'form',
  44. 'views': [[False, 'form']], # Beurk, but needed
  45. 'target': 'new',
  46. 'context': {'incall_number_popup': number}
  47. }
  48. return action
  49. def incall_notify_by_login(
  50. self, cr, uid, number, login_list, context=None):
  51. assert isinstance(login_list, list), 'login_list must be a list'
  52. res = self.get_partner_from_phone_number(
  53. cr, uid, number, context=context)
  54. user_ids = self.pool['res.users'].search(
  55. cr, uid, [('login', 'in', login_list)], context=context)
  56. logger.debug(
  57. 'Notify incoming call from number %s to users %s'
  58. % (number, user_ids))
  59. action = self._prepare_incall_pop_action(
  60. cr, uid, res, number, context=context)
  61. if action:
  62. users = self.pool['res.users'].read(
  63. cr, uid, user_ids, ['context_incall_popup'], context=context)
  64. for user in users:
  65. if user['context_incall_popup']:
  66. self.pool['action.request'].notify(
  67. cr, uid, to_id=user['id'], **action)
  68. logger.debug(
  69. 'This action has been sent to user ID %d: %s'
  70. % (user['id'], action))
  71. return res
  72. class res_users(orm.Model):
  73. _inherit = 'res.users'
  74. _columns = {
  75. 'context_incall_popup': fields.boolean('Pop-up on Incoming Calls'),
  76. }
  77. _defaults = {
  78. 'context_incall_popup': True,
  79. }