[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) <aab@odoo.com>
This commit is contained in:
committed by
Aaron Bohy
parent
2e35ba0260
commit
ea0a718fb4
@@ -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,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": '<list><field name="foo"/></list>',
|
||||
'partner,2,kanban': '<kanban></kanban>',
|
||||
"partner,3,form": `<form></form>`,
|
||||
'partner,false,search': '<search></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"]],
|
||||
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user