Skip to Content
Menu
Musisz się zarejestrować, aby móc wchodzić w interakcje z tą społecznością.
To pytanie dostało ostrzeżenie
1 Odpowiedz
1493 Widoki

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.).

 

Awatar
Odrzuć

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

/** @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
    },
});
Najlepsza odpowiedź

Hello Afri Kreto, 
 

You've already done this for many2one fields, and now you want to extend this behaviour to many2many and one2many fields. 
 
Your approach is on the right track, but the extractProps method in x2ManyField is a function, not a method, which is why using super is not directly applicable.
 

Here's how you can achieve this by modifying the x2ManyField module to disable quick create and create edit functionalities:

// Code In Comment //

I Hope this information proves helpful to you.

Thanks & Regards,
Email:  odoo@aktivsoftware.com           
Skype: kalpeshmaheshwari 

Awatar
Odrzuć

Code:

/* @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) {
const props = {
addLabel: attrs["add-label"],
context: dynamicInfo.context,
domain: dynamicInfo.domain,
crudOptions: { ...options, canQuickCreate: false, canCreateEdit: false },
string,
};
if (viewMode) {
props.views = views;
props.viewMode = viewMode;
props.relatedFields = relatedFields;
}
if (widget) {
props.widget = widget;
}
return props;
},
});

Powiązane posty Odpowiedzi Widoki Czynność
0
lis 24
1125
2
sty 25
926
0
lis 24
1185
2
lip 24
2614
2
kwi 25
1185