[FIX] web: form view does not modify useSampleModel value

Go to a (OWL) list view with sample data, click "Create" to open a (OWL)
form view and go back to the list view using the breacrumbs: the sample
data has disappeared.

This is due to the fact that the form view set useSampleModel=false in
the globalState when it is left while it does not use at all sample data
mode.

Here we make it simply pass the value that it received initially.

closes odoo/odoo#99587

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
Mathieu Duckerts-Antoine
2022-09-06 10:58:22 +02:00
parent ce8076566b
commit 2600d1f2ae
3 changed files with 64 additions and 22 deletions
@@ -103,17 +103,23 @@ export class FormController extends Component {
const beforeLoadProm = new Promise((r) => {
this.beforeLoadResolver = r;
});
this.model = useModel(this.props.Model, {
resModel: this.props.resModel,
resId: this.props.resId || false,
resIds: this.props.resIds,
fields: this.props.fields,
activeFields,
viewMode: "form",
rootType: "record",
mode: this.props.mode,
beforeLoadProm,
});
this.model = useModel(
this.props.Model,
{
resModel: this.props.resModel,
resId: this.props.resId || false,
resIds: this.props.resIds,
fields: this.props.fields,
activeFields,
viewMode: "form",
rootType: "record",
mode: this.props.mode,
beforeLoadProm,
},
{
ignoreUseSampleModel: true,
}
);
const { create, edit } = this.archInfo.activeActions;
this.canCreate = create && !this.props.preventCreate;
+14 -11
View File
@@ -119,18 +119,21 @@ export function useModel(ModelClass, params, options = {}) {
async function load(props) {
const searchParams = getSearchParams(props);
await model.load(searchParams);
if (useSampleModel && !model.hasData()) {
sampleORM =
sampleORM || buildSampleORM(component.props.resModel, component.props.fields, user);
sampleORM.setGroups(model.getGroups());
// Load data with sampleORM then restore real ORM.
model.orm = sampleORM;
await model.load(searchParams);
model.orm = orm;
} else {
useSampleModel = false;
if (!options.ignoreUseSampleModel) {
if (useSampleModel && !model.hasData()) {
sampleORM =
sampleORM ||
buildSampleORM(component.props.resModel, component.props.fields, user);
sampleORM.setGroups(model.getGroups());
// Load data with sampleORM then restore real ORM.
model.orm = sampleORM;
await model.load(searchParams);
model.orm = orm;
} else {
useSampleModel = false;
model.useSampleModel = useSampleModel;
}
}
model.useSampleModel = useSampleModel;
if (started) {
model.notify();
}
@@ -2393,4 +2393,37 @@ QUnit.module("ActionManager", (hooks) => {
// mode is "edit" because target="new"
assert.containsOnce(target, ".o_form_view .o_form_editable");
});
QUnit.test("action group_by of type string", async function (assert) {
serverData.models.partner.records = [];
serverData.views["partner,false,list"] = `
<tree sample="1">
<field name="name"/>
</tree>
`;
serverData.views["partner,false,form"] = `
<form>
<field name="name"/>
</form>
`;
registry.category("services").add("user", makeFakeUserService());
const webClient = await createWebClient({ serverData });
await doAction(webClient, {
name: "Partner",
res_model: "partner",
type: "ir.actions.act_window",
views: [
[false, "list"],
[false, "form"],
],
});
assert.containsOnce(target, ".o_list_view .o_content.o_view_sample_data");
await click(target.querySelector(".o_list_view .o_list_button_add"));
await click(target.querySelector(".o_form_view .breadcrumb-item a"));
assert.containsOnce(target, ".o_list_view .o_content.o_view_sample_data");
});
});