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.

97 lines
3.5 KiB

  1. # -*- coding: utf-8 -*-
  2. ##############################################################################
  3. #
  4. # Base Phone Pop-up module for Odoo/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. from openerp.tools.translate import _
  23. import logging
  24. logger = logging.getLogger(__name__)
  25. class phone_common(orm.AbstractModel):
  26. _inherit = 'phone.common'
  27. def _prepare_incall_pop_action(
  28. self, cr, uid, record_res, number, context=None):
  29. action = False
  30. if record_res:
  31. obj = self.pool[record_res[0]]
  32. action = {
  33. 'name': obj._description,
  34. 'type': 'ir.actions.act_window',
  35. 'res_model': record_res[0],
  36. 'view_mode': 'form,tree',
  37. 'views': [[False, 'form']], # Beurk, but needed
  38. 'target': 'new',
  39. 'res_id': record_res[1],
  40. }
  41. else:
  42. action = {
  43. 'name': _('Number Not Found'),
  44. 'type': 'ir.actions.act_window',
  45. 'res_model': 'number.not.found',
  46. 'view_mode': 'form',
  47. 'views': [[False, 'form']], # Beurk, but needed
  48. 'target': 'new',
  49. 'context': {'default_calling_number': number}
  50. }
  51. return action
  52. def incall_notify_by_login(
  53. self, cr, uid, number, login_list, context=None):
  54. assert isinstance(login_list, list), 'login_list must be a list'
  55. res = self.get_record_from_phone_number(
  56. cr, uid, number, context=context)
  57. user_ids = self.pool['res.users'].search(
  58. cr, uid, [('login', 'in', login_list)], context=context)
  59. logger.debug(
  60. 'Notify incoming call from number %s to users %s'
  61. % (number, user_ids))
  62. action = self._prepare_incall_pop_action(
  63. cr, uid, res, number, context=context)
  64. if action:
  65. users = self.pool['res.users'].read(
  66. cr, uid, user_ids, ['context_incall_popup'], context=context)
  67. for user in users:
  68. if user['context_incall_popup']:
  69. self.pool['action.request'].notify(
  70. cr, user['id'], action)
  71. logger.debug(
  72. 'This action has been sent to user ID %d: %s'
  73. % (user['id'], action))
  74. if res:
  75. callerid = res[2]
  76. else:
  77. callerid = False
  78. return callerid
  79. class res_users(orm.Model):
  80. _inherit = 'res.users'
  81. _columns = {
  82. 'context_incall_popup': fields.boolean('Pop-up on Incoming Calls'),
  83. }
  84. _defaults = {
  85. 'context_incall_popup': True,
  86. }