Odoo Help


How to store field readonly in database with onchange method

on 10/22/14, 7:14 AM 6,851 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

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
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/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
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

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

3 follower(s)


Asked: 10/22/14, 7:14 AM
Seen: 6851 times
Last updated: 12/7/16, 1:13 AM