[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@4636620004
closes odoo/odoo#100479
Signed-off-by: Denis Ledoux (dle) <dle@odoo.com>
This commit is contained in:
@@ -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);
|
||||
});
|
||||
|
||||
@@ -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": `
|
||||
<form>
|
||||
<field name="display_name"/>
|
||||
<field name="timmy" widget="one2many">
|
||||
<tree string="Values">
|
||||
<field name="display_name"/>
|
||||
<!--
|
||||
Required to add at least one different field than the fields read
|
||||
to display <field name="timmy" widget="many2many_tags"/> below.
|
||||
To force to re-read the record with more fields.
|
||||
-->
|
||||
<field name="foo"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
};
|
||||
await makeView({
|
||||
type: "form",
|
||||
resModel: "user",
|
||||
serverData,
|
||||
arch: `
|
||||
<form>
|
||||
<field name="partner_ids">
|
||||
<tree editable="top">
|
||||
<field name="display_name"/>
|
||||
<field name="timmy" widget="many2many_tags" options="{'color_field': 'color'}"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>`,
|
||||
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",
|
||||
|
||||
Reference in New Issue
Block a user