diff --git a/base_phone/base_phone.py b/base_phone/base_phone.py index 2131978..d0dcaa5 100644 --- a/base_phone/base_phone.py +++ b/base_phone/base_phone.py @@ -77,13 +77,14 @@ class PhoneCommon(models.AbstractModel): if user.company_id.country_id: user_countrycode = user.company_id.country_id.code else: - # We need to raise an exception here because, if we pass None - # as second arg of phonenumbers.parse(), it will raise an - # exception when you try to enter a phone number in - # national format... so it's better to raise the exception here - raise Warning( - _("You should set a country on the company '%s'") + _logger.error( + _("You should set a country on the company '%s' " + "to allow the reformat of phone numbers") % user.company_id.name) + user_countrycode = '' + # with country code = '', phonenumbers.parse() will work + # with phonenumbers formatted in E164, but will fail with + # phone numbers in national format for field in phonefields: if vals.get(field): init_value = vals.get(field) diff --git a/base_phone/wizard/reformat_all_phonenumbers.py b/base_phone/wizard/reformat_all_phonenumbers.py index f0eace7..a84eb2c 100644 --- a/base_phone/wizard/reformat_all_phonenumbers.py +++ b/base_phone/wizard/reformat_all_phonenumbers.py @@ -1,8 +1,8 @@ # -*- encoding: utf-8 -*- ############################################################################## # -# Base Phone module for OpenERP -# Copyright (C) 2012-2014 Alexis de Lattre +# Base Phone module for Odoo +# Copyright (C) 2012-2015 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 @@ -19,20 +19,23 @@ # ############################################################################## -from openerp.osv import orm, fields +from openerp import models, fields import logging logger = logging.getLogger(__name__) -class reformat_all_phonenumbers(orm.TransientModel): +class reformat_all_phonenumbers(models.TransientModel): _name = "reformat.all.phonenumbers" + _inherit = "res.config.installer" _description = "Reformat all phone numbers" - _columns = { - 'phonenumbers_not_reformatted': fields.text( - "Phone numbers that couldn't be reformatted"), - } + phonenumbers_not_reformatted = fields.Text( + string="Phone numbers that couldn't be reformatted") + state = fields.Selection([ + ('draft', 'Draft'), + ('done', 'Done'), + ], string='State', default='draft') def run_reformat_all_phonenumbers(self, cr, uid, ids, context=None): logger.info('Starting to reformat all the phone numbers') @@ -95,9 +98,10 @@ class reformat_all_phonenumbers(orm.TransientModel): phonenumbers_not_reformatted = \ 'All phone numbers have been reformatted successfully.' self.write( - cr, uid, ids[0], - {'phonenumbers_not_reformatted': phonenumbers_not_reformatted}, - context=context) + cr, uid, ids[0], { + 'phonenumbers_not_reformatted': phonenumbers_not_reformatted, + 'state': 'done', + }, context=context) logger.info('End of the phone number reformatting wizard') action = self.pool['ir.actions.act_window'].for_xml_id( cr, uid, 'base_phone', 'reformat_all_phonenumbers_action', diff --git a/base_phone/wizard/reformat_all_phonenumbers_view.xml b/base_phone/wizard/reformat_all_phonenumbers_view.xml index 482f0a5..181620d 100644 --- a/base_phone/wizard/reformat_all_phonenumbers_view.xml +++ b/base_phone/wizard/reformat_all_phonenumbers_view.xml @@ -12,16 +12,21 @@ reformat_all_phonenumbers.form reformat.all.phonenumbers -
- + -