Odoo Help

Welcome!

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.

0

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

By
oussama
on 10/20/14, 6:26 AM 481 views

Hi

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={}
        vals['p_achat_ht']= (t_c*prix_d)*(1+(fret_p/100))
        self.write(cr, uid,ids, vals,context=context)
        return {'value': vals}

Thanks

0

Ivan

--Ivan--
3210
| 5 3 6
Jakarta, Indonesia
--Ivan--
Ivan
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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 10/20/14, 6:26 AM
Seen: 481 times
Last updated: 3/16/15, 8:10 AM