Skip to content

Commit

Permalink
[FIX] web: form view does not modify useSampleModel value
Browse files Browse the repository at this point in the history
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#99587

Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
  • Loading branch information
Polymorphe57 committed Sep 6, 2022
1 parent ce80765 commit 2600d1f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
28 changes: 17 additions & 11 deletions addons/web/static/src/views/form/form_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
25 changes: 14 additions & 11 deletions addons/web/static/src/views/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
33 changes: 33 additions & 0 deletions addons/web/static/tests/webclient/actions/window_action_tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -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");
});
});

0 comments on commit 2600d1f

Please sign in to comment.