[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) <aab@odoo.com>
Signed-off-by: Guillaume Merlin (megu) <megu@odoo.com>
This commit is contained in:
MerlinGuillaume
2023-05-15 12:56:20 +02:00
parent d7d7f84ff2
commit 93df76fedb
2 changed files with 22 additions and 2 deletions
@@ -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 });
}
},
@@ -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(