From e331d964125ca6cef5b2b608c52c2569c3f50fc3 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 16 Sep 2022 20:07:29 +0000 Subject: [PATCH] [FIX] web: FormView: ensure defaultFields to fields Since [1], a call to getView no longer returns the all models the list of all their fields, because a lot of them aren't necessary. However, it caused an issue in the following situation: - have a form view with an x2many displayed as a list - in the list, have a field using the widget many2many_tags along the color_field option - in the arch, the x2many form view isn't inline list must be present, without the color_field option, and the color field must not be present, - in readonly mode, the user clicks on a row, which will open the x2many form view - since the form view isn't inline, a call to getView is done - in the returned form view, the color field isn't present, the field using many2many_tags/color_field in the list is present, and without the color_field option. Since [1], it crashed at this point because A wasn't part of the known fields in the form view (but it was in the fieldsInfo, since they are shared between the x2many list and form). This commit fixes the issue by adding the color field not only in fieldsInfo, but also in fields. [1] odoo/odoo@4636620004f0cc0e504cd6694fe8ddb6758ba811 closes odoo/odoo#100479 Signed-off-by: Denis Ledoux (dle) --- .../src/views/basic_relational_model.js | 1 + .../tests/views/form/form_view_tests.js | 48 +++++++++++++++++++ 2 files changed, 49 insertions(+) diff --git a/addons/web/static/src/views/basic_relational_model.js b/addons/web/static/src/views/basic_relational_model.js index 4d9c58d4d64..3b11f772188 100644 --- a/addons/web/static/src/views/basic_relational_model.js +++ b/addons/web/static/src/views/basic_relational_model.js @@ -1264,6 +1264,7 @@ export class RelationalModel extends Model { const fieldViews = fieldInfo.views || fieldInfo.fieldsInfo || {}; const defaultFieldInfo = legRec.data[name].fieldsInfo.default; _.each(fieldViews, function (fieldView) { + _.defaults(fieldView.fields, defaultFieldInfo); _.each(fieldView.fieldsInfo, function (x2mFieldInfo) { _.defaults(x2mFieldInfo, defaultFieldInfo); }); diff --git a/addons/web/static/tests/views/form/form_view_tests.js b/addons/web/static/tests/views/form/form_view_tests.js index 6dcbcad1fe4..02d766c9a26 100644 --- a/addons/web/static/tests/views/form/form_view_tests.js +++ b/addons/web/static/tests/views/form/form_view_tests.js @@ -174,6 +174,7 @@ QUnit.module("Views", (hooks) => { fields: { name: { string: "Partner Type", type: "char" }, color: { string: "Color index", type: "integer" }, + foo: { string: "Foo", type: "char" }, }, records: [ { id: 12, display_name: "gold", color: 2 }, @@ -625,6 +626,53 @@ QUnit.module("Views", (hooks) => { assert.hasClass(target.querySelector('.o_field_widget[name="foo"]'), "text-danger"); }); + QUnit.test( + "form with o2m having a many2many fields using the many2many_tags widget along the color_field option", + async function (assert) { + // In this scenario, the x2many form view isn't inline, so when we click on the record, + // it does an independant getView, which doesn't return all fields of the model. In the + // x2many list view, there's a field with a many2many_tags widget with the color option, + // and the color field (color) in our case, isn't in the form view. + // This test ensures that we can open the form view in this situation. + serverData.models.partner.records[0].timmy = [12, 14]; + serverData.views = { + "partner,false,form": ` +
+ + + + + + + + + `, + }; + await makeView({ + type: "form", + resModel: "user", + serverData, + arch: ` +
+ + + + + + +
`, + resId: 17, + }); + assert.containsOnce(target, ".o_field_widget[name=timmy] .o_field_tags"); + await click(target.querySelector(".o_data_row .o_data_cell")); + assert.containsOnce(target, ".modal .o_form_view .o_field_widget[name=timmy]"); + } + ); + QUnit.test("decoration-bf works on fields", async function (assert) { await makeView({ type: "form",