From 79e1634ca1bc2b218636b80b3b7046985b5ef93f Mon Sep 17 00:00:00 2001 From: Alexis de Lattre Date: Tue, 24 May 2016 13:50:26 +0200 Subject: [PATCH] Port base_phone_popup to v9 --- .travis.yml | 2 +- base_phone_popup/__init__.py | 19 -------- base_phone_popup/__openerp__.py | 33 +++----------- base_phone_popup/popup.py | 68 +++++++++-------------------- base_phone_popup/res_users_view.xml | 8 ++-- 5 files changed, 31 insertions(+), 99 deletions(-) diff --git a/.travis.yml b/.travis.yml index 687502f..91049aa 100644 --- a/.travis.yml +++ b/.travis.yml @@ -33,7 +33,7 @@ install: - travis_install_nightly - pip install phonenumbers py-Asterisk SOAPpy - hg clone http://bitbucket.org/juris_malinens/web_action_request -b ${VERSION} ${HOME}/web_action_request # Pull request is not merged in anybox - - hg clone http://bitbucket.org/anybox/bus_enhanced ${HOME}/bus_enhanced + - hg clone http://bitbucket.org/juris_malinens/bus_enhanced -b ${VERSION} ${HOME}/bus_enhanced # Pull request is not merged in anybox script: - travis_run_tests diff --git a/base_phone_popup/__init__.py b/base_phone_popup/__init__.py index b9cf425..d5a89e7 100644 --- a/base_phone_popup/__init__.py +++ b/base_phone_popup/__init__.py @@ -1,22 +1,3 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Base Phone Pop-up module for Odoo/OpenERP -# Copyright (C) 2014 Alexis de Lattre -# -# 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 . -# -############################################################################## from . import popup diff --git a/base_phone_popup/__openerp__.py b/base_phone_popup/__openerp__.py index e7a389c..29f9cb0 100644 --- a/base_phone_popup/__openerp__.py +++ b/base_phone_popup/__openerp__.py @@ -1,28 +1,11 @@ -# -*- encoding: utf-8 -*- -############################################################################## -# -# Base Phone Pop-up module for Odoo/OpenERP -# Copyright (C) 2014 Alexis de Lattre -# -# 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 . -# -############################################################################## +# -*- coding: utf-8 -*- +# © 2014-2016 Akretion (Alexis de Lattre ) +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). { 'name': 'Base Phone Pop-up', - 'version': '8.0.0.4.0', + 'version': '9.0.1.0.0', 'category': 'Phone', 'license': 'AGPL-3', 'summary': 'Pop-up the related form view to the user on incoming calls', @@ -55,10 +38,6 @@ http://www.akretion.com/products-and-services/openerp-asterisk-voip-connector 'author': "Akretion,Odoo Community Association (OCA)", 'website': 'http://www.akretion.com/', 'depends': ['base_phone', 'web_action_request'], - 'data': [ - 'res_users_view.xml', - ], - 'images': [], - 'active': False, - 'installable': False, + 'data': ['res_users_view.xml'], + 'installable': True, } diff --git a/base_phone_popup/popup.py b/base_phone_popup/popup.py index 47bf1c5..b0fc561 100644 --- a/base_phone_popup/popup.py +++ b/base_phone_popup/popup.py @@ -1,40 +1,22 @@ # -*- coding: utf-8 -*- -############################################################################## -# -# Base Phone Pop-up module for Odoo/OpenERP -# Copyright (C) 2014 Alexis de Lattre -# -# 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 . -# -############################################################################## +# © 2014-2016 Akretion (Alexis de Lattre ) +# 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 logger = logging.getLogger(__name__) -class phone_common(orm.AbstractModel): +class PhoneCommon(models.AbstractModel): _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 if record_res: - obj = self.pool[record_res[0]] + obj = self.env[record_res[0]] action = { 'name': obj._description, 'type': 'ir.actions.act_window', @@ -56,28 +38,23 @@ class phone_common(orm.AbstractModel): } 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' - 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( '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: - users = self.pool['res.users'].read( - cr, uid, user_ids, ['context_incall_popup'], context=context) 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( 'This action has been sent to user ID %d: %s' - % (user['id'], action)) + % (user.id, action)) if res: callerid = res[2] else: @@ -85,13 +62,8 @@ class phone_common(orm.AbstractModel): return callerid -class res_users(orm.Model): +class ResUsers(models.Model): _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) diff --git a/base_phone_popup/res_users_view.xml b/base_phone_popup/res_users_view.xml index e215c15..1631b8a 100644 --- a/base_phone_popup/res_users_view.xml +++ b/base_phone_popup/res_users_view.xml @@ -1,10 +1,10 @@ - + @@ -36,4 +36,4 @@ - +