summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2020-01-16 14:59:05 +0000
committerAaron Bohy <aab@odoo.com>2020-01-21 11:59:22 +0000
commit50bf8309f88fb6c8d8e27b14d40450e92e5a4e4e (patch)
tree00b7deea11b94ec69ea6779b87644c39a750ab65 /addons/web/static/tests/fields
parent01e3a5996f9fab841be270b84f0877d0b8b9fc37 (diff)
[FIX] web,*: fix race condition with m2o quick create
*sale,sale_product_configurator Let's assume a form view containing a many2one with an onchange that updates the value of a one2many. Do a quick create in the many2one. While the name_create request is pending, add a row to the one2many but do not leave it. When the name_create returns, and the onchange has been performed, the one2many is reset, and the row is no longer in edition (worse, it could be invalid, i.e. in a state that the user could not have reached in a normal situation). This commit fixes this issue by considering the whole [name_create + onchange] operation as one. This operation is executed in the mutex of the model, so the other request (adding a row to the one2many) is delayed until the many2one value has been correctly set. This fixes an issue with the sale and rental tours (on sale_order), that had been deactivated for a while.
Diffstat (limited to 'addons/web/static/tests/fields')
-rw-r--r--addons/web/static/tests/fields/relational_fields/field_many2one_tests.js1
-rw-r--r--addons/web/static/tests/fields/relational_fields/field_one2many_tests.js50
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js23
3 files changed, 74 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
index 8c84cf4edf2..46c6ebbe798 100644
--- a/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
+++ b/addons/web/static/tests/fields/relational_fields/field_many2one_tests.js
@@ -967,6 +967,7 @@ QUnit.module('fields', {}, function () {
},
});
var parent = new StandaloneWidget(model);
+ model.setParent(parent);
testUtils.mock.addMockEnvironment(parent, {
data: self.data,
mockRPC: function (route, args) {
diff --git a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
index 60f3398c88c..8aacf099de4 100644
--- a/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
+++ b/addons/web/static/tests/fields/relational_fields/field_one2many_tests.js
@@ -8741,6 +8741,56 @@ QUnit.module('fields', {}, function () {
form.destroy();
});
+ QUnit.test('one2many reset by onchange (of another field) while being edited', async function (assert) {
+ // In this test, we have a many2one and a one2many. The many2one has an onchange that
+ // updates the value of the one2many. We set a new value to the many2one (name_create)
+ // such that the onchange is delayed. During the name_create, we click to add a new row
+ // to the one2many. After a while, we unlock the name_create, which triggers the onchange
+ // and resets the one2many. At the end, we want the row to be in edition.
+ assert.expect(3);
+
+ const prom = testUtils.makeTestPromise();
+ this.data.partner.onchanges = {
+ trululu: obj => {
+ obj.p = [[5]].concat(obj.p);
+ },
+ };
+
+ const form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: `
+ <form>
+ <field name="trululu"/>
+ <field name="p">
+ <tree editable="top"><field name="product_id" required="1"/></tree>
+ </field>
+ </form>`,
+ mockRPC: function (route, args) {
+ const result = this._super.apply(this, arguments);
+ if (args.method === 'name_create') {
+ return prom.then(() => result);
+ }
+ return result;
+ },
+ });
+
+ // set a new value for trululu (will delay the onchange)
+ await testUtils.fields.many2one.searchAndClickItem('trululu', {search: 'new value'});
+
+ // add a row in p
+ await testUtils.dom.click(form.$('.o_field_x2many_list_row_add a'));
+ assert.containsNone(form, '.o_data_row');
+
+ // resolve the name_create to trigger the onchange, and the reset of p
+ prom.resolve();
+ await testUtils.nextTick();
+ assert.containsOnce(form, '.o_data_row');
+ assert.hasClass(form.$('.o_data_row'), 'o_selected_row');
+
+ form.destroy();
+ });
});
});
});
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index c3f9a95ea7d..41f7a86afc4 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -1914,6 +1914,29 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('fieldmany2many tags: quick create a new record', async function (assert) {
+ assert.expect(3);
+
+ const form = await createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: `<form><field name="timmy" widget="many2many_tags"/></form>`,
+ });
+
+ assert.containsNone(form, '.o_field_many2manytags .badge');
+
+ await testUtils.fields.many2one.searchAndClickItem('timmy', {search: 'new value'});
+
+ assert.containsOnce(form, '.o_field_many2manytags .badge');
+
+ await testUtils.form.clickSave(form);
+
+ assert.strictEqual(form.el.querySelector('.o_field_many2manytags').innerText, 'new value');
+
+ form.destroy();
+ });
+
QUnit.module('FieldRadio');
QUnit.test('fieldradio widget on a many2one in a new record', async function (assert) {