This post will help in creating many2one field whose value changes when the content of another field changes.

Lets consider a simple example. Suppose we have a many2one field to Product (name: product_id). We now want to change the content on this many2one field based on type selection box(name: type). Now, if I choose type as Service, only service type product should be visible in Product field.

To accomplish this, we have to define on change function on type selection box.

def onchange_type(self,cr,uid,ids, type,context=None):
    product_obj = self.pool.get('product.product')
    product_ids =,uid, [('type','=',type)])
    return {'domain':{'product_id':[('id','in',product_ids)]}}