跳至内容
菜单
此问题已终结
1 回复
6210 查看

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