From 2600d1f2ae0ad5e478bd01ca7fdc69933576bff5 Mon Sep 17 00:00:00 2001 From: Mathieu Duckerts-Antoine Date: Mon, 5 Sep 2022 14:11:42 +0000 Subject: [PATCH] [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) --- .../static/src/views/form/form_controller.js | 28 +++++++++------- addons/web/static/src/views/model.js | 25 +++++++------- .../webclient/actions/window_action_tests.js | 33 +++++++++++++++++++ 3 files changed, 64 insertions(+), 22 deletions(-) diff --git a/addons/web/static/src/views/form/form_controller.js b/addons/web/static/src/views/form/form_controller.js index bf9df625deb4b..8f71d75d7b5f2 100644 --- a/addons/web/static/src/views/form/form_controller.js +++ b/addons/web/static/src/views/form/form_controller.js @@ -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; diff --git a/addons/web/static/src/views/model.js b/addons/web/static/src/views/model.js index 5941e9fcdc7a5..fea46f92b3772 100644 --- a/addons/web/static/src/views/model.js +++ b/addons/web/static/src/views/model.js @@ -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(); } diff --git a/addons/web/static/tests/webclient/actions/window_action_tests.js b/addons/web/static/tests/webclient/actions/window_action_tests.js index 48ea011465c7d..ba58fb546a8bd 100644 --- a/addons/web/static/tests/webclient/actions/window_action_tests.js +++ b/addons/web/static/tests/webclient/actions/window_action_tests.js @@ -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"] = ` + + + + `; + serverData.views["partner,false,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"); + }); });