Skip to Content
เมนู
คุณต้องลงทะเบียนเพื่อโต้ตอบกับคอมมูนิตี้
คำถามนี้ถูกตั้งค่าสถานะ
3 ตอบกลับ
6139 มุมมอง

Do we have something like this? or do I have to add options="{'no_create': True, 'no_create_edit':True}" in every relational field?

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

Custom widget override (JS)

If you're dealing with many fields and want to prevent "create/edit" in many2one fields globally across a module or view, you can patch the relational field widgets in OWL (in Odoo 16+ / 17+ / 18):

/** @odoo-module **/


import { patch } from "@web/core/utils/patch";

import { Many2OneField } from "@web/views/fields/relational_fields/many2one_field";


patch(Many2OneField.prototype, {

    setup() {

        super.setup();

        this.props.options = {

            ...(this.props.options || {}),

            noCreate: true,

            noCreateEdit: true,

        };

    },

});


What This Does:

  • This automatically disables :
    • The "Create" option when typing something new in a Many2one field.
    • The "Create and Edit" option in the dropdown.
  • You do NOT need to write options="{'no_create': True} in XML anymore for each field.
  • It applies to all Many2one fields , unless explicitly overridden.

i hope it is usefull

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

You can use the "web_m2x_options" module for that.

https://github.com/OCA/web/tree/18.0/web_m2x_options

อวตาร
ละทิ้ง
คำตอบที่ดีที่สุด

Hi,

By default every relational field will have "Create and Edit" option.Currently there is no default method for restricting the Create and Edit for all relational fields at once.Instead we will have to mention options="{'no_create': True, 'no_create_edit':True}"  in xml every time when we declare relational fields.

Regards

อวตาร
ละทิ้ง
Related Posts ตอบกลับ มุมมอง กิจกรรม
Select multiple elements with XPath แก้ไขแล้ว
5
ส.ค. 24
47016
2
เม.ย. 24
2767
3
มิ.ย. 23
6169
2
มิ.ย. 23
4964
3
มี.ค. 23
10519