From 24e8e10b3408329e34e62ad4ebd22f20bdd0983a Mon Sep 17 00:00:00 2001 From: Aaron Bohy Date: Tue, 19 Jul 2022 09:44:23 +0000 Subject: [PATCH] [FIX] web: LegacyField: correct mode and hasReadonlyModifier Before this commit, legacy fields spawned in wowl views didn't receive the correct "mode" and "hasReadonlyModifier" params. They do now. We do not add qunit tests for this, as tours already identified the issues, and it only concerns legacy fields that we'll soon remove anyway. Part-of: odoo/odoo#78221 --- addons/web/static/src/legacy/legacy_fields.js | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/addons/web/static/src/legacy/legacy_fields.js b/addons/web/static/src/legacy/legacy_fields.js index 8f086f22cb4..004cffdd07d 100644 --- a/addons/web/static/src/legacy/legacy_fields.js +++ b/addons/web/static/src/legacy/legacy_fields.js @@ -2,6 +2,7 @@ import { registry } from "@web/core/registry"; import { sprintf } from "@web/core/utils/strings"; +import { evalDomain } from "@web/views/utils"; import { Domain } from "web.Domain"; import legacyFieldRegistry from "web.field_registry"; import { ComponentAdapter } from "web.OwlCompatibility"; @@ -23,6 +24,9 @@ class FieldAdapter extends ComponentAdapter { this.wowlEnv = this.env; this.env = Component.env; useEffect(() => { + if (!this.widgetEl || !this.widgetEl.parentElement) { + return; + } // if classNames are given to the field, we only want // to add those classes to the legacy field without // the parent element affecting the style of the field @@ -254,10 +258,11 @@ function registerField(name, LegacyFieldWidget) { const { name, record } = this.props; if (record.model.__bm__) { const legacyRecord = record.model.__bm__.get(record.__bm_handle__); + const hasReadonlyModifier = record.isReadonly(name); const options = { viewType: legacyRecord.viewType, - hasReadonlyModifier: record.isReadonly(name), - mode: record.mode, + hasReadonlyModifier, + mode: hasReadonlyModifier ? "readonly" : record.mode, }; return { name, record: legacyRecord, options }; } else { @@ -276,16 +281,19 @@ function registerField(name, LegacyFieldWidget) { arch: viewUtils.parseArch(arch), }; } + const modifiers = JSON.parse(fieldInfo.rawAttrs.modifiers || "{}"); + let hasReadonlyModifier = evalDomain(modifiers.readonly, record.evalContext); const options = { attrs: { ...fieldInfo.rawAttrs, - modifiers: JSON.parse(fieldInfo.rawAttrs.modifiers || "{}"), + modifiers, options: fieldInfo.options, widget: fieldInfo.widget, views, mode: fieldInfo.viewMode, }, - mode: record.mode, + mode: hasReadonlyModifier ? "readonly" : record.mode, + hasReadonlyModifier, }; return { name, record: legacyRecord, options }; }