Browse Source

[FIX] Fixing issues from travis in base_phone module

pull/83/head
Sebastien LANGE 8 years ago
parent
commit
559e5d8f4e
  1. 1
      base_phone/README.rst
  2. 35
      base_phone/__openerp__.py
  3. 6
      base_phone/report_sxw_format.py
  4. 114
      base_phone/wizard/number_not_found.py
  5. 3
      base_phone/wizard/number_not_found_view.xml
  6. 5
      base_phone/wizard/reformat_all_phonenumbers.py

1
base_phone/README.rst

@ -59,7 +59,6 @@ There is no specific usage procedure for this module.
Known issues / Roadmap
======================
* ...
Bug Tracker
===========

35
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 <alexis.delattre@akretion.com>
for any help or question about this module.
""",
'author': "Akretion,Odoo Community Association (OCA)",
'website': 'http://www.akretion.com/',
'depends': ['base', 'web'],

6
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,

114
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

3
base_phone/wizard/number_not_found_view.xml

@ -32,8 +32,7 @@
colspan="1" col="2">
<button name="create_partner" class="oe_highlight" colspan="2"
string="Create Partner with this Number" type="object"/>
<field name="to_update_partner_id"
on_change="onchange_to_update_partner(to_update_partner_id)"/>
<field name="to_update_partner_id" />
<field name="current_partner_phone" widget="phone"
options="{'dial_button_invisible': True}"/>
<field name="current_partner_mobile" widget="phone"

5
base_phone/wizard/reformat_all_phonenumbers.py

@ -1,4 +1,4 @@
# -*- encoding: utf-8 -*-
# -*- coding: utf-8 -*-
##############################################################################
#
# Base Phone module for Odoo
@ -61,11 +61,9 @@ class ReformatAllPhonenumbers(models.TransientModel):
all_entries = obj.search(domain)
for entry in all_entries:
print "entry=", entry
init_entry_vals = {}
for field in fields:
init_entry_vals[field] = entry[field]
print "init_entry=", init_entry_vals
entry_vals = init_entry_vals.copy()
# entry is _updated_ by the fonction
# _generic_reformat_phonenumbers()
@ -84,7 +82,6 @@ class ReformatAllPhonenumbers(models.TransientModel):
if any([
init_entry_vals.get(field) != entry_vals.get(field) for
field in fields]):
print "entry_vals=", entry_vals
logger.info(
'[%s] Reformating phone number: FROM %s TO %s',
obj._description, unicode(init_entry_vals),

Loading…
Cancel
Save