Odoo Help

Welcome!

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.

0

set domain on many2one field via onchange function

By
vimal j
on 2/27/14, 4:08 AM 2,041 views

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

For example i was checking if this function works in purchase.py 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,
            },'domain':{'product_id':[('purchase_ok','=',True)]}}
    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': {
        'pricelist_id': supplier.property_product_pricelist_purchase.id,
        'fiscal_position': supplier.property_account_position and supplier.property_account_position.id or False,
        'payment_term_id': supplier.property_supplier_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

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)

Stats

Asked: 2/27/14, 4:08 AM
Seen: 2041 times
Last updated: 3/16/15, 8:10 AM