Browse Source

Backport new cool stuff from 8.0 branch

Remove deadfile asterisk_click2dial_event/asterisk_click2dial_registration.py
pull/44/head
Alexis de Lattre 9 years ago
parent
commit
099d1795f5
  1. 39
      asterisk_click2dial_event/asterisk_click2dial_registration.py
  2. 1
      base_phone/__openerp__.py
  3. 192
      base_phone/base_phone.py
  4. 3
      base_phone/res_partner_view.xml
  5. 110
      base_phone/static/src/js/phone_widget.js
  6. 6
      base_phone/static/src/xml/phone.xml
  7. 45
      base_phone/test/phonenum.yml
  8. 5
      base_phone/wizard/number_not_found.py
  9. 41
      base_phone/wizard/reformat_all_phonenumbers.py
  10. 10
      base_phone/wizard/reformat_all_phonenumbers_view.xml
  11. 19
      crm_claim_phone/crm_claim_phone.py
  12. 1
      crm_phone/__openerp__.py
  13. 34
      crm_phone/crm_phone.py
  14. 41
      crm_phone/test/phonenum.yml
  15. 21
      event_phone/event_phone.py
  16. 21
      hr_phone/hr_phone.py
  17. 21
      hr_recruitment_phone/hr_recruitment_phone.py

39
asterisk_click2dial_event/asterisk_click2dial_registration.py

@ -1,39 +0,0 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# Asterisk click2dial Registration module for OpenERP
# Copyright (C) 2013 Invitu <contact@invitu.com>
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
from openerp.osv import orm
class event_registration(orm.Model):
_name = 'event.registration'
_inherit = ['event.registration', 'phone.common']
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
return super(event_registration, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
return super(event_registration, self).write(
cr, uid, ids, vals_reformated, context=context)

1
base_phone/__openerp__.py

@ -81,6 +81,7 @@ for any help or question about this module.
'qweb': ['static/src/xml/*.xml'],
'demo': ['base_phone_demo.xml'],
'images': [],
'test': ['test/phonenum.yml'],
'installable': True,
'active': False,
}

192
base_phone/base_phone.py

@ -20,6 +20,7 @@
##############################################################################
from openerp.osv import orm, fields
from openerp.tools.safe_eval import safe_eval
from openerp.tools.translate import _
import logging
# Lib for phone number reformating -> pip install phonenumbers
@ -31,76 +32,86 @@ _logger = logging.getLogger(__name__)
class phone_common(orm.AbstractModel):
_name = 'phone.common'
def generic_phonenumber_to_e164(
self, cr, uid, ids, field_from_to_seq, context=None):
result = {}
from_field_seq = [item[0] for item in field_from_to_seq]
for record in self.read(cr, uid, ids, from_field_seq, context=context):
result[record['id']] = {}
for fromfield, tofield in field_from_to_seq:
if not record.get(fromfield):
res = False
else:
try:
res = phonenumbers.format_number(
phonenumbers.parse(record.get(fromfield), None),
phonenumbers.PhoneNumberFormat.E164)
except Exception, e:
_logger.error(
"Cannot reformat the phone number '%s' to E.164 "
"format. Error message: %s"
% (record.get(fromfield), e))
_logger.error(
"You should fix this number and run the wizard "
"'Reformat all phone numbers' from the menu "
"Settings > Configuration > Phones")
# If I raise an exception here, it won't be possible to
# install the module on a DB with bad phone numbers
res = False
result[record['id']][tofield] = res
return result
def _generic_reformat_phonenumbers(self, cr, uid, vals, phonefields=None,
context=None):
def _generic_reformat_phonenumbers(
self, cr, uid, ids, vals, context=None):
"""Reformat phone numbers in E.164 format i.e. +33141981242"""
if phonefields is None:
phonefields = [
'phone', 'partner_phone', 'work_phone', 'fax',
'mobile', 'partner_mobile', 'mobile_phone',
]
if any([vals.get(field) for field in phonefields]):
assert isinstance(self._country_field, (str, unicode, type(None))),\
'Wrong self._country_field'
assert isinstance(self._partner_field, (str, unicode, type(None))),\
'Wrong self._partner_field'
assert isinstance(self._phone_fields, list),\
'self._phone_fields must be a list'
if context is None:
context = {}
if ids and isinstance(ids, (int, long)):
ids = [ids]
if any([vals.get(field) for field in self._phone_fields]):
user = self.pool['res.users'].browse(cr, uid, uid, context=context)
# country_id on res.company is a fields.function that looks at
# company_id.partner_id.addres(default).country_id
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 orm.except_orm(
_('Error:'),
_("You should set a country on the company '%s'")
% user.company_id.name)
for field in phonefields:
countrycode = None
if self._country_field:
if vals.get(self._country_field):
country = self.pool['res.country'].browse(
cr, uid, vals[self._country_field], context=context)
countrycode = country.code
elif ids:
rec = self.browse(cr, uid, ids[0], context=context)
country = safe_eval(
'rec.' + self._country_field, {'rec': rec})
countrycode = country and country.code or None
elif self._partner_field:
if vals.get(self._partner_field):
partner = self.pool['res.partner'].browse(
cr, uid, vals[self._partner_field], context=context)
countrycode = partner.country_id and\
partner.country_id.code or None
elif ids:
rec = self.browse(cr, uid, ids[0], context=context)
partner = safe_eval(
'rec.' + self._partner_field, {'rec': rec})
if partner:
countrycode = partner.country_id and\
partner.country_id.code or None
if not countrycode:
if user.company_id.country_id:
countrycode = user.company_id.country_id.code
else:
_logger.error(
_("You should set a country on the company '%s' "
"to allow the reformat of phone numbers")
% user.company_id.name)
countrycode = None
# with country code = None, phonenumbers.parse() will work
# with phonenumbers formatted in E164, but will fail with
# phone numbers in national format
for field in self._phone_fields:
if vals.get(field):
init_value = vals.get(field)
try:
res_parse = phonenumbers.parse(
vals.get(field), user_countrycode)
vals.get(field), countrycode)
vals[field] = phonenumbers.format_number(
res_parse, phonenumbers.PhoneNumberFormat.E164)
if init_value != vals[field]:
_logger.info(
"%s initial value: '%s' updated value: '%s'"
% (field, init_value, vals[field]))
except Exception, e:
raise orm.except_orm(
_('Error:'),
_("Cannot reformat the phone number '%s' to "
"international format. Error message: %s")
% (vals.get(field), e))
vals[field] = phonenumbers.format_number(
res_parse, phonenumbers.PhoneNumberFormat.E164)
if init_value != vals[field]:
_logger.info(
"%s initial value: '%s' updated value: '%s'"
% (field, init_value, vals[field]))
# I do BOTH logger and raise, because:
# raise is usefull when the record is created/written
# by a user via the Web interface
# logger is usefull when the record is created/written
# via the webservices
_logger.error(
"Cannot reformat the phone number '%s' to "
"international format with region=%s"
% (vals.get(field), countrycode))
if context.get('raise_if_phone_parse_fails'):
raise Warning(
_("Cannot reformat the phone number '%s' to "
"international format. Error message: %s")
% (vals.get(field), e))
return vals
def get_name_from_phone_number(
@ -144,29 +155,29 @@ class phone_common(orm.AbstractModel):
else:
end_number_to_match = presented_number
phonefieldsdict = self._get_phone_fields(cr, uid, context=context)
phonefieldslist = []
for objname, prop in phonefieldsdict.iteritems():
if prop.get('get_name_sequence'):
phonefieldslist.append({objname: prop})
phoneobjects = self._get_phone_fields(cr, uid, context=context)
phonefieldslist = [] # [('res.parter', 10), ('crm.lead', 20)]
for objname in phoneobjects:
if (
'_phone_name_sequence' in dir(self.pool[objname]) and
self.pool[objname]._phone_name_sequence):
phonefieldslist.append(
(objname, self.pool[objname]._phone_name_sequence))
phonefieldslist_sorted = sorted(
phonefieldslist,
key=lambda element: element.values()[0]['get_name_sequence'])
for phonedict in phonefieldslist_sorted:
objname = phonedict.keys()[0]
prop = phonedict.values()[0]
phonefields = prop['phonefields']
key=lambda element: element[1])
_logger.debug('phonefieldslist_sorted=%s' % phonefieldslist_sorted)
for (objname, prio) in phonefieldslist_sorted:
obj = self.pool[objname]
pg_search_number = str('%' + end_number_to_match)
_logger.debug(
"Will search phone and mobile numbers in %s ending with '%s'"
% (objname, end_number_to_match))
domain = []
for phonefield in phonefields:
domain.append((phonefield, 'like', pg_search_number))
if len(phonefields) > 1:
domain = ['|'] * (len(phonefields) - 1) + domain
for phonefield in obj._phone_fields:
domain.append((phonefield, '=like', pg_search_number))
if len(obj._phone_fields) > 1:
domain = ['|'] * (len(obj._phone_fields) - 1) + domain
res_ids = obj.search(cr, uid, domain, context=context)
if len(res_ids) > 1:
_logger.warning(
@ -190,13 +201,20 @@ class phone_common(orm.AbstractModel):
def _get_phone_fields(self, cr, uid, context=None):
'''Returns a dict with key = object name
and value = list of phone fields'''
res = {
'res.partner': {
'phonefields': ['phone', 'mobile'],
'faxfields': ['fax'],
'get_name_sequence': 10,
},
}
model_ids = self.pool['ir.model'].search(
cr, uid, [], context=context)
res = []
for model in self.pool['ir.model'].browse(
cr, uid, model_ids, context=context):
senv = False
try:
senv = self.pool[model.model]
except:
continue
if (
'_phone_fields' in dir(senv) and
isinstance(senv._phone_fields, list)):
res.append(model.model)
return res
def click2dial(self, cr, uid, erp_number, context=None):
@ -208,16 +226,20 @@ class phone_common(orm.AbstractModel):
class res_partner(orm.Model):
_name = 'res.partner'
_inherit = ['res.partner', 'phone.common']
_phone_fields = ['phone', 'mobile', 'fax']
_phone_name_sequence = 10
_country_field = 'country_id'
_partner_field = None
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(res_partner, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(res_partner, self).write(
cr, uid, ids, vals_reformated, context=context)

3
base_phone/res_partner_view.xml

@ -45,6 +45,9 @@
</field>
</record>
<record id="base.action_partner_form" model="ir.actions.act_window">
<field name="context">{'search_default_customer':1, 'raise_if_phone_parse_fails': True}</field>
</record>
</data>
</openerp>

110
base_phone/static/src/js/phone_widget.js

@ -21,51 +21,61 @@ openerp.base_phone = function (instance) {
var self = this;
var phone_num = this.get('value');
//console.log('BASE_PHONE phone_num = %s', phone_num);
var href = '#';
var href_text = '';
if (phone_num) {
this.$el.find('a.oe_form_uri')
.attr('href', 'tel:' + phone_num)
.text(formatInternational('', phone_num) || '');
href = 'tel:' + phone_num;
href_text = formatInternational('', phone_num) || '';
}
if (phone_num && !this.options.dial_button_invisible) {
this.$el.find('#click2dial')
.text(phone_num && _t('Dial') || '')
.on('click', function(ev) {
self.do_notify(
_t('Click2dial started'),
_t('Unhook your ringing phone'));
var arg = {
'phone_number': phone_num,
'click2dial_model': self.view.dataset.model,
'click2dial_id': self.view.datarecord.id};
self.rpc('/base_phone/click2dial', arg).done(function(r) {
//console.log('Click2dial r=%s', JSON.stringify(r));
if (r === false) {
self.do_warn("Click2dial failed");
} else if (typeof r === 'object') {
self.do_notify(
_t('Click2dial successfull'),
_t('Number dialed:') + ' ' + r.dialed_number);
if (r.action_model) {
var context = {};
if (self.view.dataset.model == 'res.partner') {
context = {
'partner_id': self.view.datarecord.id};
}
var action = {
name: r.action_name,
type: 'ir.actions.act_window',
res_model: r.action_model,
view_mode: 'form',
views: [[false, 'form']],
target: 'new',
context: context,
};
instance.client.action_manager.do_action(action);
}
if (href_text) {
this.$el.find('a.oe_form_uri').attr('href', href).text(href_text);
this.$el.find('span.oe_form_char_content').text('');
} else {
this.$el.find('a.oe_form_uri').attr('href', '').text('');
this.$el.find('span.oe_form_char_content').text(phone_num || '');
}
var click2dial_text = '';
if (href_text && !this.options.dial_button_invisible) {
click2dial_text = _t('Dial');
}
this.$el.find('#click2dial')
.text(click2dial_text)
.on('click', function(ev) {
self.do_notify(
_t('Click2dial started'),
_t('Unhook your ringing phone'));
var arg = {
'phone_number': phone_num,
'click2dial_model': self.view.dataset.model,
'click2dial_id': self.view.datarecord.id};
self.rpc('/base_phone/click2dial', arg).done(function(r) {
//console.log('Click2dial r=%s', JSON.stringify(r));
if (r === false) {
self.do_warn("Click2dial failed");
} else if (typeof r === 'object') {
self.do_notify(
_t('Click2dial successfull'),
_t('Number dialed:') + ' ' + r.dialed_number);
if (r.action_model) {
var context = {
'click2dial_model': self.view.dataset.model,
'click2dial_id': self.view.datarecord.id,
'phone_number': phone_num,
};
var action = {
name: r.action_name,
type: 'ir.actions.act_window',
res_model: r.action_model,
view_mode: 'form',
views: [[false, 'form']],
target: 'new',
context: context,
};
instance.client.action_manager.do_action(action);
}
});
}
});
}
});
}
},
on_button_clicked: function() {
@ -88,10 +98,19 @@ openerp.base_phone = function (instance) {
this._super();
} else {
var fax_num = this.get('value');
//console.log('BASE_PHONE fax_num = %s', fax_num);
var href = '#';
var href_text = '';
if (fax_num) {
this.$el.find('a.oe_form_uri')
.attr('href', 'fax:' + fax_num)
.text(formatInternational('', fax_num) || '');
href = 'fax:' + fax_num;
href_text = formatInternational('', fax_num) || '';
}
if (href_text) {
this.$el.find('a.oe_form_uri').attr('href', href).text(href_text);
this.$el.find('span.oe_form_char_content').text('');
} else {
this.$el.find('a.oe_form_uri').attr('href', '').text('');
this.$el.find('span.oe_form_char_content').text(fax_num || '');
}
}
},
@ -101,5 +120,4 @@ openerp.base_phone = function (instance) {
});
instance.web.form.widgets.add('fax', 'instance.base_phone.FieldFax');
}
};

6
base_phone/static/src/xml/phone.xml

@ -10,7 +10,7 @@
<t t-name="FieldPhone">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<t t-if="widget.get('effective_readonly')">
<a href="#" class="oe_form_uri"/>
<a href="#" class="oe_form_uri"/><span class="oe_form_char_content"/>
<!--
You should add the following "<a .. />" in your IPBX-specific
module (such as asterisk_click2dial) via <t t-extend="FieldPhone">
@ -33,7 +33,9 @@
<t t-name="FieldFax">
<span class="oe_form_field oe_form_field_email" t-att-style="widget.node.attrs.style">
<a t-if="widget.get('effective_readonly')" href="#" class="oe_form_uri"/>
<t t-if="widget.get('effective_readonly')">
<a href="#" class="oe_form_uri"/><span class="oe_form_char_content"/>
</t>
<t t-if="!widget.get('effective_readonly')">
<div>
<input type="text"

45
base_phone/test/phonenum.yml

@ -0,0 +1,45 @@
-
base_phone Write french phone numbers in national format
-
!record {model: res.partner, id: partner1}:
name: Pierre Paillet
mobile: 06 42 77 42 66
fax: (0) 1 45 42 12 42
-
base_phone Write swiss phone numbers in international format
-
!record {model: res.partner, id: partner2}:
name: Joël Grand-Guillaume
parent_id: base.res_partner_12
phone: +41 21 619 10 10
mobile: +41 79 606 42 42
-
base_phone Write invalid phone number
-
!record {model: res.partner, id: partner3}:
name: Jean Badphone
phone: 42
-
base_phone Check that valid phone numbers have been converted to E.164
-
!python {model: res.partner}: |
partner1 = self.browse(cr, uid, ref('partner1'), context=context)
assert partner1.mobile == '+33642774266', 'Mobile number not written in E.164 format (partner1)'
assert partner1.fax == '+33145421242', 'Fax number not written in E.164 format (partner1)'
partner2 = self.browse(cr, uid, ref('partner2'), context=context)
assert partner2.phone == '+41216191010', 'Phone number not written in E.164 format (partner2)'
assert partner2.mobile == '+41796064242', 'Mobile number not written in E.164 format (partner2)'
-
base_phone Check that invalid phone numbers are kept unchanged
-
!python {model: res.partner}: |
partner3 = self.browse(cr, uid, ref('partner3'), context=context)
assert partner3.phone == '42', 'Invalid phone numbers should not be changed'
-
base_phone Get name from phone number
-
!python {model: phone.common}: |
name = self.get_name_from_phone_number(cr, uid, '0642774266')
assert name == 'Pierre Paillet', 'Wrong result for get_name_from_phone_number'
name2 = self.get_name_from_phone_number(cr, uid, '0041216191010')
assert name2 == u'Joël Grand-Guillaume (Camptocamp)', 'Wrong result for get_name_from_phone_number (partner2)'

5
base_phone/wizard/number_not_found.py

@ -60,8 +60,9 @@ class number_not_found(orm.TransientModel):
if not res:
res = {}
if res.get('calling_number'):
convert = self.pool['phone.common']._generic_reformat_phonenumbers(
cr, uid, {'phone': res.get('calling_number')}, context=context)
convert = self.pool['res.partner']._generic_reformat_phonenumbers(
cr, uid, None, {'phone': res.get('calling_number')},
context=context)
parsed_num = phonenumbers.parse(convert.get('phone'))
res['e164_number'] = phonenumbers.format_number(
parsed_num, phonenumbers.PhoneNumberFormat.INTERNATIONAL)

41
base_phone/wizard/reformat_all_phonenumbers.py

@ -32,20 +32,25 @@ class reformat_all_phonenumbers(orm.TransientModel):
_columns = {
'phonenumbers_not_reformatted': fields.text(
"Phone numbers that couldn't be reformatted"),
'state': fields.selection([
('draft', 'Draft'),
('done', 'Done'),
], string='State', default='draft'),
}
_defaults = {
'state': 'draft',
}
def run_reformat_all_phonenumbers(self, cr, uid, ids, context=None):
logger.info('Starting to reformat all the phone numbers')
phonenumbers_not_reformatted = ''
toreformat_dict = self.pool['phone.common']._get_phone_fields(
phoneobjects = self.pool['phone.common']._get_phone_fields(
cr, uid, context=context)
for objname, prop in toreformat_dict.iteritems():
fields = []
ctx_raise = dict(context, raise_if_phone_parse_fails=True)
for objname in phoneobjects:
fields = self.pool[objname]._phone_fields
obj = self.pool[objname]
if prop.get('phonefields'):
fields += prop['phonefields']
if prop.get('faxfields'):
fields += prop['faxfields']
logger.info(
'Starting to reformat phone numbers on object %s '
'(fields = %s)' % (objname, fields))
@ -66,18 +71,17 @@ class reformat_all_phonenumbers(orm.TransientModel):
# _generic_reformat_phonenumbers()
try:
obj._generic_reformat_phonenumbers(
cr, uid, entry, context=context)
cr, uid, [entry['id']], entry, context=ctx_raise)
except Exception, e:
name = obj.name_get(
cr, uid, [init_entry['id']], context=context)[0][1]
err_msg = e and len(e) > 1 and e[1] or 'missing error msg'
phonenumbers_not_reformatted += \
"Problem on %s '%s'. Error message: %s\n" % (
obj._description,
name, e[1])
obj._description, name, err_msg)
logger.warning(
"Problem on %s '%s'. Error message: %s" % (
obj._description,
name, e[1]))
obj._description, name, err_msg))
continue
if any(
[init_entry.get(field)
@ -94,8 +98,13 @@ 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')
return True
action = self.pool['ir.actions.act_window'].for_xml_id(
cr, uid, 'base_phone', 'reformat_all_phonenumbers_action',
context=context)
action['res_id'] = ids[0]
return action

10
base_phone/wizard/reformat_all_phonenumbers_view.xml

@ -18,10 +18,16 @@
<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"/>
<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 special="cancel" string="Close"
class="oe_highlight" states="done"/>
<button special="cancel" string="Cancel"
class="oe_link" states="draft"/>
</footer>
</form>
</field>

19
crm_claim_phone/crm_claim_phone.py

@ -26,27 +26,18 @@ from openerp.osv import orm
class crm_claim(orm.Model):
_name = 'crm.claim'
_inherit = ['crm.claim', 'phone.common']
_phone_fields = ['partner_phone']
_country_field = None
_partner_field = 'partner_id'
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(crm_claim, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(crm_claim, self).write(
cr, uid, ids, vals_reformated, context=context)
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def _get_phone_fields(self, cr, uid, context=None):
res = super(phone_common, self)._get_phone_fields(
cr, uid, context=context)
res['crm.claim'] = {
'phonefields': ['partner_phone'],
}
return res

1
crm_phone/__openerp__.py

@ -47,6 +47,7 @@ for any help or question about this module.
'crm_view.xml',
'wizard/number_not_found_view.xml',
],
'test': ['test/phonenum.yml'],
'images': [],
'installable': True,
'auto_install': True,

34
crm_phone/crm_phone.py

@ -26,16 +26,20 @@ from openerp.osv import orm
class crm_lead(orm.Model):
_name = 'crm.lead'
_inherit = ['crm.lead', 'phone.common']
_phone_fields = ['phone', 'mobile', 'fax']
_phone_name_sequence = 20
_country_field = 'country_id'
_partner_field = None
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(crm_lead, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(crm_lead, self).write(
cr, uid, ids, vals_reformated, context=context)
@ -65,34 +69,18 @@ class crm_lead(orm.Model):
class crm_phonecall(orm.Model):
_name = 'crm.phonecall'
_inherit = ['crm.phonecall', 'phone.common']
_phone_fields = ['partner_phone', 'partner_mobile']
_country_field = None
_partner_field = 'partner_id'
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(crm_phonecall, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(crm_phonecall, self).write(
cr, uid, ids, vals_reformated, context=context)
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def _get_phone_fields(self, cr, uid, context=None):
res = super(phone_common, self)._get_phone_fields(
cr, uid, context=context)
res.update({
'crm.lead': {
'phonefields': ['phone', 'mobile'],
'faxfields': ['fax'],
'get_name_sequence': 20,
},
'crm.phonecall': {
'phonefields': ['partner_phone', 'partner_mobile'],
},
})
return res

41
crm_phone/test/phonenum.yml

@ -0,0 +1,41 @@
-
crm_phone Write french phone numbers in national format
-
!record {model: crm.lead, id: lead1}:
name: Jacques Toufaux
mobile: 06 42 77 42 77
fax: (0) 1 45 44 42 43
country_id: base.fr
-
crm_phone Write swiss phone numbers in national format
-
!record {model: crm.lead, id: lead2}:
name: Michel Content
country_id: base.ch
phone: 04 31 23 45 67
-
crm_phone Create a german lead
-
!record {model: crm.lead, id: lead3}:
name: Angela Strasse
country_id: base.de
-
crm_phone Check that valid phone numbers have been converted to E.164
-
!python {model: crm.lead}: |
lead1 = self.browse(cr, uid, ref('lead1'), context=context)
assert lead1.mobile == '+33642774277', 'Mobile number not written in E.164 format (lead1)'
assert lead1.fax == '+33145444243', 'Fax number not written in E.164 format (lead1)'
lead2 = self.browse(cr, uid, ref('lead2'), context=context)
assert lead2.phone == '+41431234567', 'Phone number not written in E.164 format (lead2)'
self.write(cr, uid, ref('lead3'), {'phone': '0891234567'})
lead3 = self.browse(cr, uid, ref('lead3'), context=context)
assert lead3.phone == '+49891234567', 'Phone number not written in E.164 format (lead3)'
-
crm_phone Get name from phone number
-
!python {model: phone.common}: |
name = self.get_name_from_phone_number(cr, uid, '0642774277')
assert name == 'Jacques Toufaux', 'Wrong result for get_name_from_phone_number (lead1)'
name2 = self.get_name_from_phone_number(cr, uid, '0041431234567')
assert name2 == 'Michel Content', 'Wrong result for get_name_from_phone_number (lead2)'

21
event_phone/event_phone.py

@ -26,28 +26,19 @@ from openerp.osv import orm
class event_registration(orm.Model):
_name = 'event.registration'
_inherit = ['event.registration', 'phone.common']
_phone_fields = ['phone']
_phone_name_sequence = 100
_country_field = None
_partner_field = 'partner_id'
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(event_registration, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(event_registration, self).write(
cr, uid, ids, vals_reformated, context=context)
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def _get_phone_fields(self, cr, uid, context=None):
res = super(phone_common, self)._get_phone_fields(
cr, uid, context=context)
res['event.registration'] = {
'phonefields': ['phone'],
'get_name_sequence': 100,
}
return res

21
hr_phone/hr_phone.py

@ -26,28 +26,19 @@ from openerp.osv import orm
class hr_employee(orm.Model):
_name = 'hr.employee'
_inherit = ['hr.employee', 'phone.common']
_phone_fields = ['work_phone', 'mobile_phone']
_phone_name_sequence = 30
_country_field = 'country_id'
_partner_field = None
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(hr_employee, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(hr_employee, self).write(
cr, uid, ids, vals_reformated, context=context)
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def _get_phone_fields(self, cr, uid, context=None):
res = super(phone_common, self)._get_phone_fields(
cr, uid, context=context)
res['hr.employee'] = {
'phonefields': ['work_phone', 'mobile_phone'],
'get_name_sequence': 30,
}
return res

21
hr_recruitment_phone/hr_recruitment_phone.py

@ -26,28 +26,19 @@ from openerp.osv import orm
class hr_applicant(orm.Model):
_name = 'hr.applicant'
_inherit = ['hr.applicant', 'phone.common']
_phone_fields = ['partner_phone', 'partner_mobile']
_phone_name_sequence = 50
_country_field = None
_partner_field = 'partner_id'
def create(self, cr, uid, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, None, vals, context=context)
return super(hr_applicant, self).create(
cr, uid, vals_reformated, context=context)
def write(self, cr, uid, ids, vals, context=None):
vals_reformated = self._generic_reformat_phonenumbers(
cr, uid, vals, context=context)
cr, uid, ids, vals, context=context)
return super(hr_applicant, self).write(
cr, uid, ids, vals_reformated, context=context)
class phone_common(orm.AbstractModel):
_inherit = 'phone.common'
def _get_phone_fields(self, cr, uid, context=None):
res = super(phone_common, self)._get_phone_fields(
cr, uid, context=context)
res['hr.applicant'] = {
'phonefields': ['partner_phone', 'partner_mobile'],
'get_name_sequence': 50,
}
return res
Loading…
Cancel
Save