Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
5840 Lượt xem

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??


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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"

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
1
thg 10 22
2522
1
thg 8 19
1822
1
thg 9 17
4828
0
thg 4 23
4725
0
thg 6 22
2367