From cea8a6adaf99aafd9d9d9fbdddaa1b0e617f3e02 Mon Sep 17 00:00:00 2001 From: Lucas Perais Date: Mon, 25 Jul 2022 10:11:20 +0000 Subject: [PATCH] [FIX] views: fields: one2many open record containing another one2many MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .../src/views/fields/relational_utils.js | 5 ++- .../views/fields/one2many_field_tests.js | 40 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/addons/web/static/src/views/fields/relational_utils.js b/addons/web/static/src/views/fields/relational_utils.js index 96bbd083b6a..f7fc9e143e3 100644 --- a/addons/web/static/src/views/fields/relational_utils.js +++ b/addons/web/static/src/views/fields/relational_utils.js @@ -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 }) => { 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 7afc91d63d3..4c6415cca1c 100644 --- a/addons/web/static/tests/views/fields/one2many_field_tests.js +++ b/addons/web/static/tests/views/fields/one2many_field_tests.js @@ -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": `
+ +
`, + }; + + 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: `
+ + + +
`, + 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", + ]); + }); });