From ea0a718fb4d4f3d0f34100e151d8a280e600cac0 Mon Sep 17 00:00:00 2001 From: "Francois (fge)" Date: Tue, 15 Jun 2021 14:59:45 +0000 Subject: [PATCH] [FIX] web: add the missing views in legacy_views Before this commit, the switch from a multiple view (list, kanban, ...) to a custom form view was not correctly done. The form view displayed was not the custom version but the default one. This problem is caused by the filter applied on viewSwitcherEntries which removes the form views because they are not a multiple view. To solve this problem, we will add the missing form view in the actions.views given to the legacy view. closes odoo-dev/odoo#958 Signed-off-by: Aaron Bohy (aab) --- addons/web/static/src/legacy/legacy_views.js | 16 ++++- .../tests/webclient/actions/legacy_tests.js | 68 +++++++++++++++++++ 2 files changed, 83 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/legacy/legacy_views.js b/addons/web/static/src/legacy/legacy_views.js index e2bd9c1294d..16e55b3e783 100644 --- a/addons/web/static/src/legacy/legacy_views.js +++ b/addons/web/static/src/legacy/legacy_views.js @@ -101,10 +101,24 @@ function registerView(name, LegacyView) { viewFields: result.fields_views.search.fields, }); } + const views = this.viewParams.action.views + .filter(([vid, vtype]) => vtype !== "search") + .map(([vid, vtype]) => { + const view = this.props.viewSwitcherEntries.find((v) => v.type === vtype); + if (view) { + return Object.assign({}, view, {viewID: vid}); + } else { + return { + viewID: vid, + type: vtype, + multiRecord: !this.constructor.multiRecord, + }; + } + }); this.viewParams.action = Object.assign({}, this.viewParams.action, { controlPanelFieldsView, _views: this.viewParams.action.views, - views: this.props.viewSwitcherEntries, + views, }); } } diff --git a/addons/web/static/tests/webclient/actions/legacy_tests.js b/addons/web/static/tests/webclient/actions/legacy_tests.js index 7e9b8ffc398..7b5190d7e75 100644 --- a/addons/web/static/tests/webclient/actions/legacy_tests.js +++ b/addons/web/static/tests/webclient/actions/legacy_tests.js @@ -3,6 +3,7 @@ import { registry } from "@web/core/registry"; import testUtils from "web.test_utils"; import ListController from "web.ListController"; +import ListView from 'web.ListView'; import { click, legacyExtraNextTick, patchWithCleanup } from "../../helpers/utils"; import { createWebClient, doAction, getActionManagerServerData } from "./../helpers"; @@ -184,4 +185,71 @@ QUnit.module("ActionManager", (hooks) => { delete core.action_registry.map.customLegacy; }); + + QUnit.test("Checks the availability of all views in the action", async (assert) => { + assert.expect(2); + patchWithCleanup(ListView.prototype, { + init(viewInfo, params) { + const action = params.action; + const views = action.views.map((view) => ([view.viewID, view.type])); + assert.deepEqual(views, [ + [1, "list"], + [2, "kanban"], + [3, "form"], + ]); + assert.deepEqual(action._views, [ + [1, "list"], + [2, "kanban"], + [3, "form"], + [false, "search"], + ]); + this._super(...arguments); + }, + }); + const models = { + partner: { + fields: { + display_name: {string: "Displayed name", type: "char", searchable: true}, + foo: {string: "Foo", type: "char", default: "My little Foo Value", searchable: true}, + bar: {string: "Bar", type: "boolean"}, + int_field: {string: "Integer field", type: "integer", group_operator: 'sum'}, + }, + records: [{ + id: 1, + display_name: "first record", + foo: "yop", + int_field: 3, + }, { + id: 2, + display_name: "second record", + foo: "lalala", + int_field: 5, + }, { + id: 4, + display_name: "aaa", + foo: "abc", + int_field: 2, + }], + } + }; + const views = { + "partner,1,list": '', + 'partner,2,kanban': '', + "partner,3,form": `
`, + 'partner,false,search': '', + }; + const serverData = { models, views }; + + const webClient = await createWebClient({ + serverData, + }); + + await doAction(webClient, { + id: 1, + res_model: "partner", + type: "ir.actions.act_window", + views: [[1, "list"], [2, "kanban"], [3, "form"]], + + }); + }); });