[FIX] views: fields: one2many open record containing another one2many

Have a form view with a one2many list with one record inside.
Click on it to open it. The form view that will open must also have a one2many list

Before this commit, there was a crash because the information of the main record's view
was not propagated to the form view of the opened record. Generally speaking, env.config was lost.

After this commit, we propagate correctly the config.

closes odoo/odoo#96618

Signed-off-by: Géry Debongnie <ged@odoo.com>
This commit is contained in:
Lucas Perais
2022-07-28 09:14:43 +02:00
parent 6eb2238294
commit cea8a6adaf
2 changed files with 44 additions and 1 deletions
@@ -21,7 +21,7 @@ import { useViewButtons } from "@web/views/view_button/view_button_hook";
import { FormViewDialog } from "@web/views/view_dialogs/form_view_dialog";
import { SelectCreateDialog } from "@web/views/view_dialogs/select_create_dialog";
const { useEffect } = owl;
const { useEffect, useSubEnv } = owl;
//
// Commons
@@ -408,6 +408,7 @@ class X2ManyFieldDialog extends owl.Component {
this.archInfo = this.props.archInfo;
this.record = this.props.record;
this.title = this.props.title;
useSubEnv({ config: this.props.config });
useBus(this.record.model, "update", () => this.render(true));
@@ -512,6 +513,7 @@ X2ManyFieldDialog.props = {
save: Function,
title: String,
delete: { optional: true },
config: Object,
};
X2ManyFieldDialog.template = "web.X2ManyFieldDialog";
@@ -610,6 +612,7 @@ export function useOpenX2ManyRecord({
addDialog(
X2ManyFieldDialog,
{
config: env.config,
archInfo: form,
record,
save: async (rec, { saveAndNew }) => {
@@ -12155,4 +12155,44 @@ QUnit.module("Fields", (hooks) => {
assert.containsOnce(target, ".o_list_renderer");
}
);
QUnit.test("open a one2many record containing a one2many", async (assert) => {
serverData.views = {
"partner,1234,form": `<form><field name="turtles" >
<tree><field name="display_name" /></tree></field>
</form>`,
};
patchWithCleanup(browser.localStorage, {
setItem(args) {
assert.step(`localStorage setItem ${args}`);
},
getItem(args) {
assert.step(`localStorage getItem ${args}`);
},
});
const rec = serverData.models.partner.records.find(({ id }) => id === 2);
rec.p = [1];
await makeView({
type: "form",
arch: `<form>
<field name="p" context="{ 'form_view_ref': 1234 }">
<tree><field name="display_name" /></tree>
</field>
</form>`,
serverData,
resModel: "partner",
resId: 2,
});
assert.verifySteps([
"localStorage getItem optional_fields,partner,form,100000001,p,list,display_name",
]);
await click(target.querySelector(".o_data_cell"));
assert.containsOnce(target, ".modal .o_data_row");
assert.verifySteps([
"localStorage getItem optional_fields,partner,form,100000001,turtles,list,display_name",
]);
});
});