Using (Sale Order) onchange Function how to add return domain for (Sale Order Line) one2many table Product ID Field?..
In Default onchange domain return example available for same table and column.
Example: return {'domain': {'column_name': [('id', 'in', listids)]}}
But how to add domain in one2many table Field using onchange method ?..
Requirement:- Sale Order based on Partner selection dynamic add domain in Sale Order Line Product Field.
Code:
def onchange_partner_id(self, cr, uid, ids, part, context=None):
res = super(sale_order, self).onchange_partner_id(cr, uid, ids, part, context=context)
res['value'].update({'order_line': []})
if part:
product_obj = self.pool.get('product.product')
matching_cust_ids = product_obj.search(cr, uid, [('x_cust_name','=',part)])
res['value'].update({'custproduct_id': matching_cust_ids})
domain = {'domain':{'order_line.product_id': [('order_line.id', '=', matching_cust_ids)]}}
res['value']['order_line'].append(domain)
return res
Issue: The above code return domain for one2many table product Field is not working.
For more background, what we were trying to do earlier (https://www.odoo.com/forum/help-1/question/limiting-customers-to-specific-products-58972) is link a customer and a product using a field on many2one field on the product page - 'x_cust_name': fields.many2one('res.partner', 'Customer', store=True). Ideally the module would only display the products that have the 'x_cust_name" equal to the name of the customer on the Sales Order.
Prakash - Janeesh's solution below worked! I think we were seriously overthinking things. Thanks again for your help, I really appreciate it.