From 559e5d8f4e9e4ec8d2b6efbf7806fe9415d9af87 Mon Sep 17 00:00:00 2001 From: Sebastien LANGE Date: Thu, 24 Mar 2016 17:22:31 +0100 Subject: [PATCH] [FIX] Fixing issues from travis in base_phone module --- base_phone/README.rst | 1 - base_phone/__openerp__.py | 35 ------ base_phone/report_sxw_format.py | 6 +- base_phone/wizard/number_not_found.py | 114 ++++++++---------- base_phone/wizard/number_not_found_view.xml | 3 +- .../wizard/reformat_all_phonenumbers.py | 5 +- 6 files changed, 55 insertions(+), 109 deletions(-) diff --git a/base_phone/README.rst b/base_phone/README.rst index 875c537..20be1f2 100644 --- a/base_phone/README.rst +++ b/base_phone/README.rst @@ -59,7 +59,6 @@ There is no specific usage procedure for this module. Known issues / Roadmap ====================== -* ... Bug Tracker =========== diff --git a/base_phone/__openerp__.py b/base_phone/__openerp__.py index ae90138..6447c32 100644 --- a/base_phone/__openerp__.py +++ b/base_phone/__openerp__.py @@ -26,41 +26,6 @@ 'category': 'Phone', 'license': 'AGPL-3', 'summary': 'Validate phone numbers', - 'description': """ -Base Phone -========== - -This module validate phone numbers using the *phonenumbers* Python library, -which is a port of the library used in Android smartphones. For example, if -your user is linked to a French company and you update the form view of a -partner with a badly written French phone number such as '01-55-42-12-42', -Odoo will automatically update the phone number to E.164 format '+33155421242' -and display in the form and tree view of the partner the readable equivalent -'+33 1 55 42 12 42'. - -This module also adds *tel:* links on phone numbers and *fax:* links on fax -numbers. If you have a softphone or a client software on your PC that is -associated with *tel:* links, the softphone should propose you to dial the -phone number when you click on such a link. - -This module also updates the format() function for reports and adds 2 -arguments : - -* *phone* : should be True for a phone number, False (default) otherwize. -* *phone_format* : it can have 3 possible values : - * *international* (default) : the report will display '+33 1 55 42 12 42' - * *national* : the report will display '01 55 42 12 42' - * *e164* : the report will display '+33155421242' - -For example, in the Sale Order report, to display the phone number of the -Salesman, you can write : o.user_id and o.user_id.phone and -format(o.user_id.phone, phone=True, phone_format='national') or '' - -This module is independant from the Asterisk connector. - -Please contact Alexis de Lattre from Akretion -for any help or question about this module. -""", 'author': "Akretion,Odoo Community Association (OCA)", 'website': 'http://www.akretion.com/', 'depends': ['base', 'web'], diff --git a/base_phone/report_sxw_format.py b/base_phone/report_sxw_format.py index 91a48f7..3ba94e6 100644 --- a/base_phone/report_sxw_format.py +++ b/base_phone/report_sxw_format.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Base Phone module for OpenERP @@ -19,12 +19,12 @@ # ############################################################################## -from openerp.osv import orm +from openerp import models from openerp.report import report_sxw import phonenumbers -class base_phone_installed(orm.AbstractModel): +class BasePhoneInstalled(models.AbstractModel): '''When you use monkey patching, the code is executed when the module is in the addons_path of the OpenERP server, even is the module is not installed ! In order to avoid the side-effects it can create, diff --git a/base_phone/wizard/number_not_found.py b/base_phone/wizard/number_not_found.py index 4fc4a5b..510a2c1 100644 --- a/base_phone/wizard/number_not_found.py +++ b/base_phone/wizard/number_not_found.py @@ -1,4 +1,4 @@ -# -*- encoding: utf-8 -*- +# -*- coding: utf-8 -*- ############################################################################## # # Base Phone module for Odoo @@ -19,7 +19,7 @@ # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields, api, exceptions from openerp.tools.translate import _ import logging import phonenumbers @@ -27,43 +27,40 @@ import phonenumbers _logger = logging.getLogger(__name__) -class number_not_found(orm.TransientModel): +class NumberNotFound(models.TransientModel): _name = "number.not.found" _description = "Number not found" - _columns = { - 'calling_number': fields.char( - 'Calling Number', size=64, readonly=True, - help="Phone number of calling party that has been obtained " - "from the telephony server, in the format used by the " - "telephony server (not E.164)."), - 'e164_number': fields.char( - 'E.164 Number', size=64, - help="E.164 equivalent of the calling number."), - 'number_type': fields.selection( - [('phone', 'Fixed'), ('mobile', 'Mobile')], - 'Fixed/Mobile', required=True), - 'to_update_partner_id': fields.many2one( - 'res.partner', 'Partner to Update', - help="Partner on which the phone number will be written"), - 'current_partner_phone': fields.related( - 'to_update_partner_id', 'phone', type='char', - relation='res.partner', string='Current Phone', readonly=True), - 'current_partner_mobile': fields.related( - 'to_update_partner_id', 'mobile', type='char', - relation='res.partner', string='Current Mobile', readonly=True), - } + calling_number = fields.Char(string='Calling Number', size=64, + readonly=True, + help="Phone number of calling party that has " + "been obtained from the telephony server, in " + "the format used by the telephony server " + "(not E.164).") + e164_number = fields.Char(string='E.164 Number', size=64, + help="E.164 equivalent of the calling number.") + number_type = fields.Selection(selection=[ + ('phone', 'Fixed'), + ('mobile', 'Mobile') + ], string='Fixed/Mobile', required=True) + to_update_partner_id = fields.Many2one(comodel_name='res.partner', + string='Partner to Update', + help="Partner on which the phone " + "number will be written") + current_partner_phone = fields.Char(related='to_update_partner_id.phone', + string='Current Phone', readonly=True) + current_partner_mobile = fields.Char(related='to_update_partner_id.mobile', + string='Current Mobile', + readonly=True) - def default_get(self, cr, uid, fields_list, context=None): - res = super(number_not_found, self).default_get( - cr, uid, fields_list, context=context - ) + @api.model + def default_get(self, fields_list): + res = super(NumberNotFound, self).default_get(fields_list) if not res: res = {} if res.get('calling_number'): - convert = self.pool['res.partner']._generic_reformat_phonenumbers( - cr, uid, None, {'phone': res.get('calling_number')}, - context=context) + convert = self.env['res.partner']._generic_reformat_phonenumbers( + None, {'phone': res.get('calling_number')}) parsed_num = phonenumbers.parse(convert.get('phone')) res['e164_number'] = phonenumbers.format_number( parsed_num, phonenumbers.PhoneNumberFormat.INTERNATIONAL) @@ -74,15 +71,15 @@ class number_not_found(orm.TransientModel): res['number_type'] = 'phone' return res - def create_partner(self, cr, uid, ids, context=None): + @api.multi + def create_partner(self): '''Function called by the related button of the wizard''' - if context is None: - context = {} - wiz = self.browse(cr, uid, ids[0], context=context) + wiz = self[0] parsed_num = phonenumbers.parse(wiz.e164_number, None) phonenumbers.number_type(parsed_num) - context['default_%s' % wiz.number_type] = wiz.e164_number + context = dict(self._context or {}) + context.update({'default_%s' % wiz.number_type: wiz.e164_number}) action = { 'name': _('Create New Partner'), 'view_mode': 'form,tree,kanban', @@ -91,18 +88,19 @@ class number_not_found(orm.TransientModel): 'nodestroy': False, 'target': 'current', 'context': context, - } + } return action - def update_partner(self, cr, uid, ids, context=None): - wiz = self.browse(cr, uid, ids[0], context=context) + @api.multi + def update_partner(self): + wiz = self[0] if not wiz.to_update_partner_id: - raise orm.except_orm( - _('Error:'), - _("Select the Partner to Update.")) - self.pool['res.partner'].write( - cr, uid, wiz.to_update_partner_id.id, - {wiz.number_type: wiz.e164_number}, context=context) + raise exceptions.Warning( + _('Error'), + _('Select the Partner to Update.')) + self.env['res.partner'].write( + wiz.to_update_partner_id.id, + {wiz.number_type: wiz.e164_number}) action = { 'name': _('Partner: %s' % wiz.to_update_partner_id.name), 'type': 'ir.actions.act_window', @@ -111,23 +109,11 @@ class number_not_found(orm.TransientModel): 'nodestroy': False, 'target': 'current', 'res_id': wiz.to_update_partner_id.id, - 'context': context, - } + 'context': self._context, + } return action - def onchange_to_update_partner( - self, cr, uid, ids, to_update_partner_id, context=None): - res = {'value': {}} - if to_update_partner_id: - to_update_partner = self.pool['res.partner'].browse( - cr, uid, to_update_partner_id, context=context) - res['value'].update({ - 'current_partner_phone': to_update_partner.phone, - 'current_partner_mobile': to_update_partner.mobile, - }) - else: - res['value'].update({ - 'current_partner_phone': False, - 'current_partner_mobile': False, - }) - return res + @api.onchange('to_update_partner_id') + def onchange_to_update_partner(self): + self.current_partner_phone = self.to_update_partner.phone or False + self.current_partner_mobile = self.to_update_partner.mobile or False diff --git a/base_phone/wizard/number_not_found_view.xml b/base_phone/wizard/number_not_found_view.xml index f88b49f..24d951e 100644 --- a/base_phone/wizard/number_not_found_view.xml +++ b/base_phone/wizard/number_not_found_view.xml @@ -32,8 +32,7 @@ colspan="1" col="2">