Odoo Help


How to make specific field read-only after saving the record

Jagdish Panchal
on 12/11/13, 5:19 AM 3,244 views


How to make specific field read-only after saving the record? i.e. When I edit the record that field should be read-only


Ashif Abdulrahman
On 12/11/13, 5:50 AM

you have to do this one

add a boolean field in your model like

_columns = {
        'is_created' : fields.boolean('Created')

and in xml add attribute for the field to be made readonly, like,

<field name="your field name" position="attributes">
        <attribute name="attrs">{'readonly': [('is_created','=',True)]}</attribute>

and override create function in your model, like

def create(self, cr, uid, vals, context=None):
        vals['is_created'] = True
        lot = super(stock_production_lot, self).create(cr, uid, vals, context=context)
        return lot

Thanks for Ans.

Jagdish Panchal
on 12/11/13, 6:31 AM
Dipak Shah
On 1/29/18, 5:20 AM

Hello Jagdish,

> You can try this better and optimised way to make any field read only after saving a record,

> In your XML file please add 'attrs' on relevant field as below,

                 attrs="{'readonly': [('id', '!=', False)]}"


About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

0 follower(s)


Asked: 12/11/13, 5:19 AM
Seen: 3244 times
Last updated: 1/29/18, 5:20 AM