How to fetch all orders ids of same customer in many2many, the customer is selected by the res_partner field ?
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project management
- MRP
This question has been flagged
1
Reply
613
Views
Hello Dhiraj,
You can search orders using,
orders = self.env[<'order_model'>].search([(<'field_name_where_partner'>, '=', <partner_id>)])
Then can add in many2many using many2many_field = [(4, id) for id in orders]
Or you can execute following query,
SELECT partner_id, COUNT(*) FROM sale_order GROUP BY partner_id HAVING COUNT(*) > 1;