[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
This commit is contained in:
FrancoisGe
2022-08-23 16:28:57 +02:00
parent d531848034
commit e1d60b9161
3 changed files with 40 additions and 2 deletions
@@ -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 = {};
@@ -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"]],
});
@@ -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": '<form><field name="turtle_foo"/></form>',
};
await makeView({
type: "form",
resModel: "partner",
serverData,
arch: `
<form>
<field name="int_field"/>
<field name="turtles" context="{'hello': 'world', 'abc': int_field}">
<tree>
<field name="turtle_foo"/>
</tree>
</field>
</form>`,
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);