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.


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

on 3/21/13, 4:57 PM 455 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 community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

0 follower(s)


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