From 88b4938b7ce7ff2cf76f2381303da8bb62960e58 Mon Sep 17 00:00:00 2001 From: Jorge Pinna Puissant Date: Tue, 11 Jul 2023 13:58:11 +0000 Subject: [PATCH] [FIX] web: one2many, await onchange when resequence - On an one2many; - drag and drop two records; - a resequence is called, with an onchange; - click save; Before this commit, if the network was a little too slow, the return of the onchange wasn't taken it into account for the save. Now, we await the onchange of the resequence before executing another action. Task 3179751 Part-of: odoo/odoo#114024 --- .../src/model/relational_model/static_list.js | 2 +- .../views/fields/one2many_field_tests.js | 55 ++++++++++++++++++- 2 files changed, 55 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/model/relational_model/static_list.js b/addons/web/static/src/model/relational_model/static_list.js index 32547575112..7dd83192c9f 100644 --- a/addons/web/static/src/model/relational_model/static_list.js +++ b/addons/web/static/src/model/relational_model/static_list.js @@ -868,7 +868,7 @@ export class StaticList extends DataPoint { await Promise.all(proms); await this._sort(); - this._onUpdate(); + await this._onUpdate(); } async _sort(currentIds = this.currentIds, orderBy = this.orderBy) { diff --git a/addons/web/static/tests/views/fields/one2many_field_tests.js b/addons/web/static/tests/views/fields/one2many_field_tests.js index 839ff5e74df..2381e872b4d 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -604,6 +604,58 @@ QUnit.module("Fields", (hooks) => { await clickSave(target); }); + QUnit.test( + "one2many wait for the onchange of the resequenced finish before save", + async function (assert) { + assert.expect(4); + + serverData.models.partner.records[0].p = [1, 2]; + serverData.models.partner.onchanges = { + p: function (obj) { + obj.p = [[1, 2, { qux: 99 }]]; + }, + }; + const def = makeDeferred(); + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + + + +
`, + resId: 1, + async mockRPC(route, args) { + if (args.method === "onchange2") { + await def; + assert.step("onchange"); + } + if (args.method === "write") { + assert.step("write"); + assert.deepEqual(args.args[1].p, [ + [1, 1, { int_field: 9 }], + [1, 2, { int_field: 10, qux: 99 }], + ]); + } + }, + }); + // Drag and drop the second line in first position + await dragAndDrop("tbody tr:nth-child(2) .o_handle_cell", "tbody tr", "top"); + await clickSave(target); + + // resolve the onchange promise + def.resolve(); + await nextTick(); + assert.verifySteps(["onchange", "write"]); + } + ); + QUnit.test("one2many basic properties", async function (assert) { serverData.models.partner.records[0].p = [2]; await makeView({ @@ -5612,7 +5664,8 @@ QUnit.module("Fields", (hooks) => { const fieldValues = args.args[1]; if (count === 1) { assert.deepEqual(fieldValues.trululu, { - foo: "hello", id: 1, + foo: "hello", + id: 1, }); } else if (count === 2) { assert.deepEqual(fieldValues.trululu, {