[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
This commit is contained in:
committed by
Géry Debongnie
parent
d3662d370c
commit
24e8e10b34
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user