Odoo Help


Make a field non-editable after Save

aci aisha
on 2/5/15, 12:56 AM 5,733 views


I have a field field_type.Its a many2one.I have to make it non-editable after save it.

Ex:When i create a file 1st time i set field_type as "Trademark"..

     Then when i edit it the field_type should be read only





| 5 3 6
Jakarta, Indonesia
On 2/5/15, 3:08 AM

Redefine id as an integer field, put the id field in the view and use it in the attrs: attrs="{'readonly':[('id','>', 0)]}"

thanks ivan,but need som clarification

aci aisha
on 2/5/15, 3:11 AM

Sure @aci, what clarification do you need?

on 2/5/15, 3:23 AM

what u mean by id?

aci aisha
on 2/5/15, 3:26 AM

When you define a model, Odoo/OpenERP will always add 5 additional columns (in some of the codes they call it Magic Columns: id, create_uid, create_date, write_date, write_uid) which will be controlled by ORM. id is the Database ID which will be the unique identifier of the record and Primary Key of the table representing the record and id is only assigned after the record is saved for the first time. It is implemented as serial in PostgreSQL and hence will start with 1 and continue until limit is reached, never recycled. The create_ pairs will record who and when the record is created (_uid will be a FK to res.users and _date is a timestamp field), while write_ pair will record who and when the record is updated last via ORM. Unfortunately you cannot just use the column 'id' without defining it in _columns. That's why I say you need to re-define the column first as an integer column.

on 2/5/15, 3:36 AM

Ya Allah,,Confused!!!

aci aisha
on 2/5/15, 3:48 AM

Ivan plz help

aci aisha
on 2/5/15, 4:18 AM

Have you tried the solution? Create an integer field, call it 'id', include it in the view, and use it in attrs?

on 2/5/15, 4:39 AM

Ivan,try as u told,but the following error occured... Uncaught Error: Unknown field id in domain [["id",">",0]]

aci aisha
on 2/5/15, 4:42 AM

Have you include the 'id' field in the view?

on 2/5/15, 4:51 AM

yes, 'id' : fields.integer('ID'),

aci aisha
on 2/5/15, 6:29 AM

That is not the view @aci. The view is defined in XML, part of which you put in your answer.

on 2/5/15, 8:42 AM

Great Ivan..U R BRILLIANT!!!!

aci aisha
on 2/10/15, 7:35 AM

you are genius Mr Ivan

Nebil Aydi
on 12/16/17, 3:34 PM



| 5 3 8
Pondicherry, India
On 2/5/15, 2:34 AM

Add a boolean field in the py fiel and add the field in the view and make it as invisible,then use the following code:

<field name="dummy_field" invisible="1" />

<field name="field_type"  attrs="{'readonly':[('dummy_field','=', True)]}" on_change="onchange_file_type(file_type)" />

In the onhange method,check if the field_type is true,then make the boolean (dummy_field) as true

else False


On 2/5/15, 2:28 AM

as empiro tech said.. add a state field like draft...

whenever you create the record it should be set to draft...

like _defaults={




then in field set attrs="{'readonly':[('state','=','draft')]}"

This would be wery unprqactical... name state is reserved for states, and if you add more states , while using your code, the field would be readonly ONLY in draft state.... ( other models like account invoice , sales order etc...use reverse logic,,, 'readonly':[('state','!=',draft)]...

on 2/5/15, 2:43 AM

functionally it will right.. but conceptually wrong may be...

on 2/5/15, 2:45 AM

may be dummy field whic would do like this...

on 2/5/15, 2:46 AM

Emipro Technologies Pvt. Ltd.

--Emipro Technologies Pvt. Ltd.--
| 6 7 8
Rajkot, India
--Emipro Technologies Pvt. Ltd.--

Being an emerging leader in IT market since 2011, Emipro Technologies Pvt. Ltd. has been providing a wide range of business solutions in Odoo & Magento. We are pleased to have a large pool of contented customers with our meticulous work in the domain of ERP & e-Commerce. A ray of relief & satisfaction to  our customers heart by our successful deployment in their organization, purely represents our success in Odoo platform. Hence, we take pride for being an Odoo partner with a vision of expanding our strategic alliances with our customers to offer them high value-added, trustworthy & cost effective solutions.


Since establishment, our business has span across 11 countries of the world. Our customers are companies of all sizes ranging from start-ups to large enterprises, who realize that they need a professional business solutions to generate revenue streams, establish proper communication channels or streamline business operations. Standing with strong determination of customer satisfaction, observing each minute detail of their business processes, providing proper guidance and moving forth to develop product accordingly adds our value and reliability among our customers. 


We are blessed with efficient, passionate & eclectic young developers who have come across almost all kinds of business profiles, working with full dedication, applying creativity & new features in existing modules and completing customer's projects successfully on predefined target. Our in-depth knowledge while giving business solutions in Odoo allows us to offer following services to our customers :


  • Consulting
  • Installation, Configuration & Customization
  • Training & Support
  • Maintenance
  • Upgradation
  • Documentation
  • Crafting community modules
  • Drafting videos on demand
  • Smart Apps development

We will be :) to welcome you @ www.emiprotechnologies.com to solve any kind of your business needs around Odoo. However we are just an inch away from you by email info@emiprotechnologies.com or a tweet to @EmiproTech

Emipro Technologies Pvt. Ltd.
On 2/5/15, 1:04 AM

Try to add some kind of "state" and based on that you can make id readonly.

state is a field??

aci aisha
on 2/5/15, 1:06 AM

yes... ofcourse.. it is a field. Try looking the examples in sale order, purchase order, you will get better idea.

Emipro Technologies Pvt. Ltd.
on 2/5/15, 1:26 AM

But if i add a state field,Have i enter values there?

aci aisha
on 2/5/15, 1:30 AM
aci aisha
On 2/5/15, 3:19 AM

Thank you Every1 for ur co-operation...


When i use the following code it works,

                    <field name="file_type"  attrs="{'readonly':[('file_type','!=', False)]}" on_change="onchange_file_type(file_type)" /> 

That is when i select 1 value in file_type it becomes read only...

But when i try to save the file it cause the following error...!!


Odoo Warning

Integrity Error

The operation cannot be completed, probably due to the following:
- deletion: you may be trying to delete a record while other records still reference it
- creation/update: a mandatory field is not correctly set

[object with reference: file_type - file.type]

I also try this,,

    _columns = {
                'name' : fields.char('File No', readonly=True),
                #'file_type': fields.selection((('Trademark Registeration','Trademark Registeration'), ('Company Registeration','Company Registeration')),'File Type'),        
                'file_type': fields.many2one('file.type.details','File Type',required=True),
                'seq_id':fields.related('file_type','seq_id',type='char',string='Sequence ID'),        
                'application_no' : fields.char('Application No'),
                'classification_no' : fields.many2one('classification.details', 'Classification Number'),
                'classi_name' : fields.related('classification_no','classification_name',type='char',string= 'Classification Name'),
                'remarks' : fields.text('Remarks'),
                'file_status_id' : fields.many2one('file.status', 'Status', required=False),
                'a' : fields.char('a'),
                #'file_type' : _get_file_type
                'a' : 'a'


                    <field name="file_type"  attrs="{'readonly':[('a','=', 'a')]}" on_change="onchange_file_type(file_type)" /> 

But i cause the following error,

Error: Unknown field a in domain [["a","=","a"]]


See my comment in @Bole's answer.

on 2/5/15, 3:24 AM



| 5 4 6
Zagreb | Karlovac, Croatia

there is only 10 kind of people the ones that understand binary ... and others

On 2/5/15, 2:48 AM

The simplest way to do it is to define readonly state on the ffield ITSELF:.. in xml view definition... like:

<field name="your_field_name" attrs="{'readonly':[('your_field_name','=',False)]}" />

beware this will only allow to select value ONCE, and if you select wrong value, you need a mechanism to change it (just in case of error) . Such mechanism can be a wizard (allowerd for specific group  of users .. or something simmilar... )

Using field state to determine readonly state is most usual way to do it, but then the field remains in RW state until whole document changes state ... 

hop it helps..

how set wizard?

aci aisha
on 2/5/15, 3:01 AM

@Bole, I think that approach would not work. Once the field is populated, then it will be made readonly and hence the value would not be stored in the database. So, when the record is pulled up again, it would be empty and editable.

on 2/5/15, 3:11 AM

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

1 follower(s)


Asked: 2/5/15, 12:56 AM
Seen: 5733 times
Last updated: 12/28/17, 4:14 AM