Help

0

Domain on One2many Field using onchange method

Avatar
Ghulam Masood

We have a field "picking_type" on stock.picking model. 

I want to apply domain on "product_id" which is inside the "move_lines" field (as we know move_lines is o2m). 

Explanation: 

When ever there is a change in operations type(picking_type) while creating a transfer a domain shall be applied on product_id field in the move lines of transfer(stock.picking) object and i shall be able to select only the limited products i want. 

I have set a field on product form which links the operation type with the product. 

Here is My code: 

@api.onchange('picking_type_id')
def onchange_picking_operation_type(self):
    product_template_ids = self.env['product.template'].search([('picking_type_code', '=', self.picking_type_id.code)])
    product_product_ids = self.env['product.product'].search([('product_tmpl_id', 'in', product_template_ids.ids)])
    _logger.info('----------------Products-----------------'+ str(product_product_ids))
    return {'domain': {'move_lines': [('product_id', 'in', product_product_ids.ids)]}}

Am able to view the list of product ids clearly in logs but somehow the domain is not working. Can anyone point out how to implement the domain on a many2one field inside the one2many object??


1 Comment
Avatar
Discard
Avatar
Sehrish
-

Odoo Customization Tips: https://www.scoop.it/t/learn-openerp

1 Answer
0
Avatar
Oscar González
Best Answer

Have you tried something like this :

return {'domain': {'move_lines': [('product_id.id', 'in', product_product_ids.ids)]}}

??

instead of 'product_id' - > "product_id.id"

1 Comment
Avatar
Discard
Avatar
Ghulam Masood
-

This will not work becuase with this domain syntax the field is not getting updated at all. Moreover we cant specify the product_id.id on left side of the comparison operator. Thanks