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
Alexis de Lattre 6 years ago
parent
commit
543159fe89
  1. 4
      README.md
  2. 5
      asterisk_click2dial/__manifest__.py
  3. 12
      asterisk_click2dial/scripts/set_name_agi.py
  4. 0
      asterisk_click2dial/static/src/css/asterisk.css
  5. 9
      asterisk_click2dial/views/web_asterisk_click2dial.xml
  6. 2
      base_phone/__manifest__.py
  7. 75
      base_phone/common.py
  8. 61
      base_phone/fields.py
  9. 31
      base_phone/models/base.py
  10. 17
      base_phone/models/ir_fields_converter.py
  11. 9
      base_phone/models/phone_common.py
  12. 5
      base_phone/models/phone_validation_mixin.py
  13. 29
      base_phone/static/src/js/phone_widget.js
  14. 2
      base_phone/wizard/reformat_all_phonenumbers.py
  15. 0
      base_phone_popup/models/phone_common.py
  16. 0
      base_phone_popup/views/res_users.xml
  17. 2
      crm_phone/__manifest__.py
  18. 2
      event_phone/__manifest__.py
  19. 2
      hr_phone/__manifest__.py
  20. 5
      hr_recruitment_phone/__manifest__.py

4
README.md

@ -1,5 +1,5 @@
[![Build Status](https://travis-ci.org/OCA/connector-telephony.svg?branch=12.0)](https://travis-ci.org/OCA/connector-telephony)
[![Coverage Status](https://coveralls.io/repos/OCA/connector-telephony/badge.png?branch=12.0)](https://coveralls.io/r/OCA/connector-telephony?branch=12.0)
[![Build Status](https://travis-ci.org/OCA/connector-telephony.svg?branch=11.0)](https://travis-ci.org/OCA/connector-telephony)
[![Coverage Status](https://coveralls.io/repos/OCA/connector-telephony/badge.png?branch=11.0)](https://coveralls.io/r/OCA/connector-telephony?branch=11.0)
# Odoo telephony connector

5
asterisk_click2dial/__manifest__.py

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2010-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'Asterisk connector',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Asterisk-Odoo connector',

12
asterisk_click2dial/scripts/set_name_agi.py

@ -115,8 +115,8 @@ options = [
'(will not try to connect to Odoo)'},
{'names': ('-p', '--port'), 'dest': 'port', 'type': 'int',
'action': 'store', 'default': False,
'help': "Port of Odoo's webservice interface. Default = 443 when SSL is on, "
"8069 when SSL is off"},
'help': "Port of Odoo's webservice interface. "
"Default = 443 when SSL is on, 8069 when SSL is off"},
{'names': ('-e', '--ssl'), 'dest': 'ssl',
'help': "Use SSL connections instead of clear connections. "
"Default = no, use clear XML-RPC or JSON-RPC",
@ -235,7 +235,9 @@ def main(options, arguments):
phone_chars += ['+']
if (
agi.env.get('agi_calleridname') and
any([x not in phone_chars for x in agi.env['agi_calleridname']]) and
any([
x not in phone_chars
for x in agi.env['agi_calleridname']]) and
agi.env['agi_calleridname'].lower()
not in ['asterisk', 'unknown', 'anonymous'] and
not options.notify):
@ -296,7 +298,7 @@ def main(options, arguments):
else:
res = odoo.execute('phone.common', method, phone_number)
agi.verbose("Called method %s" % method)
except:
except Exception:
agi.verbose("Could not connect to Odoo in JSON-RPC")
elif options.server:
proto = options.ssl and 'https' or 'http'
@ -317,7 +319,7 @@ def main(options, arguments):
options.database, options.userid, options.password,
'phone.common', method, phone_number)
agi.verbose("Called method %s" % method)
except:
except Exception:
agi.verbose("Could not connect to Odoo in XML-RPC")
# To simulate a long execution of the XML-RPC request
# import time

0
asterisk_click2dial/static/src/scss/asterisk.scss → asterisk_click2dial/static/src/css/asterisk.css

9
asterisk_click2dial/views/web_asterisk_click2dial.xml

@ -7,15 +7,10 @@
<odoo>
<template id="_assets_primary_variables" name="asterisk_click2dial assets"
inherit_id="web._assets_primary_variables">
<xpath expr="//link[last()]" position="after">
<link rel="stylesheet" type="text/scss" href="/asterisk_click2dial/static/src/scss/asterisk.scss"/>
</xpath>
</template>
<template id="assets_backend" name="mail assets" inherit_id="web.assets_backend">
<template id="assets_backend" name="asterisk_click2dial assets" inherit_id="web.assets_backend">
<xpath expr="." position="inside">
<link rel="stylesheet" href="/asterisk_click2dial/static/src/css/asterisk.css"/>
<script type="text/javascript"
src="/asterisk_click2dial/static/src/js/asterisk_click2dial.js"></script>
</xpath>

2
base_phone/__manifest__.py

@ -5,7 +5,7 @@
{
'name': 'Base Phone',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers',

75
base_phone/common.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

61
base_phone/fields.py

@ -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'

31
base_phone/models/base.py

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

17
base_phone/models/ir_fields_converter.py

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

9
base_phone/models/phone_common.py

@ -1,5 +1,6 @@
# -*- coding: utf-8 -*-
# Copyright 2010-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2010-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, api
@ -68,12 +69,12 @@ class PhoneCommon(models.AbstractModel):
_logger.debug("get_record_from_phone_number sql=%s", sql)
self._cr.execute(sql, tuple(sql_args))
res_sql = self._cr.fetchall()
#res_obj = obj.search(domain)
if len(res_sql) > 1:
res_ids = [x[0] for x in res_sql]
_logger.warning(
u"There are several %s (IDS = %s) with a phone number "
"ending with '%s'. Taking the first one.",
obj._name, res_obj.ids, end_number_to_match)
obj._name, res_ids, end_number_to_match)
if res_sql:
obj_id = res_sql[0][0]
res_obj = obj.browse(obj_id)
@ -96,7 +97,7 @@ class PhoneCommon(models.AbstractModel):
senv = False
try:
senv = self.with_context(callerid=True).env[model_name]
except:
except Exception:
continue
if (
hasattr(senv, '_phone_name_sequence') and

5
base_phone/models/phone_validation_mixin.py

@ -13,6 +13,9 @@ class PhoneValidationMixin(models.AbstractModel):
def _phone_get_country(self):
if 'country_id' in self and self.country_id:
return self.country_id
if 'partner_id' in self and self.partner_id and self.partner_id.country_id:
if (
'partner_id' in self and
self.partner_id and
self.partner_id.country_id):
return self.partner_id.country_id
return self.env.user.company_id.country_id

29
base_phone/static/src/js/phone_widget.js

@ -18,27 +18,16 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
var updatedFieldPhone = originalFieldPhone.extend({
/* init: function () {
this._super.apply(this, arguments);
}, */
/* Always enable phone link tel:, not only on small screens */
_canCall: function () {
return true;
},
_renderReadonly: function() {
this._super();
if (this.mode == "readonly") {
var self = this;
var phone_num = this.value;
/* if(phone_num) {
phone_num = phone_num.replace(/ /g, '').replace(/-/g, '');
} */
/* var click2dial_text = '';
if (phone_num && !this.options.dial_button_invisible) {
click2dial_text = _t('Dial');
}
this.$el.filter('#click2dial').off('click');
this.$el.filter('#click2dial')
.text(click2dial_text)
.attr('href', '#')
} */
this.$el.filter('a[href^="tel:"]').off('click');
this.$el.filter('a[href^="tel:"]')
.on('click', function(ev) {
@ -86,16 +75,6 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
}
});
// To avoid conflicts, we check that widgets do not exist before using
/*
if(!core.form_widget_registry.get('fax')){
core.form_widget_registry.add('fax', FieldFax);
}
if(!core.form_widget_registry.get('phone')){
core.form_widget_registry.add('phone', FieldPhone);
}
*/
fieldRegistry.add('phone', updatedFieldPhone);

2
base_phone/wizard/reformat_all_phonenumbers.py

@ -3,7 +3,7 @@
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
from odoo import models, fields, api
from odoo import models, fields
import logging
logger = logging.getLogger(__name__)

0
base_phone_popup/popup.py → base_phone_popup/models/phone_common.py

0
base_phone_popup/res_users_view.xml → base_phone_popup/views/res_users.xml

2
crm_phone/__manifest__.py

@ -5,7 +5,7 @@
{
'name': 'CRM Phone',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers in CRM',

2
event_phone/__manifest__.py

@ -6,7 +6,7 @@
{
'name': 'Event Phone',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers in Events',

2
hr_phone/__manifest__.py

@ -5,7 +5,7 @@
{
'name': 'HR Phone',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers in HR',

5
hr_recruitment_phone/__manifest__.py

@ -1,10 +1,11 @@
# -*- coding: utf-8 -*-
# Copyright 2014-2018 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
# Copyright 2014-2018 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
{
'name': 'HR Recruitment Phone',
'version': '12.0.1.0.0',
'version': '11.0.1.0.0',
'category': 'Phone',
'license': 'AGPL-3',
'summary': 'Validate phone numbers in HR Recruitment',

Loading…
Cancel
Save