Odoo Help


This community 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.


How to store field readonly in database with onchange method

on 10/22/14, 7:14 AM 3,805 views


How to store field readonly in database with onchange method

my code :

 def fret_change (self,cr, uid,ids ,tva_p,t_c,prix_d,fret_p,context):
        vals['p_achat_ht']= (t_c*prix_d)*(1+(fret_p/100))
        return {'value': vals}

def write(self,cr, uid, ids, vals, context=None):
        for rec in self.browse(cr, uid, ids, context=context):
            #Pass required value of fields in onchange
            res = self.fret_change(cr, uid, [rec.id], rec.tva_p, rec.t_c,rec.prix_d,rec.fret_p,context)
            if res.has_key('p_achat_ht'):
                vals.update({'p_achat_ht': res.get('p_achat_ht')})
        return super(product_product, self).write(cr, uid, ids, vals, context=context)

    def create(self,cr, uid, vals, context=None):
        #Pass required value of fields in onchange
        res = self.fret_change(cr, uid, [], vals.get('tva_p'),vals.get('t_c'), vals.get('prix_d'),vals.get('fret_p'),context)
        if res.has_key('p_achat_ht'):
            vals.update({'p_achat_ht': res.get('p_achat_ht')})
        return super(product_product, self).create(cr, uid, vals, context=context)


On 7/8/16, 3:51 AM

Hey! guys. We found a solution to store readonlyonchange in DB through below code.. CREATE edit, it will store in DB





def adding_samp(self):



def create(self,vals):

    if self.samp_cal3:


    res = super(tokenreservation, self).create(vals)

    return res


def write(self,vals):

    if not self.samp_cal3:

        vals['samp_cal3'] = self.samp_cal1+self.samp_cal2

    res = super(tokenreservation, self).write(vals)

    return res

Bharat Devnani
On 2/6/16, 12:57 AM

Dear All,

Kindly look at this blog post for solution https://bharatrdevnani.wordpress.com/2016/02/04/readonly-attributes-onchange-odoo/ surely it will help.



On 10/27/14, 7:32 AM

Hi friend, Usually when field is readonly and it gets input through on_change function after saving the record the value wont stored in database.So try below code:


In view_form.js:

in line: 840:

if (!f.get("readonly")) {

     values[f.name] = f.get_value(); }

else { readonly_values[f.name] = f.get_value(); }

     values[f.name] = f.get_value(); 

if (f.get("readonly")) 

   readonly_values[f.name] = f.get_value();



I think it will help you Thanks

Can you format your answer code more nicely. I think your solution could works.

Ben Bernard
on 10/27/14, 10:42 AM
sameer alhwety
On 5/4/15, 10:03 AM

If the field in new module you created you can making it functional field, but if the field already on system created by OpenERP/Odoo  don't change the field just create new field and save the value on it



| 5 4 7
Bangalore, India

Techno-Functional Associate with 6+ years of experience in Odoo (formerly known as OpenERP).

On 10/24/14, 9:24 AM

As the term indicates Readonly, meaning values are not changed in those fields, hence odoo will not consider those values while saving it into database....

So best way to handle is making it as Functional / Computational field... that way it will be readonly and as well value will computated and can be either stored or not-stored...

But still you wish to use basic/normal fields with readonly property, then in ORM methods both create & write method, call the onchange event and update your values for those readonly fields manually...


hey Dep..! we can change onchange readonly field and save it to DB.. look my code

on 7/8/16, 3:56 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

3 follower(s)


Asked: 10/22/14, 7:14 AM
Seen: 3805 times
Last updated: 7/8/16, 3:51 AM