This question has been flagged
1909 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
Avatar
Discard