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.

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