[REF] sale: adapt code after jQuery update

Part of task 1896658

Co-authored-by: Aaron Bohy <aab@odoo.com>
Co-authored-by: Christophe Matthieu <chm@odoo.com>
Co-authored-by: Mathieu Duckerts-Antoine <dam@odoo.com>
Co-authored-by: David Monjoie <dmo@odoo.com>
Co-authored-by: Martin Geubelle <mge@odoo.com>
Co-authored-by: svs-odoo <svs@odoo.com>
Co-authored-by: Vincent Schippefilt <vsc@odoo.com>
This commit is contained in:
Vincent Schippefilt
2019-03-06 20:07:17 +01:00
committed by Aaron Bohy
co-authored by Aaron Bohy Christophe Matthieu Mathieu Duckerts-Antoine David Monjoie Martin Geubelle svs-odoo
parent cae1f71b75
commit bc76549a7d
7 changed files with 49 additions and 46 deletions
@@ -94,14 +94,12 @@ var ProductConfiguratorFormController = FormController.extend({
];
var productId = parseInt($modal.find(productSelector.join(', ')).first().val(), 10);
var productReady = this.renderer.selectOrCreateProduct(
this.renderer.selectOrCreateProduct(
$modal,
productId,
$modal.find('.product_template_id').val(),
false
);
productReady.done(function (productId) {
).then(function (productId) {
$modal.find(productSelector.join(', ')).val(productId);
var variantValues = self
@@ -280,25 +280,25 @@ var ProductConfiguratorMixin = {
},
/**
* Will return a deferred:
* Will return a promise:
*
* - If the product already exists, immediately resolves it with the product_id
* - If the product does not exist yet ("dynamic" variant creation), this method will
* create the product first and then resolve the deferred with the created product's id
* create the product first and then resolve the promise with the created product's id
*
* @param {$.Element} $container the container to look into
* @param {integer} productId the product id
* @param {integer} productTemplateId the corresponding product template id
* @param {boolean} useAjax wether the rpc call should be done using ajax.jsonRpc or using _rpc
* @returns {$.Deferred} the deferred that will be resolved with a {integer} productId
* @returns {Promise} the promise that will be resolved with a {integer} productId
*/
selectOrCreateProduct: function ($container, productId, productTemplateId, useAjax) {
var self = this;
productId = parseInt(productId);
productTemplateId = parseInt(productTemplateId);
var productReady = $.Deferred();
var productReady = Promise.resolve();
if (productId) {
productReady.resolve(productId);
productReady = Promise.resolve(productId);
} else {
var params = {
product_template_id: productTemplateId,
@@ -103,7 +103,7 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi
});
var parentInit = self._super.apply(self, arguments);
return $.when(getModalContent, parentInit);
return Promise.all([getModalContent, parentInit]);
},
/**
@@ -124,7 +124,7 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi
self.$modal.removeAttr("aria-hidden");
self.$modal.modal().appendTo(self.container);
self.$modal.focus();
self._opened.resolve();
self._openedResolver();
}
});
if (options && options.shouldFocusButtons) {
@@ -353,14 +353,12 @@ var OptionalProductsModal = Dialog.extend(ServicesMixin, ProductConfiguratorMixi
$main_product.after($parent);
}
var productReady = this.selectOrCreateProduct(
this.selectOrCreateProduct(
$parent,
$parent.find('.product_id').val(),
productTemplateId,
true
);
productReady.done(function (productId){
).then(function (productId) {
$parent.find('.product_id').val(productId);
ajax.jsonRpc(self._getUri("/product_configurator/optional_product_items"), 'call', {
@@ -16,8 +16,10 @@ var ProductConfiguratorFormRenderer = FormRenderer.extend(ProductConfiguratorMix
* @override
*/
start: function () {
this._super.apply(this, arguments);
this.$el.append($('<div>', {class: 'configurator_container'}));
var self = this;
return this._super.apply(this, arguments).then(function () {
self.$el.append($('<div>', {class: 'configurator_container'}));
});
},
//--------------------------------------------------------------------------
+6 -5
View File
@@ -39,7 +39,6 @@ KanbanRecord.include({
* Mostly a handler for what happens to the input "this.$target_input"
*
* @private
* @param {JqueryEvent} ev
*
*/
_onSalesTeamTargetSet: function () {
@@ -48,10 +47,12 @@ KanbanRecord.include({
if (isNaN(value)) {
this.do_warn(_t("Wrong value entered!"), _t("Only Integer Value should be valid."));
} else {
this.trigger_up('kanban_record_update', {invoiced_target: value});
this.trigger_up('reload');
// TODO: previous lines can be refactored as follows (in master)
// self.trigger_up('kanban_record_update', {invoiced_target: value});
this.trigger_up('kanban_record_update', {
invoiced_target: value,
onSuccess: function () {
self.trigger_up('reload');
},
});
}
},
});
@@ -91,12 +91,12 @@ odoo.define('sale.product.configurator.tests', function (require) {
}
}
};
}
},
}, function (){
QUnit.test('click on "Configure a product" and check for form loading', function (assert) {
QUnit.test('click on "Configure a product" and check for form loading', async function (assert) {
assert.expect(2);
var form = createView({
var form = await createView({
View: FormView,
model: 'sale_order',
data: this.data,
@@ -104,25 +104,26 @@ odoo.define('sale.product.configurator.tests', function (require) {
mockRPC: function (route) {
if (route === '/web/dataset/call_kw/ir.model.data/xmlid_to_res_id') {
assert.ok(true);
return $.Deferred().then(_.constant(1));
return Promise.resolve(1);
}
return this._super.apply(this, arguments);
},
});
assert.strictEqual(form.$("a:contains('Configure a product')").length, 1);
assert.containsOnce(form, "a:contains('Configure a product')");
testUtils.dom.click(form.$("a:contains('Configure a product')"));
await testUtils.dom.click(form.$("a:contains('Configure a product')"));
form.destroy();
});
QUnit.test('trigger_up the "add_record" event and checks that rows are correctly added to the list', function (assert) {
QUnit.test('trigger_up the "add_record" event and checks that rows are correctly added to the list', async function (assert) {
assert.expect(1);
var form = createView({
var form = await createView({
View: FormView,
model: 'sale_order',
data: this.data,
arch: getArch()
arch: getArch(),
});
var list = form.renderer.allFieldWidgets[form.handle][1];
@@ -132,14 +133,16 @@ odoo.define('sale.product.configurator.tests', function (require) {
forceEditable: "bottom" ,
allowWarning: true
});
await testUtils.nextTick();
assert.strictEqual(list.$("tr.o_data_row").length, 2);
assert.containsN(list, "tr.o_data_row", 2);
form.destroy();
});
QUnit.test('Select a product in the list and check for template loading', function (assert){
QUnit.test('Select a product in the list and check for template loading', async function (assert){
assert.expect(1);
var product_configurator_form = createView({
var product_configurator_form = await createView({
View: ProductConfiguratorFormView,
model: 'sale_product_configurator',
data: this.data,
@@ -156,13 +159,14 @@ odoo.define('sale.product.configurator.tests', function (require) {
mockRPC: function (route) {
if (route === '/product_configurator/configure') {
assert.ok(true);
return $.Deferred().then(_.constant(1));
return Promise.resolve('<div>plop</div>');
}
return this._super.apply(this, arguments);
}
});
testUtils.dom.click(product_configurator_form.$('.o_input'));
testUtils.dom.click($("ul.ui-autocomplete li a:contains('Customizable Desk')").mouseenter());
await testUtils.dom.click(product_configurator_form.$('.o_input'));
await testUtils.dom.click($("ul.ui-autocomplete li a:contains('Customizable Desk')").mouseenter());
product_configurator_form.destroy();
});
});
});
@@ -22,10 +22,10 @@ QUnit.module('Sales Team Dashboard', {
}
});
QUnit.test('edit target with several o_kanban_primary_bottom divs [REQUIRE FOCUS]', function (assert) {
QUnit.test('edit target with several o_kanban_primary_bottom divs [REQUIRE FOCUS]', async function (assert) {
assert.expect(6);
var kanban = createView({
var kanban = await createView({
View: KanbanView,
model: 'crm.team',
data: this.data,
@@ -60,24 +60,24 @@ QUnit.test('edit target with several o_kanban_primary_bottom divs [REQUIRE FOCUS
assert.containsN(kanban, '.o_kanban_primary_bottom', 2,
"should have two divs with classname 'o_kanban_primary_bottom'");
testUtils.dom.click(kanban.$('a.sales_team_target_definition'));
await testUtils.dom.click(kanban.$('a.sales_team_target_definition'));
assert.containsOnce(kanban, '.o_kanban_primary_bottom:last input',
"should have rendered an input in the last o_kanban_primary_bottom div");
kanban.$('.o_kanban_primary_bottom:last input').focus();
kanban.$('.o_kanban_primary_bottom:last input').val('123');
kanban.$('.o_kanban_primary_bottom:last input').blur();
kanban.$('.o_kanban_primary_bottom:last input').trigger('blur');
await testUtils.nextTick();
assert.strictEqual(kanban.$('.o_kanban_record').text(), "123Click to define a target",
'The kanban record should display the updated target value');
kanban.destroy();
});
QUnit.test('edit target supports push Enter', function (assert) {
QUnit.test('edit target supports push Enter', async function (assert) {
assert.expect(3);
var kanban = createView({
var kanban = await createView({
View: KanbanView,
model: 'crm.team',
data: this.data,
@@ -107,12 +107,12 @@ QUnit.test('edit target supports push Enter', function (assert) {
},
});
kanban.$('a.sales_team_target_definition').click();
await testUtils.dom.click(kanban.$('a.sales_team_target_definition'));
kanban.$('.o_kanban_primary_bottom:last input').focus();
kanban.$('.o_kanban_primary_bottom:last input').val('123');
kanban.$('.o_kanban_primary_bottom:last input').trigger($.Event('keydown', {which: $.ui.keyCode.ENTER, keyCode: $.ui.keyCode.ENTER}));
await testUtils.nextTick();
assert.strictEqual(kanban.$('.o_kanban_record').text(), "123Click to define a target",
'The kanban record should display the updated target value');