[REF] web, * : simplify concrete fields API - remove type prop
This commit, is part of a series of commits that aim to simplifie the concrete fields API. In this commit we will remove type prop from concrete fields. Now each field could directly use this.props.record.fields[this.props.name].type if they need to know the type of field. task-id 3179751 closes odoo/odoo#112792 Related: odoo/enterprise#37118 Signed-off-by: Aaron Bohy (aab) <aab@odoo.com>
This commit is contained in:
@@ -15,6 +15,7 @@ export function useAssignUserCommand() {
|
||||
const env = useEnv();
|
||||
const orm = useService("orm");
|
||||
const user = useService("user");
|
||||
const type = component.props.record.fields[component.props.name].type;
|
||||
if (
|
||||
component.props.relation !== "res.users" ||
|
||||
component.props.record.activeFields[component.props.name].viewType !== "form"
|
||||
@@ -23,18 +24,18 @@ export function useAssignUserCommand() {
|
||||
}
|
||||
|
||||
const getCurrentIds = () => {
|
||||
if (component.props.type === "many2one" && component.props.value) {
|
||||
if (type === "many2one" && component.props.value) {
|
||||
return [component.props.value[0]];
|
||||
} else if (component.props.type === "many2many") {
|
||||
} else if (type === "many2many") {
|
||||
return component.props.value.currentIds;
|
||||
}
|
||||
return [];
|
||||
};
|
||||
|
||||
const add = async (record) => {
|
||||
if (component.props.type === "many2one") {
|
||||
if (type === "many2one") {
|
||||
component.props.record.update({ [component.props.name]: record });
|
||||
} else if (component.props.type === "many2many") {
|
||||
} else if (type === "many2many") {
|
||||
component.props.record.update({
|
||||
[component.props.name]: {
|
||||
operation: "REPLACE_WITH",
|
||||
@@ -45,9 +46,9 @@ export function useAssignUserCommand() {
|
||||
};
|
||||
|
||||
const remove = async (record) => {
|
||||
if (component.props.type === "many2one") {
|
||||
if (type === "many2one") {
|
||||
component.props.record.update({ [component.props.name]: [] });
|
||||
} else if (component.props.type === "many2many") {
|
||||
} else if (type === "many2many") {
|
||||
component.props.record.update({
|
||||
[component.props.name]: {
|
||||
operation: "REPLACE_WITH",
|
||||
@@ -61,7 +62,7 @@ export function useAssignUserCommand() {
|
||||
const value = options.searchValue.trim();
|
||||
let domain = component.props.record.getFieldDomain(component.props.name);
|
||||
const context = component.props.record.getFieldContext(component.props.name);
|
||||
if (component.props.type === "many2many") {
|
||||
if (type === "many2many") {
|
||||
const selectedUserIds = getCurrentIds();
|
||||
if (selectedUserIds.length) {
|
||||
domain = Domain.and([domain, [["id", "not in", selectedUserIds]]]);
|
||||
|
||||
@@ -14,7 +14,7 @@ export class BadgeField extends Component {
|
||||
};
|
||||
|
||||
get formattedValue() {
|
||||
const formatter = formatters.get(this.props.type);
|
||||
const formatter = formatters.get(this.props.record.fields[this.props.name].type);
|
||||
return formatter(this.props.value, {
|
||||
selection: this.props.record.fields[this.props.name].selection,
|
||||
});
|
||||
|
||||
@@ -27,7 +27,7 @@ export class BadgeSelectionField extends Component {
|
||||
}
|
||||
|
||||
get string() {
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "many2one":
|
||||
return this.props.value ? this.props.value[1] : "";
|
||||
case "selection":
|
||||
@@ -40,7 +40,9 @@ export class BadgeSelectionField extends Component {
|
||||
}
|
||||
get value() {
|
||||
const rawValue = this.props.value;
|
||||
return this.props.type === "many2one" && rawValue ? rawValue[0] : rawValue;
|
||||
return this.props.record.fields[this.props.name].type === "many2one" && rawValue
|
||||
? rawValue[0]
|
||||
: rawValue;
|
||||
}
|
||||
|
||||
stringify(value) {
|
||||
@@ -51,7 +53,7 @@ export class BadgeSelectionField extends Component {
|
||||
* @param {string | number | false} value
|
||||
*/
|
||||
onChange(value) {
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "many2one":
|
||||
if (value === false) {
|
||||
this.props.record.update({ [this.props.name]: false });
|
||||
|
||||
@@ -28,11 +28,14 @@ class CopyClipboardField extends Component {
|
||||
}
|
||||
|
||||
get copyButtonClassName() {
|
||||
return `o_btn_${this.props.type}_copy btn-sm`;
|
||||
return `o_btn_${this.type}_copy btn-sm`;
|
||||
}
|
||||
get fieldProps() {
|
||||
return omit(this.props, "string", "disabledExpr");
|
||||
}
|
||||
get type() {
|
||||
return this.props.record.fields[this.props.name].type;
|
||||
}
|
||||
get disabled() {
|
||||
const context = this.props.record.evalContext;
|
||||
const evaluated = this.props.disabledExpr ? evaluateExpr(this.props.disabledExpr) : false;
|
||||
@@ -48,7 +51,7 @@ export class CopyClipboardButtonField extends CopyClipboardField {
|
||||
static components = { CopyButton };
|
||||
|
||||
get copyButtonClassName() {
|
||||
return `o_btn_${this.props.type}_copy rounded-2`;
|
||||
return `o_btn_${this.type}_copy rounded-2`;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -157,6 +157,7 @@ export class Field extends Component {
|
||||
delete props.showTooltip;
|
||||
delete props.fieldInfo;
|
||||
delete props.attrs;
|
||||
delete props.type;
|
||||
|
||||
return {
|
||||
...fieldInfo.props,
|
||||
@@ -165,7 +166,6 @@ export class Field extends Component {
|
||||
readonly: !record.isInEdition || readonlyFromModifiers || false,
|
||||
...propsFromAttrs,
|
||||
...props,
|
||||
type: field.type,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@ export class RadioField extends Component {
|
||||
return this.props.record.activeFields[this.props.name].string;
|
||||
}
|
||||
get value() {
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "selection":
|
||||
return this.props.value;
|
||||
case "many2one":
|
||||
@@ -56,7 +56,7 @@ export class RadioField extends Component {
|
||||
* @param {any} value
|
||||
*/
|
||||
onChange(value) {
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "selection":
|
||||
this.props.record.update({ [this.props.name]: value[0] });
|
||||
break;
|
||||
|
||||
@@ -43,7 +43,7 @@ export class ReferenceField extends Component {
|
||||
return p.record.preloadedData[p.name];
|
||||
}
|
||||
getValue(p) {
|
||||
if (p.type === "char") {
|
||||
if (p.record.fields[p.name].type === "char") {
|
||||
const pdata = this.getPreloadedData(p);
|
||||
if (!pdata) {
|
||||
return null;
|
||||
@@ -69,7 +69,10 @@ export class ReferenceField extends Component {
|
||||
return p;
|
||||
}
|
||||
get selection() {
|
||||
if (this.props.type !== "char" && !this.props.hideModelSelector) {
|
||||
if (
|
||||
this.props.record.fields[this.props.name].type !== "char" &&
|
||||
!this.props.hideModelSelector
|
||||
) {
|
||||
return this.props.record.fields[this.props.name].selection;
|
||||
}
|
||||
return [];
|
||||
|
||||
@@ -16,7 +16,7 @@ export class RemainingDaysField extends Component {
|
||||
};
|
||||
|
||||
get hasTime() {
|
||||
return this.props.type === "datetime";
|
||||
return this.props.record.fields[this.props.name].type === "datetime";
|
||||
}
|
||||
|
||||
get pickerComponent() {
|
||||
|
||||
@@ -26,7 +26,7 @@ export class SelectionField extends Component {
|
||||
}
|
||||
}
|
||||
get string() {
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "many2one":
|
||||
return this.props.value ? this.props.value[1] : "";
|
||||
case "selection":
|
||||
@@ -39,7 +39,9 @@ export class SelectionField extends Component {
|
||||
}
|
||||
get value() {
|
||||
const rawValue = this.props.value;
|
||||
return this.props.type === "many2one" && rawValue ? rawValue[0] : rawValue;
|
||||
return this.props.record.fields[this.props.name].type === "many2one" && rawValue
|
||||
? rawValue[0]
|
||||
: rawValue;
|
||||
}
|
||||
get isRequired() {
|
||||
return this.props.record.isRequired(this.props.name);
|
||||
@@ -54,7 +56,7 @@ export class SelectionField extends Component {
|
||||
*/
|
||||
onChange(ev) {
|
||||
const value = JSON.parse(ev.target.value);
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "many2one":
|
||||
if (value === false) {
|
||||
this.props.record.update({ [this.props.name]: false });
|
||||
|
||||
@@ -5,7 +5,6 @@ export const standardFieldProps = {
|
||||
name: { type: String, optional: true },
|
||||
readonly: { type: Boolean, optional: true },
|
||||
record: { type: Object },
|
||||
type: { type: String, optional: true },
|
||||
value: true,
|
||||
decorations: { type: Object, optional: true },
|
||||
setDirty: { type: Function, optional: true },
|
||||
|
||||
@@ -18,7 +18,7 @@ export class StatInfoField extends Component {
|
||||
};
|
||||
|
||||
get formattedValue() {
|
||||
const formatter = formatters.get(this.props.type);
|
||||
const formatter = formatters.get(this.props.record.fields[this.props.name].type);
|
||||
return formatter(this.props.value || 0, { digits: this.props.digits });
|
||||
}
|
||||
get label() {
|
||||
|
||||
@@ -168,7 +168,7 @@ export class StatusBarField extends Component {
|
||||
|
||||
computeItems(grouped = true) {
|
||||
let items = null;
|
||||
if (this.props.type === "many2one") {
|
||||
if (this.props.record.fields[this.props.name].type === "many2one") {
|
||||
items = this.getVisibleMany2Ones();
|
||||
} else {
|
||||
items = this.getVisibleSelection();
|
||||
@@ -196,7 +196,7 @@ export class StatusBarField extends Component {
|
||||
this.props.record.model.root instanceof this.props.record.constructor &&
|
||||
this.props.record.model.root;
|
||||
const isInEdition = rootRecord ? rootRecord.isInEdition : this.props.record.isInEdition;
|
||||
switch (this.props.type) {
|
||||
switch (this.props.record.fields[this.props.name].type) {
|
||||
case "many2one":
|
||||
this.props.record.update({ [this.props.name]: [item.id, item.name] });
|
||||
// We save only if we're on view mode readonly and no readonly field modifier
|
||||
|
||||
Reference in New Issue
Block a user