[REF] web,mail: handle "color_field" option in M2MTagsField
Before this commit, there was a hack done in Field.js to handle a special case of the Many2ManyTagsField which sometimes require an additional "color" field to be fetched. This field is given in option on the many2many field, in the arch. It wasn't possible for the Many2ManyTags field to add that field on its "FieldToFetch", because this object was static (it didn't depend on the arch). This commit allows it to do so as FieldsToFetch can now be a function that receives the fieldInfo (extracted from the arch) in arguments. So with this commit, fieldsToFetch can be either an array of fields (instead of an object as before), or a function returning an array of fields. Part of task 3179751 closes odoo/odoo#112518 Related: odoo/enterprise#37020 Signed-off-by: Georis François (fge) <fge@odoo.com>
This commit is contained in:
@@ -87,9 +87,9 @@ FieldMany2ManyTagsEmail.components = {
|
||||
TagsList: FieldMany2ManyTagsEmailTagsList,
|
||||
};
|
||||
|
||||
FieldMany2ManyTagsEmail.fieldsToFetch = Object.assign({}, Many2ManyTagsField.fieldsToFetch, {
|
||||
email: { name: "email", type: "char" },
|
||||
});
|
||||
FieldMany2ManyTagsEmail.fieldsToFetch = (fieldInfo) => {
|
||||
return [...Many2ManyTagsField.fieldsToFetch(fieldInfo), { name: "email", type: "char" }];
|
||||
};
|
||||
|
||||
FieldMany2ManyTagsEmail.additionalClasses = ["o_field_many2many_tags"];
|
||||
|
||||
|
||||
@@ -279,17 +279,16 @@ Field.parseFieldNode = function (node, models, modelName, viewType, jsClass) {
|
||||
viewMode = viewMode.replace("tree", "list");
|
||||
}
|
||||
fieldInfo.viewMode = viewMode;
|
||||
|
||||
const fieldsToFetch = { ...fieldInfo.FieldComponent.fieldsToFetch }; // should become an array?
|
||||
// special case for color field
|
||||
// GES: this is not nice, we will look for something better.
|
||||
const colorField = fieldInfo.options.color_field;
|
||||
if (colorField) {
|
||||
fieldsToFetch[colorField] = { name: colorField, type: "integer", active: true };
|
||||
}
|
||||
fieldInfo.fieldsToFetch = fieldsToFetch;
|
||||
fieldInfo.relation = field.relation; // not really necessary
|
||||
fieldInfo.views = views;
|
||||
|
||||
let fieldsToFetch = fieldInfo.FieldComponent.fieldsToFetch;
|
||||
if (fieldsToFetch) {
|
||||
if (fieldsToFetch instanceof Function) {
|
||||
fieldsToFetch = fieldsToFetch(fieldInfo);
|
||||
}
|
||||
fieldInfo.fieldsToFetch = Object.fromEntries(fieldsToFetch.map((f) => [f.name, f]));
|
||||
}
|
||||
}
|
||||
|
||||
return fieldInfo;
|
||||
|
||||
@@ -56,10 +56,10 @@ Many2ManyBinaryField.props = {
|
||||
uploadText: { type: String, optional: true },
|
||||
};
|
||||
Many2ManyBinaryField.supportedTypes = ["many2many"];
|
||||
Many2ManyBinaryField.fieldsToFetch = {
|
||||
name: { type: "char" },
|
||||
mimetype: { type: "char" },
|
||||
};
|
||||
Many2ManyBinaryField.fieldsToFetch = [
|
||||
{ name: "name", type: "char" },
|
||||
{ name: "mimetype", type: "char" },
|
||||
];
|
||||
|
||||
Many2ManyBinaryField.isEmpty = () => false;
|
||||
Many2ManyBinaryField.extractProps = ({ attrs, field }) => {
|
||||
|
||||
@@ -245,8 +245,12 @@ Many2ManyTagsField.defaultProps = {
|
||||
|
||||
Many2ManyTagsField.displayName = _lt("Tags");
|
||||
Many2ManyTagsField.supportedTypes = ["many2many"];
|
||||
Many2ManyTagsField.fieldsToFetch = {
|
||||
display_name: { name: "display_name", type: "char" },
|
||||
Many2ManyTagsField.fieldsToFetch = (fieldInfo) => {
|
||||
const fieldsToFetch = [{ name: "display_name", type: "char" }];
|
||||
if (fieldInfo.options.color_field) {
|
||||
fieldsToFetch.push({ name: fieldInfo.options.color_field, type: "integer" });
|
||||
}
|
||||
return fieldsToFetch;
|
||||
};
|
||||
Many2ManyTagsField.isSet = (value) => value.count > 0;
|
||||
|
||||
|
||||
@@ -115,10 +115,15 @@ export function mapActiveFieldsToFieldsInfo(activeFields, fields, viewType, env)
|
||||
}
|
||||
|
||||
if (!fieldInfo.__no_fetch && FieldComponent && FieldComponent.fieldsToFetch) {
|
||||
fieldInfo.relatedFields = { ...FieldComponent.fieldsToFetch };
|
||||
let fieldsToFetch = FieldComponent.fieldsToFetch;
|
||||
if (fieldsToFetch instanceof Function) {
|
||||
fieldsToFetch = fieldsToFetch(fieldInfo.__WOWL_FIELD_DESCR__);
|
||||
}
|
||||
fieldsToFetch = Object.fromEntries(fieldsToFetch.map((f) => [f.name, f]));
|
||||
fieldInfo.relatedFields = { ...fieldsToFetch };
|
||||
fieldInfo.viewType = "default";
|
||||
const defaultView = {};
|
||||
for (const fieldName of Object.keys(FieldComponent.fieldsToFetch)) {
|
||||
for (const fieldName of Object.keys(fieldsToFetch)) {
|
||||
defaultView[fieldName] = {};
|
||||
if (fieldDescr.fieldsToFetch[fieldName]) {
|
||||
defaultView[fieldName].__WOWL_FIELD_DESCR__ =
|
||||
@@ -126,15 +131,6 @@ export function mapActiveFieldsToFieldsInfo(activeFields, fields, viewType, env)
|
||||
}
|
||||
}
|
||||
fieldInfo.fieldsInfo = { default: defaultView };
|
||||
const colorField = fieldInfo.options && fieldInfo.options.color_field;
|
||||
if (colorField) {
|
||||
fieldInfo.relatedFields[colorField] = { type: "integer" };
|
||||
fieldInfo.fieldsInfo.default[colorField] = {};
|
||||
if (fieldDescr.fieldsToFetch[colorField]) {
|
||||
fieldInfo.fieldsInfo.default[colorField].__WOWL_FIELD_DESCR__ =
|
||||
fieldDescr.fieldsToFetch[colorField];
|
||||
}
|
||||
}
|
||||
}
|
||||
if (fieldDescr.views && fieldDescr.views[fieldDescr.viewMode]) {
|
||||
fieldInfo.limit = fieldDescr.views[fieldDescr.viewMode].limit || 40;
|
||||
|
||||
Reference in New Issue
Block a user