From 0e2d8eeabe22240a1bc37a0a71bf836d05002c2d Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Wed, 12 Jul 2023 12:31:09 +0000 Subject: [PATCH] [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 --- .../src/model/relational_model/static_list.js | 14 +++---- .../views/fields/one2many_field_tests.js | 40 +++++++++++++++++++ 2 files changed, 47 insertions(+), 7 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 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];