如何在ODOO中保存记录后才能使字段可编辑

时间:2021-02-27 18:52:26

I have a field in odoo. I want it to be non-editable during the creation of record. After saving the record, if we again edit it , then it should be editable

我有一个字段在odoo。我希望它在创建记录期间不可编辑。保存记录后,如果我们再次编辑它,那么它应该是可编辑的

1 个解决方案

#1


3  

You can do it with readonly attribute base on id field:

您可以使用id字段的readonly属性来执行此操作:

<field name='id' invisible='True'/>
<field name="field_name" attrs="{'readonly': [('id','=', False )]}"/>

Demo:

演示:

<record model="ir.ui.view" id="session_form_view">
    <field name="name">session.form</field>
    <field name="model">openacademy.session</field>
    <field name="arch" type="xml">
        <form string="Session Form">
           <field name='id' invisible='True'/>
           <field name="name" attrs="{'readonly': [('id','=', False )]}"/>
        </form>
    </field>
</record>

id is a default field in odoo and it takes a value after creation of the record so name field should not be editable during creation of the record.

id是odoo中的默认字段,它在创建记录后获取值,因此在创建记录期间不应编辑名称字段。

#1


3  

You can do it with readonly attribute base on id field:

您可以使用id字段的readonly属性来执行此操作:

<field name='id' invisible='True'/>
<field name="field_name" attrs="{'readonly': [('id','=', False )]}"/>

Demo:

演示:

<record model="ir.ui.view" id="session_form_view">
    <field name="name">session.form</field>
    <field name="model">openacademy.session</field>
    <field name="arch" type="xml">
        <form string="Session Form">
           <field name='id' invisible='True'/>
           <field name="name" attrs="{'readonly': [('id','=', False )]}"/>
        </form>
    </field>
</record>

id is a default field in odoo and it takes a value after creation of the record so name field should not be editable during creation of the record.

id是odoo中的默认字段,它在创建记录后获取值,因此在创建记录期间不应编辑名称字段。