Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged

Hello,


In a new sale order I want to filter only products that have been previously ordered by the selected partner.


Any suggestions ?


Working on Odoo Community 13.


Thank you!

Avatar
Opusti
Best Answer
Hi, 
your query is: When you create a SO, list of possible products to be selected must only be the previous ones that were purchased by the selected client. 

In this case:
1- Onchange on partner_id.
2- If partner_id is changed, then:
   A. Get all products in previous customer's Orders  : product_ids = self.partner_id.sale_order_ids.mapped('order_line.product_id')
   B. add domain to product_id in order line.

In sale.order.line,the function should look like this:

@api.onchange('order_partner_id')
def onchange_order_partner_id(self):
     domain = []
     if self.order_partner_id != self._origin.order_partner_id:
            if self.product_id:
                   self.product_id = False  ( you may want this to make product_id empty )
            product_ids =self.order_partner_id.sale_order_ids.mapped('order_line.product_id')
            domain += [('id', 'in', product_ids.ids)]
    return {'domain':{'product_id': domain}}




i hope this helps.
Avatar
Opusti
Related Posts Odgovori Prikazi Aktivnost
2
jun. 23
3546
1
jan. 25
11189
3
feb. 16
8723
3
apr. 20
6381
1
apr. 18
8193