summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/fields/relational_fields_tests.js
diff options
context:
space:
mode:
authorAaron Bohy <aab@odoo.com>2017-05-31 08:55:24 +0200
committerAaron Bohy <aab@odoo.com>2017-05-31 20:53:55 +0200
commitf9a1241721d1457dd7ddd0eebb1ec0ba4fba3225 (patch)
tree1ee5226cf3bbc54e5fefa1febaccb953bc0d47ff /addons/web/static/tests/fields/relational_fields_tests.js
parent23613b411feb6571c0f2907d8c88a7e8f8e39d87 (diff)
[FIX] web: editable list: don't create invalid records
Clicking multiple times on 'Create' (in main list views) or 'Add an item' (in o2m lists) might create invalid rows (i.e. rows with required fields unset). Creating a new record requires two sequential RPCs: a default_get and an onchange (only if there is an onchange of one of the record's field). When clicking twice to create a new record, that sequence of RPCs is done twice in parallel, after unselecting the current row (i.e. saving it if it is valid). However, in both cases, there is no line to unselect yet (as both operations are done basically simultaneously). When the first onchange returns, a first new record is added to the list. When the second returns, the second one is added and takes the edition, leaving the first one, invalid, in the list. This rev. ensures this doesn't happen by preventing concurrent record creation.
Diffstat (limited to 'addons/web/static/tests/fields/relational_fields_tests.js')
-rw-r--r--addons/web/static/tests/fields/relational_fields_tests.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/addons/web/static/tests/fields/relational_fields_tests.js b/addons/web/static/tests/fields/relational_fields_tests.js
index 916325b64b7..73aa28730e2 100644
--- a/addons/web/static/tests/fields/relational_fields_tests.js
+++ b/addons/web/static/tests/fields/relational_fields_tests.js
@@ -3699,6 +3699,51 @@ QUnit.module('relational_fields', {
form.destroy();
});
+ QUnit.test('editable list: multiple clicks on Add an item do not create invalid rows', function (assert) {
+ assert.expect(3);
+
+ this.data.turtle.onchanges = {
+ turtle_trululu: function () {},
+ };
+
+ var def;
+ var form = createView({
+ View: FormView,
+ model: 'partner',
+ data: this.data,
+ arch: '<form string="Partners">' +
+ '<field name="turtles">' +
+ '<tree editable="bottom">' +
+ '<field name="turtle_trululu" required="1"/>' +
+ '</tree>' +
+ '</field>' +
+ '</form>',
+ mockRPC: function (route, args) {
+ var result = this._super.apply(this, arguments);
+ if (args.method === 'onchange') {
+ return $.when(def).then(_.constant(result));
+ }
+ return result;
+ },
+ });
+
+ // click twice to add a new line
+ def = $.Deferred();
+ form.$('.o_field_x2many_list_row_add a').click();
+ form.$('.o_field_x2many_list_row_add a').click();
+ assert.strictEqual(form.$('.o_data_row').length, 0,
+ "no row should have been created yet (waiting for the onchange)");
+
+ // resolve the onchange def
+ def.resolve();
+ assert.strictEqual(form.$('.o_data_row').length, 1,
+ "only one row should have been created");
+ assert.ok(form.$('.o_data_row:first').hasClass('o_selected_row'),
+ "the created row should be in edition");
+
+ form.destroy();
+ });
+
QUnit.module('FieldMany2Many');
QUnit.test('many2many kanban: edition', function (assert) {