Browse Source

Merge pull request #180 from akretion/11-imp-base_phone_click2dial

[11.0] Restore Dial button for click2dial
11.0
Alexis de Lattre 6 years ago
committed by GitHub
parent
commit
a0735a5f31
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      .travis.yml
  2. 28
      asterisk_click2dial/static/src/js/asterisk_click2dial.js
  3. 10
      asterisk_click2dial/views/asterisk_server.xml
  4. 129
      base_phone/static/src/js/phone_widget.js
  5. 3
      base_phone/tests/__init__.py
  6. 69
      base_phone/tests/test_phone.py
  7. 82
      crm_phone/tests/test_crm_phone.py
  8. 5
      crm_phone/wizard/create_crm_phonecall.py

2
.travis.yml

@ -15,7 +15,7 @@ python:
env:
global:
- VERSION="12.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- VERSION="11.0" TESTS="0" LINT_CHECK="0" TRANSIFEX="0"
- TRANSIFEX_USER='transbot@odoo-community.org'
- secure: LhS+tozOz65gNeGs3yQ4WQOJ6o4fljCHp/bAyHXj4QqB4NkRj7ajO92ZasvtWA4BbxDjsz+Rie3Ct9zq0Zmg05rCT58TYxoqnq2+rN+ZOqr46VYnzIk4MapHNXLQuXhAfTVqsJRdpJteF7nn2wnnc3ZDAIJTfLmP8v789iIbCcA=

28
asterisk_click2dial/static/src/js/asterisk_click2dial.js

@ -7,12 +7,18 @@ odoo.define('asterisk_click2dial.systray.OpenCaller', function (require) {
var core = require('web.core');
var SystrayMenu = require('web.SystrayMenu');
var web_client = require('web.web_client');
var Widget = require('web.Widget');
var _t = core._t;
var click2dial = {};
var FieldPhone = require('base_phone.updatedphone_widget').FieldPhone;
FieldPhone.include({
showDialButton: function () {
return true;
}
});
var OpenCallerMenu = Widget.extend({
@ -22,10 +28,6 @@ var OpenCallerMenu = Widget.extend({
'click': 'on_open_caller',
},
start: function () {
this._super();
},
on_open_caller: function (event) {
event.stopPropagation();
var self = this;
@ -33,14 +35,14 @@ var OpenCallerMenu = Widget.extend({
self._rpc({
route: '/asterisk_click2dial/get_record_from_my_channel',
params: {local_context: context, },
}).done(function(r) {
}).then(function(r) {
// console.log('RESULT RPC r='+r);
// console.log('RESULT RPC type r='+typeof r);
// console.log('RESULT RPC isNaN r='+isNaN(r));
if (r === false) {
self.do_warn(
_t('Failure'),
_t('Problem in the connection to Asterisk'),
_t('IPBX error'),
_t('Calling party number not retreived from IPBX or IPBX unreachable by Odoo'),
false);
}
else if (typeof r == 'string' && isNaN(r)) {
@ -59,13 +61,13 @@ var OpenCallerMenu = Widget.extend({
target: 'new',
context: {'default_calling_number': r},
};
web_client.action_manager.do_action(action);
self.do_action(action);
}
else if (typeof r == 'object' && r.length == 3) {
self.do_notify(
_t('Success'),
_.str.sprintf(_t('Moving to %s ID %d'), r[0], r[1]),
_.str.sprintf(_t("On the phone with '%s'"), r[2]),
_.str.sprintf(_t("Moving to form view of '%s' (%s ID %d)"), r[2], r[0], r[1]),
false);
var action = {
type: 'ir.actions.act_window',
@ -83,7 +85,7 @@ var OpenCallerMenu = Widget.extend({
target: 'current',
context: {},
};
web_client.action_manager.do_action(action);
self.do_action(action);
}
});
},

10
asterisk_click2dial/views/asterisk_server.xml

@ -14,6 +14,8 @@
<search string="Asterisk Server Search">
<field name="name"
filter_domain="['|', ('name', 'ilike', self), ('ip_address', 'ilike', self)]"/>
<separator/>
<filter string="Archived" name="inactive" domain="[('active', '=', False)]"/>
</search>
</field>
</record>
@ -24,6 +26,13 @@
<field name="arch" type="xml">
<form string="Asterisk Servers">
<sheet>
<div class="oe_button_box" name="button_box">
<button name="toggle_active" type="object"
class="oe_stat_button" icon="fa-archive">
<field name="active" widget="boolean_button"
options='{"terminology": "archive"}'/>
</button>
</div>
<div class="oe_title">
<label for="name" string="Server Name" class="oe_edit_only"/>
<h1>
@ -33,7 +42,6 @@
<group name="main">
<field name="company_id"
groups="base.group_multi_company"/>
<field name="active" />
</group>
<group name="ami" string="Asterisk Manager Interface">
<field name="ip_address" />

129
base_phone/static/src/js/phone_widget.js

@ -8,76 +8,91 @@ odoo.define('base_phone.updatedphone_widget', function (require) {
var core = require('web.core');
var web_client = require('web.web_client');
var basicFields = require('web.basic_fields');
var InputField = basicFields.InputField;
var originalFieldPhone = basicFields.FieldPhone;
var fieldRegistry = require('web.field_registry');
var QWeb = core.qweb;
var FieldPhone = require('web.basic_fields').FieldPhone;
var _t = core._t;
var updatedFieldPhone = originalFieldPhone.extend({
FieldPhone.include({
/* Always enable phone link tel:, not only on small screens */
_canCall: function () {
return true;
},
showDialButton: function () {
// must be inherited by ipbx specific modules
// and set to true
return false;
},
_renderReadonly: function() {
// create a link to trigger action on server
// this link will be after the <a href="tel:">
this._super();
if (this.mode == "readonly") {
var self = this;
var phone_num = this.value;
this.$el.filter('a[href^="tel:"]').off('click');
this.$el.filter('a[href^="tel:"]')
.on('click', function(ev) {
self.do_notify(
_t('Click2dial started'),
_t('Unhook your ringing phone'),
false);
var arg = {
'phone_number': phone_num,
'click2dial_model': self.model,
'click2dial_id': self.res_id};
self._rpc({
route: '/base_phone/click2dial',
params: arg,
}).done(function(r) {
// TODO: check why it never goes in there
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,
false);
if (r.action_model) {
var context = {
'click2dial_model': self.model,
'click2dial_id': self.res_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,
};
this.do_action(action);
}
}
});
});
if (!this.showDialButton()) {
return;
}
}
});
var self = this;
// create our link
var dial = $('<a href="#" class="dial"><div class="label label-primary">☎ Dial</div></a>');
fieldRegistry.add('phone', updatedFieldPhone);
// add a parent element
// it's not possible to append to $el directly
// because $el don't have any parent yet
var parent = $('<div>');
parent.append([this.$el[0], ' ', dial]);
return updatedFieldPhone;
// replace this.$el by our new container
this.$el = parent;
var phone_num = this.value;
dial.click(function(evt) {
self.click2dial(phone_num);
});
},
click2dial: function(phone_num) {
var self = this;
this.do_notify(
_.str.sprintf(_t('Click2dial to %s'), phone_num),
_t('Unhook your ringing phone'),
false);
var params = {
'phone_number': phone_num,
'click2dial_model': this.model,
'click2dial_id': this.res_id};
return this._rpc({
route: '/base_phone/click2dial',
params: params,
}).then(function(r) {
console.log('successfull', r);
if (r === false) {
self.do_warn("Click2dial failed");
} else if (typeof r === 'object') {
self.do_notify(
_t('Click2dial successfull'),
_.str.sprintf(_t('Number dialed: %s'), r.dialed_number),
false);
if (r.action_model) {
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: params,
};
return self.do_action(action);
}
}
}, function (r) {
console.log('on error');
self.do_warn("Click2dial failed");
});
}
});
return {
'FieldPhone': FieldPhone
};
});

3
base_phone/tests/__init__.py

@ -1,3 +0,0 @@
# -*- coding: utf-8 -*-
from . import test_phone

69
base_phone/tests/test_phone.py

@ -1,69 +0,0 @@
# -*- coding: utf-8 -*-
# Copyright 2016-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.tests.common import TransactionCase
class TestPhone(TransactionCase):
def test_phone(self):
company = self.env.ref('base.main_company')
fr_country_id = self.env.ref('base.fr').id
company.country_id = fr_country_id
rpo = self.env['res.partner']
# Create an existing partner without country
partner1 = rpo.create({
'name': u'Pierre Paillet',
'phone': '04-72-08-87-32',
'mobile': '06.42.77.42.66',
'fax': '(0) 1 45 42 12 42',
})
self.assertEquals(partner1.phone, u'+33 4 72 08 87 32')
self.assertEquals(partner1.mobile, u'+33 6 42 77 42 66')
self.assertEquals(partner1.fax, u'+33 1 45 42 12 42')
# Create a partner with country
self.env.ref('base.res_partner_12').country_id =\
self.env.ref('base.ch').id
partner2 = rpo.create({
'name': u'Joël Grand-Guillaume',
'parent_id': self.env.ref('base.res_partner_12').id,
'phone': '(0) 21 619 10 10',
'mobile': '(0) 79 606 42 42',
})
self.assertEquals(partner2.country_id, self.env.ref('base.ch'))
self.assertEquals(partner2.phone, u'+41 21 619 10 10')
self.assertEquals(partner2.mobile, u'+41 79 606 42 42')
# Write on an existing partner
agrolait = self.env.ref('base.res_partner_2')
self.assertEquals(agrolait.country_id, self.env.ref('base.be'))
agrolait.write({'phone': '(0) 2 391 43 74'})
self.assertEquals(agrolait.phone, u'+32 2 391 43 74')
# Write on an existing partner with country at the same time
agrolait.write({
'fax': '04 72 89 32 43',
'country_id': fr_country_id,
})
self.assertEquals(agrolait.fax, u'+33 4 72 89 32 43')
# Write an invalid phone number
partner2.fax = '42'
self.assertEquals(partner2.fax, u'42')
# Test get_name_from_phone_number
pco = self.env['phone.common']
name = pco.get_name_from_phone_number('0642774266')
self.assertEquals(name, 'Pierre Paillet')
name2 = pco.get_name_from_phone_number('0041216191010')
self.assertEquals(name2, u'Joël Grand-Guillaume (Camptocamp)')
# Test against the POS bug
# https://github.com/OCA/connector-telephony/issues/113
# When we edit/create a partner from the POS,
# the country_id key in create(vals) is given as a string !
partnerpos = rpo.create({
'name': u'POS customer',
'phone': '04-72-08-87-42',
'country_id': str(fr_country_id),
})
self.assertEquals(partnerpos.phone, u'+33 4 72 08 87 42')
self.assertEquals(partnerpos.country_id.id, fr_country_id)

82
crm_phone/tests/test_crm_phone.py

@ -1,5 +1,4 @@
# -*- coding: utf-8 -*-
# Copyright 2016-2018 Akretion France
# Copyright 2016-2019 Akretion France
# @author: Alexis de Lattre <alexis.delattre@akretion.com>
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
@ -8,6 +7,71 @@ from odoo.tests.common import TransactionCase
class TestCRMPhone(TransactionCase):
def test_phone(self):
company = self.env.ref('base.main_company')
fr_country_id = self.env.ref('base.fr').id
company.country_id = fr_country_id
rpo = self.env['res.partner']
# Create an existing partner without country
partner1 = rpo.create({
'name': 'Pierre Paillet',
'phone': '04-72-08-87-32',
'mobile': '06.42.77.42.66',
})
partner1._onchange_phone_validation()
partner1._onchange_mobile_validation()
self.assertEquals(partner1.phone, '+33 4 72 08 87 32')
self.assertEquals(partner1.mobile, '+33 6 42 77 42 66')
# Create a partner with country
parent_partner2 = rpo.create({
'name': 'C2C',
'country_id': self.env.ref('base.ch').id,
})
partner2 = rpo.create({
'name': 'Joël Grand-Guillaume',
'parent_id': parent_partner2.id,
'phone': '(0) 21 619 10 10',
'mobile': '(0) 79 606 42 42',
})
partner2._onchange_phone_validation()
partner2._onchange_mobile_validation()
self.assertEquals(partner2.country_id, self.env.ref('base.ch'))
self.assertEquals(partner2.phone, '+41 21 619 10 10')
self.assertEquals(partner2.mobile, '+41 79 606 42 42')
# Write on an existing partner
partner3 = rpo.create({
'name': 'Belgian corp',
'country_id': self.env.ref('base.be').id,
})
partner3.write({'phone': '(0) 2 391 43 74'})
partner3._onchange_phone_validation()
self.assertEquals(partner3.phone, '+32 2 391 43 74')
# Write on an existing partner with country at the same time
partner3.write({
'phone': '04 72 89 32 43',
'country_id': fr_country_id,
})
partner3._onchange_phone_validation()
self.assertEquals(partner3.phone, '+33 4 72 89 32 43')
# Test get_name_from_phone_number
pco = self.env['phone.common']
name = pco.get_name_from_phone_number('0642774266')
self.assertEquals(name, 'Pierre Paillet')
name2 = pco.get_name_from_phone_number('0041216191010')
self.assertEquals(name2, 'C2C, Joël Grand-Guillaume')
# Test against the POS bug
# https://github.com/OCA/connector-telephony/issues/113
# When we edit/create a partner from the POS,
# the country_id key in create(vals) is given as a string !
partnerpos = rpo.create({
'name': 'POS customer',
'phone': '04-72-08-87-42',
'country_id': str(fr_country_id),
})
partnerpos._onchange_phone_validation()
self.assertEquals(partnerpos.phone, '+33 4 72 08 87 42')
self.assertEquals(partnerpos.country_id.id, fr_country_id)
def test_crm_phone(self):
clo = self.env['crm.lead']
lead1 = clo.create({
@ -18,23 +82,23 @@ class TestCRMPhone(TransactionCase):
'country_id': self.env.ref('base.fr').id,
})
lead1._onchange_mobile_validation()
self.assertEquals(lead1.mobile, u'+33 6 42 77 42 77')
self.assertEquals(lead1.mobile, '+33 6 42 77 42 77')
lead2 = clo.create({
'name': u'Automobile Odoo deployment',
'partner_name': u'Kia',
'contact_name': u'Mikaël Content',
'name': 'Automobile Odoo deployment',
'partner_name': 'Kia',
'contact_name': 'Mikaël Content',
'country_id': self.env.ref('base.ch').id,
'phone': '04 31 23 45 67',
})
lead2._onchange_phone_validation()
self.assertEquals(lead2.phone, u'+41 43 123 45 67')
self.assertEquals(lead2.phone, '+41 43 123 45 67')
lead3 = clo.create({
'name': 'Angela Strasse',
'country_id': self.env.ref('base.de').id,
'phone': '08912345678',
})
lead3._onchange_phone_validation()
self.assertEquals(lead3.phone, u'+49 89 12345678')
self.assertEquals(lead3.phone, '+49 89 12345678')
partner4 = self.env['res.partner'].create({
'name': 'Belgian Guy',
'country_id': self.env.ref('base.be').id,
@ -45,7 +109,7 @@ class TestCRMPhone(TransactionCase):
'mobile': '(0) 2-391-43-75',
})
lead4._onchange_mobile_validation()
self.assertEquals(lead4.mobile, u'+32 2 391 43 75')
self.assertEquals(lead4.mobile, '+32 2 391 43 75')
pco = self.env['phone.common']
name = pco.get_name_from_phone_number('0642774277')
self.assertEquals(name, 'Jacques Toufaux (Ford)')

5
crm_phone/wizard/create_crm_phonecall.py

@ -30,15 +30,12 @@ class WizardCreateCrmPhonecall(models.TransientModel):
'default_direction': direction,
'default_team_id': teams and teams[0].id or False,
})
domain = False
if self.env.context.get('click2dial_model') == 'res.partner':
partner_id = self.env.context.get('click2dial_id')
action_ctx['default_partner_id'] = partner_id
domain = [('partner_id', 'child_of', partner_id)]
elif self.env.context.get('click2dial_model') == 'crm.lead':
lead_id = self.env.context.get('click2dial_id')
action_ctx['default_opportunity_id'] = lead_id
domain = [('opportunity_id', '=', lead_id)]
parsed_num = phonenumbers.parse(self.env.context.get('phone_number'))
number_type = phonenumbers.number_type(parsed_num)
if number_type == 1:
@ -50,8 +47,8 @@ class WizardCreateCrmPhonecall(models.TransientModel):
action = self.env['ir.actions.act_window'].for_xml_id(
'crm_phone', 'crm_phonecall_action')
action.update({
'domain': domain,
'view_mode': 'form,tree,calendar',
'views': False,
'context': action_ctx,
})
return action
Loading…
Cancel
Save