From 09063c81614e259c300d1bf58b22e4e0991e037e Mon Sep 17 00:00:00 2001 From: paso-odoo Date: Fri, 19 May 2023 10:43:45 +0000 Subject: [PATCH] [FIX] web: prevent selection while record in edit mode from editable list view If applied, this commit will solve the issue of the list view selection when the record is not actually created but it can be selected and can able to perform the action. Steps to produce: - Open Accounting > Configurations > Chart of Accounts. - Click on the 'New' button. - Select the new line which has been added. - Perform the 'Duplicate' action for that record. This commit will fix the generic issue by preventing the record selection while the record is in 'Edit' mode. sentry - 4191036697 closes odoo/odoo#129000 X-original-commit: 5570216c8c852b5851526217858b5b7515309444 Signed-off-by: Mathieu Duckerts-Antoine (dam) Signed-off-by: Parth Solanki (paso) --- .../static/src/views/list/list_renderer.js | 10 +++++++ .../static/src/views/list/list_renderer.xml | 4 +-- .../web/static/tests/views/list_view_tests.js | 27 +++++++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/list/list_renderer.js b/addons/web/static/src/views/list/list_renderer.js index d8428a38888..e8f1c189840 100644 --- a/addons/web/static/src/views/list/list_renderer.js +++ b/addons/web/static/src/views/list/list_renderer.js @@ -1732,8 +1732,15 @@ export class ListRenderer extends Component { group.toggle(); } + get canSelectRecord() { + return !this.props.list.editedRecord && !this.props.list.model.useSampleModel; + } + toggleSelection() { const list = this.props.list; + if (!this.canSelectRecord) { + return; + } if (list.selection.length === list.records.length) { list.records.forEach((record) => { record.toggleSelection(false); @@ -1747,6 +1754,9 @@ export class ListRenderer extends Component { } toggleRecordSelection(record) { + if (!this.canSelectRecord) { + return; + } if (this.shiftKeyMode && this.lastCheckedRecord) { this.toggleRecordShiftSelection(record); } else { diff --git a/addons/web/static/src/views/list/list_renderer.xml b/addons/web/static/src/views/list/list_renderer.xml index 948518ccc23..cf1983bf7c5 100644 --- a/addons/web/static/src/views/list/list_renderer.xml +++ b/addons/web/static/src/views/list/list_renderer.xml @@ -14,7 +14,7 @@ - + - + diff --git a/addons/web/static/tests/views/list_view_tests.js b/addons/web/static/tests/views/list_view_tests.js index 13a0d65b871..05f9aef1d01 100644 --- a/addons/web/static/tests/views/list_view_tests.js +++ b/addons/web/static/tests/views/list_view_tests.js @@ -19044,6 +19044,33 @@ QUnit.module("Views", (hooks) => { ); }); + QUnit.test("list view: prevent record selection when editable list in edit mode", async function (assert) { + await makeView({ + type: "list", + resModel: "foo", + serverData, + arch: ` + + + `, + }); + + // When we try to select new record in edit mode + await click(target.querySelector(".o_control_panel_main_buttons .d-none.d-xl-inline-flex .o_list_button_add")); + await click(target.querySelector('.o_data_row .o_list_record_selector')); + assert.strictEqual( + target.querySelector('.o_data_row .o_list_record_selector input[type="checkbox"]').checked, + false + ); + + // When we try to select all records in edit mode + await click(target.querySelector('th.o_list_record_selector.o_list_controller')); + assert.strictEqual( + target.querySelector('.o_list_controller input[type="checkbox"]').checked, + false + ); + }); + QUnit.test("context keys not passed down the stack and not to fields", async (assert) => { patchWithCleanup(AutoComplete, { timeout: 0,