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.

91 lines
3.4 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_type': 'form',
  34. 'view_mode': 'form,tree,kanban',
  35. 'views': [[False, 'form']], # Beurk, but needed
  36. 'target': 'new',
  37. 'res_id': partner_res[0],
  38. }
  39. else:
  40. action = {
  41. 'name': 'No Partner Found',
  42. 'type': 'ir.actions.act_window',
  43. 'res_model': 'wizard.open.calling.partner',
  44. 'view_type': 'form',
  45. 'view_mode': 'form',
  46. 'views': [[False, 'form']], # Beurk, but needed
  47. 'target': 'new',
  48. 'context': {'incall_number_popup': number}
  49. }
  50. return action
  51. def incall_notify_by_login(
  52. self, cr, uid, number, login_list, context=None):
  53. assert isinstance(login_list, list), 'login_list must be a list'
  54. res = self.get_partner_from_phone_number(
  55. cr, uid, number, context=context)
  56. user_ids = self.pool['res.users'].search(
  57. cr, uid, [('login', 'in', login_list)], context=context)
  58. logger.debug(
  59. 'Notify incoming call from number %s to users %s'
  60. % (number, user_ids))
  61. action = self._prepare_incall_pop_action(
  62. cr, uid, res, number, context=context)
  63. if action:
  64. users = self.pool['res.users'].read(
  65. cr, uid, user_ids, ['context_incall_popup'], context=context)
  66. for user in users:
  67. if user['context_incall_popup']:
  68. self.pool['action.request'].notify(
  69. cr, uid, to_id=user['id'], **action)
  70. logger.debug(
  71. 'This action has been sent to user ID %d: %s'
  72. % (user['id'], action))
  73. return res
  74. class res_users(orm.Model):
  75. _inherit = 'res.users'
  76. _columns = {
  77. 'context_incall_popup': fields.boolean('Pop-up on Incoming Calls'),
  78. }
  79. _defaults = {
  80. 'context_incall_popup': True,
  81. }