[FIX] web: don't remove sample data on view switch
This commit solves an issue where sample data would be erased when the user switches from a view with no sample data to another that should contain them. This commit also removes unnecessary usage of nextTick in assets loading. Steps to reproduce: - go to project and open one - enter a no match filter and save it as favorite - reload - switch from kanban to calendar view and switch back to kanban - after the fix, sample data should no longer be erased from kanban task-3701143 closes odoo/odoo#152666 X-original-commit: a8ff1465c6c31240d06c98fa5d61e146b3908cf0 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com> Signed-off-by: Julien Carion (juca) <juca@odoo.com>
This commit is contained in:
@@ -133,11 +133,9 @@ export function useModelWithSampleData(ModelClass, params, options = {}) {
|
||||
|
||||
const globalState = component.props.globalState || {};
|
||||
const localState = component.props.state || {};
|
||||
let useSampleModel = Boolean(
|
||||
"useSampleModel" in globalState
|
||||
? globalState.useSampleModel
|
||||
: component.props.useSampleModel
|
||||
);
|
||||
let useSampleModel =
|
||||
component.props.useSampleModel &&
|
||||
(!("useSampleModel" in globalState) || globalState.useSampleModel);
|
||||
model.useSampleModel = useSampleModel;
|
||||
const orm = model.orm;
|
||||
let sampleORM = localState.sampleORM;
|
||||
@@ -179,7 +177,9 @@ export function useModelWithSampleData(ModelClass, params, options = {}) {
|
||||
|
||||
useSetupView({
|
||||
getGlobalState() {
|
||||
return { useSampleModel };
|
||||
if (component.props.useSampleModel) {
|
||||
return { useSampleModel };
|
||||
}
|
||||
},
|
||||
getLocalState: () => {
|
||||
return { sampleORM };
|
||||
|
||||
@@ -5426,4 +5426,62 @@ QUnit.module("Views", ({ beforeEach }) => {
|
||||
"00 - bazar0 - chouette1 - brol10 - machin11 - chose100 - bidule1011000 - trucEdên@Hello#HelloJean-Paul 1Jean-Paul 2JeremyKévinRomelüThibaùltZoooroUndefined"
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test(
|
||||
"sample data are not removed when switching back from calendar view",
|
||||
async function (assert) {
|
||||
serverData.models.event.records = [];
|
||||
serverData.actions = {
|
||||
1: {
|
||||
id: 1,
|
||||
name: "Partners",
|
||||
res_model: "event",
|
||||
type: "ir.actions.act_window",
|
||||
views: [
|
||||
[false, "list"],
|
||||
[false, "calendar"],
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
serverData.views = {
|
||||
"event,false,calendar": `<calendar date_start="start" date_stop="stop" mode="day"/>`,
|
||||
"event,false,list": `<tree sample="1">
|
||||
<field name="start"/>
|
||||
<field name="stop"/>
|
||||
</tree>`,
|
||||
|
||||
"event,false,search": `<search />`,
|
||||
};
|
||||
|
||||
const webClient = await createWebClient({
|
||||
serverData,
|
||||
async mockRPC(route, args) {
|
||||
if (args.method === "check_access_rights") {
|
||||
return true;
|
||||
}
|
||||
if (route.endsWith("/has_group")) {
|
||||
return true;
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
await doAction(webClient, 1);
|
||||
|
||||
assert.containsOnce(target, ".o_list_view", "should have rendered a list view");
|
||||
assert.containsOnce(target, ".o_view_sample_data", "should have sample data");
|
||||
|
||||
await click(target, ".o_cp_switch_buttons .o_calendar");
|
||||
assert.containsOnce(
|
||||
target,
|
||||
".o_calendar_container",
|
||||
"should have rendered a calendar view"
|
||||
);
|
||||
|
||||
await click(target, ".o_cp_switch_buttons .o_list");
|
||||
|
||||
assert.containsOnce(target, ".o_list_view", "should have rendered a list view");
|
||||
assert.containsOnce(target, ".o_view_sample_data", "should have sample data");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user