From e1d60b916134d7fad07cc5b583ee5d54ea55d0c7 Mon Sep 17 00:00:00 2001 From: FrancoisGe Date: Thu, 11 Aug 2022 13:03:56 +0000 Subject: [PATCH] [FIX] web: x2m open form dialog with the correct context Before this commit, when you want to modify or add a record in a non-editable x2many, the call to get_views to receive the arch for the FormViewDialog did not contain a context. Problem: The arch of the form view that is received for adding or editing a record in a non-editable x2many is not evaluated correctly. Cause: An empty context is passed to the "get_views" to receive the arch for the FormViewDialog. Solution: We use the context of the StaticList that represents the x2many for the "get_views". Part-of: odoo/odoo#97558 --- .../src/views/basic_relational_model.js | 3 +- .../src/views/fields/relational_utils.js | 2 +- .../views/fields/one2many_field_tests.js | 37 +++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/addons/web/static/src/views/basic_relational_model.js b/addons/web/static/src/views/basic_relational_model.js index 8821fd5bd0c..a382055a7fd 100644 --- a/addons/web/static/src/views/basic_relational_model.js +++ b/addons/web/static/src/views/basic_relational_model.js @@ -181,13 +181,14 @@ class DataPoint { if (params.__bm_load_params__) { this.__bm_load_params__ = params.__bm_load_params__; info = this.__bm_load_params__; + this.context = info.context; } else if (params.handle) { this.__bm_handle__ = params.handle; info = this.model.__bm__.get(this.__bm_handle__); + this.context = this.model.__bm__.localData[this.__bm_handle__].getContext(); } else { throw new Error("Datapoint needs load params or handle"); } - this.context = info.context; this.resModel = info.model || info.modelName; this.fields = info.fields; this.activeFields = {}; diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index d114231aef8..5a8942bdee8 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -522,7 +522,7 @@ async function getFormViewInfo({ list, activeField, viewService, userService, en const comodel = list.resModel; if (!formViewInfo) { const { fields, relatedModels, views } = await viewService.loadViews({ - context: {}, + context: list.context, resModel: comodel, views: [[false, "form"]], }); diff --git a/addons/web/static/tests/views/fields/one2many_field_tests.js b/addons/web/static/tests/views/fields/one2many_field_tests.js index e98144d740d..9bd60c7a3c2 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -5017,6 +5017,43 @@ QUnit.module("Fields", (hooks) => { } ); + QUnit.test( + "one2many list not editable, the context is properly evaluated and sent", + async function (assert) { + assert.expect(3); + serverData.views = { + "turtle,false,form": '
', + }; + + await makeView({ + type: "form", + resModel: "partner", + serverData, + arch: ` +
+ + + + + + + `, + resId: 1, + mockRPC(route, args) { + if (args.method === "get_views" && args.model === "turtle") { + const context = args.kwargs.context; + assert.strictEqual(context.hello, "world"); + assert.strictEqual(context.abc, 10); + } + }, + }); + + await clickEdit(target); + await addRow(target); + assert.containsOnce(target, ".modal"); + } + ); + QUnit.test("one2many with many2many widget: create", async function (assert) { assert.expect(10);