Skip to Content
Menu
This question has been flagged
1 Reply
1986 Views

Hi,

I would like to filter sales orders to get only orders where ALL picking_ids.state = 'done'.

If I use the filter [('picking_ids.state', '=', 'done')] I get all orders where at least one picking_ids.state = done. 

What can I do to get orders where ALL picking_ids.state = done?

Avatar
Discard
Best Answer

Hi,

You can combine the search ORM method  with the filtered function like the below code:

order_ids = self.env['sale.order'].search([('picking_ids.state', '=', 'done')]).filtered(
lambda x: all(picking_id.state == 'done' for picking_id in x.picking_ids))

Best regards!

Avatar
Discard
Author

It's wokring! Thanks!