Good evening everyone. I want to remove the 'create and edit' option that appears when searching for data in many2many, many2one, and one2many fields. I have found the solution for many2one fields; here is the code for the solution:
/** @odoo-module **/ import {patch} from "@web/core/utils/patch"; import {many2OneField} from "@web/views/fields/many2one/many2one_field"; patch(many2OneField, { extractProps({ attrs, context, decorations, options, string }, dynamicInfo) { var res = super.extractProps({ attrs, context, decorations, options, string }, dynamicInfo) res.canQuickCreate = false res.canCreateEdit = false return res }, });
After doing some research, I believe I have found the object that will allow me to achieve the same behavior as many2one fields. This applies to both many2one and one2many fields.
The object is located in addons/web/static/src/views/fields/x2many/x2many_field.js.
Code:
export const x2ManyField = {
component: X2ManyField,
displayName: _t("Relational table"),
supportedTypes: ["one2many", "many2many"],
useSubView: true,
extractProps: (
{ attrs, relatedFields, viewMode, views, widget, options, string },
dynamicInfo
) => {
const props = {
addLabel: attrs["add-label"],
context: dynamicInfo.context,
domain: dynamicInfo.domain,
crudOptions: options,
string,
};
if (viewMode) {
props.views = views;
props.viewMode = viewMode;
props.relatedFields = relatedFields;
}
if (widget) {
props.widget = widget;
}
return props;
},
};
I tried to extend this object using the 'patch' function, but it doesn't work.
/** @odoo-module **/
import {patch} from "@web/core/utils/patch";
import {x2ManyField} from "@web/views/fields/x2many/x2many_field";
patch(x2ManyField, {
extractProps( { attrs, relatedFields, viewMode, views, widget, options, string }, dynamicInfo) {
var res = super.extractProps()
console.log(res)
}
});
According to the patch documentation, it informs us that super can only be used in a method and not in a function, which is why I can't extend it.
I need your help, any response will be useful (forums, documentation, etc.).
How can i disable create and edit functionality in many2one field for specific modal like product.template
following code is disable functionality for all many2one field but i need to disable for specific modal