set domain on many2one field via onchange function

vimal j

Im unable to set domain on many2one field via onchange function of another field.

For example i was checking if this function works in file.

xml of view

<field name="partner_id" on_change="onchange_partner_id(partner_id)" context="{'search_default_supplier':1,'default_supplier':1,'default_customer':0}" domain="[('supplier','=',True)]"/>

def onchange_partner_id(self, cr, uid, ids, partner_id):

    partner = self.pool.get('res.partner')
    if not partner_id:
        return {'value': {
            'fiscal_position': False,
            'payment_term_id': False,
    supplier_address = partner.address_get(cr, uid, [partner_id], ['default'])
    supplier = partner.browse(cr, uid, partner_id)
    return {'domain':{'product_id':[('purchase_ok','=',True)]},'value': {
        'fiscal_position': supplier.property_account_position and or False,
        'payment_term_id': or False,

The domain on field has been removed and i included that in previous function 'product_id': fields.many2one('product.product', 'Product', change_default=True)

My question is, the domain which i set on function is not reflecting when i click on product_id field. I am getting all products as list rather than purchasable products. It would be nice to know if someone points out what i'm missing.

Also should we set anything more on product_id field view? Presently it looks like this <field name="product_id" on_change="onchange_product_id(parent.pricelist_id,product_id,0,product_uom,parent.partner_id, parent.date_order,parent.fiscal_position,date_planned,name,price_unit,context)"/>

PS: Im just trying out how domain works with onchange function so i just did this minor change in core module to understand the concept. I know it isn't advisable to change core modules.

Thank you

1 Comment

Did you find any solution?