Browse Source

Fully remove raise from write/create, to avoid a crash on module install with XML data for res.company + it's related partner with phone numbers

FIX install wizard
pull/31/head
Alexis de Lattre 10 years ago
parent
commit
586296537b
  1. 13
      base_phone/base_phone.py
  2. 26
      base_phone/wizard/reformat_all_phonenumbers.py
  3. 19
      base_phone/wizard/reformat_all_phonenumbers_view.xml

13
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)

26
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 <alexis@via.ecp.fr>
# Base Phone module for Odoo
# Copyright (C) 2012-2015 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
@ -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',

19
base_phone/wizard/reformat_all_phonenumbers_view.xml

@ -12,16 +12,21 @@
<field name="name">reformat_all_phonenumbers.form</field>
<field name="model">reformat.all.phonenumbers</field>
<field name="arch" type="xml">
<form string="Reformat all phone numbers" version="7.0">
<!-- TODO : add a "state" and display fields accordingly -->
<form string="Reformat all phone numbers">
<group name="main">
<label string="This wizard reformats the phone, mobile and fax numbers of all partners in standard international format e.g. +33141981242" colspan="4"/>
<label colspan="4" string="Phone numbers that couldn't be reformatted:"/>
<field name="phonenumbers_not_reformatted" colspan="4" nolabel="1"/>
<label string="This wizard reformats the phone, mobile and fax numbers of all partners in standard international format e.g. +33141981242" colspan="2" states="draft"/>
<label colspan="2" string="Phone numbers that couldn't be reformatted:" states="done"/>
<field name="phonenumbers_not_reformatted" colspan="2" nolabel="1" states="done"/>
<field name="state" invisible="1"/>
</group>
<footer>
<button name="run_reformat_all_phonenumbers" string="Reformat all phone numbers" type="object" class="oe_highlight"/>
<button special="cancel" string="Cancel" class="oe_link" />
<button name="run_reformat_all_phonenumbers"
string="Reformat all phone numbers" type="object"
class="oe_highlight" states="draft"/>
<button name="action_next" type="object" string="Close"
class="oe_highlight" states="done"/>
<button special="cancel" string="Cancel"
class="oe_link" states="draft"/>
</footer>
</form>
</field>

Loading…
Cancel
Save