Browse Source
Backport main modules from v12 to v11 (base_phone, crm_phone, hr_phone, event_phone, hr_recruitment_phone, asterisk_click2dial)
pull/180/head
Backport main modules from v12 to v11 (base_phone, crm_phone, hr_phone, event_phone, hr_recruitment_phone, asterisk_click2dial)
pull/180/head
Alexis de Lattre
6 years ago
20 changed files with 35 additions and 237 deletions
-
4README.md
-
5asterisk_click2dial/__manifest__.py
-
12asterisk_click2dial/scripts/set_name_agi.py
-
0asterisk_click2dial/static/src/css/asterisk.css
-
9asterisk_click2dial/views/web_asterisk_click2dial.xml
-
2base_phone/__manifest__.py
-
75base_phone/common.py
-
61base_phone/fields.py
-
31base_phone/models/base.py
-
17base_phone/models/ir_fields_converter.py
-
9base_phone/models/phone_common.py
-
5base_phone/models/phone_validation_mixin.py
-
29base_phone/static/src/js/phone_widget.js
-
2base_phone/wizard/reformat_all_phonenumbers.py
-
0base_phone_popup/models/phone_common.py
-
0base_phone_popup/views/res_users.xml
-
2crm_phone/__manifest__.py
-
2event_phone/__manifest__.py
-
2hr_phone/__manifest__.py
-
5hr_recruitment_phone/__manifest__.py
@ -1,75 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Akretion (http://www.akretion.com) |
|||
# Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Alexis de Lattre <alexis.delattre@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
|
|||
from . import fields as phone_fields |
|||
import logging |
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
try: |
|||
import phonenumbers |
|||
except ImportError: |
|||
_logger.debug('Cannot `import phonenumbers`.') |
|||
|
|||
|
|||
def convert_phone_field(value, country_code): |
|||
_logger.debug( |
|||
'convert_phone_field value=%s country=%s', value, country_code) |
|||
try: |
|||
res_parse = phonenumbers.parse( |
|||
value, country_code) |
|||
_logger.debug('res_parse=%s', res_parse) |
|||
new_value = phonenumbers.format_number( |
|||
res_parse, phonenumbers.PhoneNumberFormat.E164) |
|||
_logger.debug('new_value=%s', new_value) |
|||
except: |
|||
_logger.error( |
|||
"Cannot reformat the phone number '%s' to " |
|||
"international format with region=%s", |
|||
value, country_code) |
|||
new_value = value |
|||
return new_value |
|||
|
|||
|
|||
def convert_all_phone_fields(self, vals, fields_to_convert): |
|||
loc_vals = vals.copy() |
|||
for field in fields_to_convert: |
|||
country_key = self._fields[field].country_field |
|||
partner_key = self._fields[field].partner_field |
|||
country = False |
|||
if country_key: |
|||
if country_key in loc_vals: |
|||
# Warning: when we edit or create a partner from the |
|||
# POS frontend vals[country_key] is a string ! |
|||
country = self.env['res.country'].browse( |
|||
int(vals[country_key])) |
|||
else: |
|||
country = self[country_key] |
|||
if partner_key and not country: |
|||
if partner_key in loc_vals: |
|||
partner = self.env['res.partner'].browse( |
|||
int(vals[partner_key])) |
|||
else: |
|||
partner = self[partner_key] |
|||
if partner: |
|||
country = partner.country_id |
|||
if not country: |
|||
country = self.env.user.company_id.country_id |
|||
country_code = False |
|||
if country: |
|||
country_code = country.code.upper() |
|||
if loc_vals[field]: |
|||
loc_vals[field] = convert_phone_field( |
|||
loc_vals[field], country_code) |
|||
return loc_vals |
|||
|
|||
|
|||
def get_phone_fields(self, vals): |
|||
fields_to_convert = [] |
|||
for key in vals: |
|||
if isinstance(self._fields.get(key), phone_fields.Fax): |
|||
fields_to_convert.append(key) |
|||
return fields_to_convert |
@ -1,61 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Akretion (http://www.akretion.com) |
|||
# Sébastien BEAU <sebastien.beau@akretion.com> |
|||
# Alexis de Lattre <alexis.delattre@akretion.com> |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
|||
|
|||
|
|||
from odoo import fields |
|||
from operator import attrgetter |
|||
import logging |
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
try: |
|||
import phonenumbers |
|||
except ImportError: |
|||
_logger.debug('Cannot `import phonenumbers`.') |
|||
|
|||
|
|||
class Fax(fields.Char): |
|||
type = 'fax' |
|||
|
|||
_slots = { |
|||
'country_field': None, |
|||
'partner_field': None, |
|||
} |
|||
|
|||
def __init__( |
|||
self, string=fields.Default, country_field=fields.Default, |
|||
partner_field=fields.Default, **kwargs): |
|||
super(Fax, self).__init__( |
|||
string=string, country_field=country_field, |
|||
partner_field=partner_field, **kwargs) |
|||
|
|||
_related_country_field = property(attrgetter('country_field')) |
|||
_related_partner_field = property(attrgetter('partner_field')) |
|||
|
|||
def _setup_regular_full(self, model): |
|||
super(Fax, self)._setup_regular_full(model) |
|||
assert self.country_field in model._fields or \ |
|||
self.partner_field in model._fields, \ |
|||
"field %s with unknown country_field and partner_field" % self |
|||
|
|||
def convert_to_cache(self, value, record, validate=True): |
|||
res = super(Fax, self).convert_to_cache( |
|||
value, record, validate=validate) |
|||
# print 'db value', res |
|||
if res: |
|||
try: |
|||
res_parse = phonenumbers.parse(res) |
|||
res = phonenumbers.format_number( |
|||
res_parse, phonenumbers.PhoneNumberFormat.INTERNATIONAL) |
|||
no_break_space = u'\u00A0' |
|||
res = res.replace(' ', no_break_space) |
|||
except: |
|||
pass |
|||
# print 'cache value', res |
|||
return res |
|||
|
|||
|
|||
class Phone(Fax): |
|||
type = 'phone' |
@ -1,31 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 SYLEAM |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from .. import common |
|||
from odoo import models, api |
|||
|
|||
|
|||
class Base(models.AbstractModel): |
|||
_inherit = 'base' |
|||
|
|||
@api.multi |
|||
def write(self, vals): |
|||
fields_to_convert = common.get_phone_fields(self, vals) |
|||
if fields_to_convert: |
|||
for record in self: |
|||
loc_vals = common.convert_all_phone_fields( |
|||
record, vals, fields_to_convert) |
|||
super(Base, record).write(loc_vals) |
|||
return True |
|||
else: |
|||
return super(Base, self).write(vals) |
|||
|
|||
@api.model |
|||
@api.returns('self', lambda value: value.id) |
|||
def create(self, vals): |
|||
fields_to_convert = common.get_phone_fields(self, vals) |
|||
if fields_to_convert: |
|||
vals = common.convert_all_phone_fields( |
|||
self, vals, fields_to_convert) |
|||
return super(Base, self).create(vals) |
@ -1,17 +0,0 @@ |
|||
# -*- coding: utf-8 -*- |
|||
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>) |
|||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
|||
|
|||
from odoo import models, api |
|||
|
|||
|
|||
class IrFieldsConverter(models.AbstractModel): |
|||
_inherit = 'ir.fields.converter' |
|||
|
|||
@api.model |
|||
def _str_to_phone(self, model, field, value): |
|||
return super(IrFieldsConverter, self)._str_to_char(model, field, value) |
|||
|
|||
@api.model |
|||
def _str_to_fax(self, model, field, value): |
|||
return super(IrFieldsConverter, self)._str_to_char(model, field, value) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue