[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
This commit is contained in:
Jorge Pinna Puissant
2023-07-24 20:17:55 +02:00
committed by Aaron Bohy
parent 5e684776d3
commit 88b4938b7c
2 changed files with 55 additions and 2 deletions
@@ -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) {
@@ -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: `
<form>
<field name="p">
<tree>
<field name="int_field" widget="handle"/>
<field name="foo"/>
<field name="qux"/>
</tree>
</field>
</form>`,
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, {