Pular para o conteúdo
Menu
Esta pergunta foi sinalizada
1 Responder
6204 Visualizações

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.

Avatar
Cancelar
Melhor resposta

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,

Avatar
Cancelar
Autor

Thanks, jignesh mehta