|
@ -1,40 +1,22 @@ |
|
|
# -*- coding: utf-8 -*- |
|
|
# -*- coding: utf-8 -*- |
|
|
############################################################################## |
|
|
|
|
|
# |
|
|
|
|
|
# Base Phone Pop-up module for Odoo/OpenERP |
|
|
|
|
|
# Copyright (C) 2014 Alexis de Lattre <alexis@via.ecp.fr> |
|
|
|
|
|
# |
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
|
|
|
|
# it under the terms of the GNU Affero General Public License as |
|
|
|
|
|
# published by the Free Software Foundation, either version 3 of the |
|
|
|
|
|
# License, or (at your option) any later version. |
|
|
|
|
|
# |
|
|
|
|
|
# This program is distributed in the hope that it will be useful, |
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
|
|
|
|
# GNU Affero General Public License for more details. |
|
|
|
|
|
# |
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License |
|
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
|
|
|
|
# |
|
|
|
|
|
############################################################################## |
|
|
|
|
|
|
|
|
# © 2014-2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) |
|
|
|
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|
|
|
|
|
|
|
|
from openerp.osv import orm, fields |
|
|
|
|
|
from openerp.tools.translate import _ |
|
|
|
|
|
|
|
|
from openerp import models, fields, api, _ |
|
|
import logging |
|
|
import logging |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger = logging.getLogger(__name__) |
|
|
logger = logging.getLogger(__name__) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class phone_common(orm.AbstractModel): |
|
|
|
|
|
|
|
|
class PhoneCommon(models.AbstractModel): |
|
|
_inherit = 'phone.common' |
|
|
_inherit = 'phone.common' |
|
|
|
|
|
|
|
|
def _prepare_incall_pop_action( |
|
|
|
|
|
self, cr, uid, record_res, number, context=None): |
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def _prepare_incall_pop_action(self, record_res, number): |
|
|
action = False |
|
|
action = False |
|
|
if record_res: |
|
|
if record_res: |
|
|
obj = self.pool[record_res[0]] |
|
|
|
|
|
|
|
|
obj = self.env[record_res[0]] |
|
|
action = { |
|
|
action = { |
|
|
'name': obj._description, |
|
|
'name': obj._description, |
|
|
'type': 'ir.actions.act_window', |
|
|
'type': 'ir.actions.act_window', |
|
@ -56,28 +38,23 @@ class phone_common(orm.AbstractModel): |
|
|
} |
|
|
} |
|
|
return action |
|
|
return action |
|
|
|
|
|
|
|
|
def incall_notify_by_login( |
|
|
|
|
|
self, cr, uid, number, login_list, context=None): |
|
|
|
|
|
|
|
|
@api.model |
|
|
|
|
|
def incall_notify_by_login(self, number, login_list): |
|
|
assert isinstance(login_list, list), 'login_list must be a list' |
|
|
assert isinstance(login_list, list), 'login_list must be a list' |
|
|
res = self.get_record_from_phone_number( |
|
|
|
|
|
cr, uid, number, context=context) |
|
|
|
|
|
user_ids = self.pool['res.users'].search( |
|
|
|
|
|
cr, uid, [('login', 'in', login_list)], context=context) |
|
|
|
|
|
|
|
|
res = self.get_record_from_phone_number(number) |
|
|
|
|
|
users = self.env['res.users'].search( |
|
|
|
|
|
[('login', 'in', login_list)]) |
|
|
logger.debug( |
|
|
logger.debug( |
|
|
'Notify incoming call from number %s to users %s' |
|
|
'Notify incoming call from number %s to users %s' |
|
|
% (number, user_ids)) |
|
|
|
|
|
action = self._prepare_incall_pop_action( |
|
|
|
|
|
cr, uid, res, number, context=context) |
|
|
|
|
|
|
|
|
% (number, users.ids)) |
|
|
|
|
|
action = self._prepare_incall_pop_action(res, number) |
|
|
if action: |
|
|
if action: |
|
|
users = self.pool['res.users'].read( |
|
|
|
|
|
cr, uid, user_ids, ['context_incall_popup'], context=context) |
|
|
|
|
|
for user in users: |
|
|
for user in users: |
|
|
if user['context_incall_popup']: |
|
|
|
|
|
self.pool['action.request'].notify( |
|
|
|
|
|
cr, user['id'], action) |
|
|
|
|
|
|
|
|
if user.context_incall_popup: |
|
|
|
|
|
self.sudo(user.id).env['action.request'].notify(action) |
|
|
logger.debug( |
|
|
logger.debug( |
|
|
'This action has been sent to user ID %d: %s' |
|
|
'This action has been sent to user ID %d: %s' |
|
|
% (user['id'], action)) |
|
|
|
|
|
|
|
|
% (user.id, action)) |
|
|
if res: |
|
|
if res: |
|
|
callerid = res[2] |
|
|
callerid = res[2] |
|
|
else: |
|
|
else: |
|
@ -85,13 +62,8 @@ class phone_common(orm.AbstractModel): |
|
|
return callerid |
|
|
return callerid |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class res_users(orm.Model): |
|
|
|
|
|
|
|
|
class ResUsers(models.Model): |
|
|
_inherit = 'res.users' |
|
|
_inherit = 'res.users' |
|
|
|
|
|
|
|
|
_columns = { |
|
|
|
|
|
'context_incall_popup': fields.boolean('Pop-up on Incoming Calls'), |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
_defaults = { |
|
|
|
|
|
'context_incall_popup': True, |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
context_incall_popup = fields.Boolean( |
|
|
|
|
|
string='Pop-up on Incoming Calls', default=True) |