From 93df76fedb71b1eb5ebe0d11bcdb0cb6bb2173c4 Mon Sep 17 00:00:00 2001 From: MerlinGuillaume Date: Tue, 25 Apr 2023 11:19:27 +0000 Subject: [PATCH] [FIX] web: disable click on list action with target new When importing data and checking the possible values of a field, clicking on one of the records to open it throws an error Steps to reproduce: 1. Install Projects 2. Go to Project > My Tasks and trigger the list view 3. Select any record and export it (check the import-compatible export option) 4. Open the exported file and modify the `project_id` to a non-existing project name 5. Click on Favorites > Import records 6. Upload the modified file and click on 'TEST' 7. In the `project_id` field, click on 'See possible values' 8. Click on any project, an error is thrown Solution: Prevent the form from being opened when the action is in target "new" Problem: Opening the record in a target new throws the error `switchView called but the current controller isn't a view` opw-3161777 closes odoo/odoo#121384 X-original-commit: 63d43713ea5b2efba2e63b1735954bb2069bc6f4 Signed-off-by: Aaron Bohy (aab) Signed-off-by: Guillaume Merlin (megu) --- .../src/webclient/actions/action_service.js | 4 ++-- .../tests/webclient/actions/target_tests.js | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/webclient/actions/action_service.js b/addons/web/static/src/webclient/actions/action_service.js index 9d1e0aec976..9776c354612 100644 --- a/addons/web/static/src/webclient/actions/action_service.js +++ b/addons/web/static/src/webclient/actions/action_service.js @@ -463,12 +463,12 @@ function makeActionManager(env) { resModel: action.res_model, type: view.type, selectRecord: async (resId, { activeIds, mode }) => { - if (_getView("form")) { + if (target !== "new" && _getView("form")) { await switchView("form", { mode, resId, resIds: activeIds }); } }, createRecord: async () => { - if (_getView("form")) { + if (target !== "new" && _getView("form")) { await switchView("form", { resId: false }); } }, diff --git a/addons/web/static/tests/webclient/actions/target_tests.js b/addons/web/static/tests/webclient/actions/target_tests.js index 01929b6c0cb..5eb98e69bff 100644 --- a/addons/web/static/tests/webclient/actions/target_tests.js +++ b/addons/web/static/tests/webclient/actions/target_tests.js @@ -475,6 +475,26 @@ QUnit.module("ActionManager", (hooks) => { assert.hasClass(target.querySelector(".o_dialog .modal-dialog"), "modal-xl"); }); + QUnit.test('click on record in list view action in target="new"', async function (assert) { + const webClient = await createWebClient({ serverData }); + await doAction(webClient, 1001); + await doAction(webClient, { + name: "Favorite Ponies", + res_model: "pony", + type: "ir.actions.act_window", + target: "new", + views: [[false, "list"], [false, "form"]], + }); + + // The list view has been opened in a dialog + assert.containsOnce(target, ".o_dialog .modal-dialog .o_list_view"); + + // click on a record in the dialog -> should do nothing as we can't switch view in the dialog + await click(target.querySelector(".modal .o_data_row .o_data_cell")); + assert.containsOnce(target, ".o_dialog .modal-dialog .o_list_view"); + assert.containsNone(target, ".o_form_view"); + }); + QUnit.module('Actions in target="fullscreen"'); QUnit.test(