Odoo Help


Does on_change need to be reset for subsequent changes to fire?

on 3/21/13, 4:57 PM 495 views

I have some related fields setup with an on_change event handler and it works fine the 1st time the initial value is changed but changing the value back or to yet another value does not seem to fire the event again. Is there something I need to flush or clear for the event to work on subsequent changes? Here is example code:

_columns = {    
    'code': fields.char('Commodity Code', size=255,  translate=False,  required=True,  readonly=False),
    'title':fields.char('Commodity Title', size=255,  translate=True,  required=True, readonly=False), 
    'id':fields.integer('Commodity Code Id',  required=True, readonly=True), 
    'category_id':fields.many2one('commodity.category', 'Category Id', ondelete='restrict', required=False, readonly=False),
    'category_child_prefix':fields.related('category_id', 'category_child_prefix', string="Prefix", type='char', relation='commodity.category', readonly=False),
    'category_child_name':fields.related('category_id', 'category_child_name', string="Subcategory", type='char', relation='commodity.category', readonly=False)
def onchange_category_id(self, cr, uid, category_id, context=None):
    """Returns new category child prefix and child name values based on category_id
    @param category_id: The new category id selected by user
    @return dictionary with dictionary of values with key ['value']
    res = {'value': {'category_child_prefix': False, 'category_child_name': False}}
    cat = None
    if category_id:
        cat = self.pool.get('commodity.category').browse(cr, uid, category_id)
        res['value'] = {'category_child_prefix': cat[0].category_child_prefix,
                         'category_child_name': cat[0].category_child_name}

    return res

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

0 follower(s)


Asked: 3/21/13, 4:57 PM
Seen: 495 times
Last updated: 3/16/15, 8:10 AM