跳至內容
選單
此問題已被標幟
1 回覆
6246 瀏覽次數

Is it possible to create a field which become read only once it is created.I need to create a record in which one of the field should be read only but it should be editable at the time of creation so that the record can be created.

頭像
捨棄
最佳答案

Hello Abhijith soman,


May be you can achieve this from below code:


In PY :-

from openerp import models, fields, api

class ClassName(models.Model):
    _name = 'class.name'

    @api.model
    def create(self, vals):
        result = super(ClassName, self).create(vals)
        self.is_create = True
        return result

    is_create = fields.Boolean('Is Create?')
    readonly_field = fields.Char('Readonly Field')


In XML :-

<record id="class_name_form_view" model="ir.ui.view">
    <field name="name">class.name.form.view</field>
    <field name="model">class.name</field>
    <field name="arch" type="xml">
        <form string="Name">
            <sheet>
                <field name="is_create" invisible="1"/>
                <field name="readonly_field" attrs="{'readonly' : [('is_create', '=', True)]}"/>
               </sheet>
        </form>
    </field>
</record>


Hope it will works for you.

Thanks,

頭像
捨棄
作者

Thanks, jignesh mehta