Odoo Help


Field readonly don't stored in database when i use onchange method

on 10/20/14, 6:26 AM 503 views


Field readonly don't stored in database when i use onchange method

my method onchange is

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))
        self.write(cr, uid,ids, vals,context=context)
        return {'value': vals}




| 5 3 6
Jakarta, Indonesia
On 10/20/14, 7:10 AM

Yes, readonly field is not passed to the server when the object is saved.  What you need to do is inherit the write method, call the onchange method (fret_change), passing the information needed, get the method's return value and update the value that you use to write.  So roughly:

def write(self, cr, uid, ids, vals, context=context)

    for _obj in self.browse(cr, uid, ids, context=context):

        _tva_p = vals.get('tva_p', _obj.tva_p)

        _t_c = vals.get('t_c', _obj.t_c)

        _prix_d = vals.get('prix_d', _obj.prix_d)

        _fret_p = vals.get('fret_p', _obj.fret_p)

        _new_vals = _obj.fret_change(tva_p,t_c,prix_d,fret_p,context)

        _to_write = vals.copy()

        _to_write.update(_new_vals.get('values', {}))

        _obj.write(_to_write, context=context)

    return True


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 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: 10/20/14, 6:26 AM
Seen: 503 times
Last updated: 3/16/15, 8:10 AM