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 7dd83192c9f..748b3a2b9e5 100644 --- a/addons/web/static/src/model/relational_model/static_list.js +++ b/addons/web/static/src/model/relational_model/static_list.js @@ -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; } 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 2381e872b4d..99cd995deaf 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -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: ` +
+ + + + + + + + +
`, + 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];