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

How to make a field editable only after saving the record in ODOO

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

您可以使用基于 id 字段的 readonly 属性来完成:

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

演示:

<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 是 odoo 中的默认字段,它在创建记录后取值,因此 name 字段在创建记录期间不应是可编辑的。