[FIX] web: o2m multi page command forget second page

Have an x2many list or kanban with several page, and an onchange
on the main record that returns forget or delete commands for
x2many records that aren't on the first page. Before this commit,
it crashed, because the code expected the records to be in
this.records (the record of the current page).

Part of task~3179751

Part-of: odoo/odoo#114024
This commit is contained in:
Aaron Bohy
2023-07-24 20:17:55 +02:00
parent 30d2e224d8
commit 0e2d8eeabe
2 changed files with 47 additions and 7 deletions
@@ -541,14 +541,14 @@ export class StaticList extends DataPoint {
}
}
const record = this._cache[command[1]];
this.records.splice(
this.records.findIndex((r) => r.id === record.id),
1
);
if (record.resId) {
const index = this._currentIds.findIndex((id) => id === record.resId);
this._currentIds.splice(index, 1);
if (record) {
const index = this.records.findIndex((r) => r.id === record.id);
if (index >= 0) {
this.records.splice(index, 1);
}
}
const index = this._currentIds.findIndex((id) => id === command[1]);
this._currentIds.splice(index, 1);
this.count--;
break;
}
@@ -12780,6 +12780,46 @@ QUnit.module("Fields", (hooks) => {
assert.strictEqual(serverData.models.turtle.records[0].turtle_int, 5);
});
QUnit.test("multi page, command forget for record of second page", async function (assert) {
serverData.models.partner.records[0].p = [1, 2, 4];
serverData.models.partner.onchanges = {
int_field: function (obj) {
obj.p = [[3, 4]];
},
};
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<group>
<field name="int_field"/>
<field name="p">
<tree limit="2">
<field name="display_name"/>
</tree>
</field>
</group>
</form>`,
resId: 1,
});
assert.strictEqual(target.querySelector("[name=int_field] input").value, "10");
assert.containsN(target, ".o_data_row", 2);
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_data_cell")), ["first record", "second record"]);
assert.strictEqual(
target.querySelector(".o_x2m_control_panel .o_pager_counter").innerText,
"1-2 / 3"
);
// trigger the onchange
await editInput(target, "[name=int_field] input", "16");
assert.containsN(target, ".o_data_row", 2);
assert.deepEqual(getNodesTextContent(target.querySelectorAll(".o_data_cell")), ["first record", "second record"]);
assert.containsNone(target, ".o_x2m_control_panel .o_pager");
});
QUnit.test("active actions are passed to o2m field", async (assert) => {
serverData.models.partner.records[0].turtles = [1, 2, 3];