Ir al contenido
Menú
Se marcó esta pregunta

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
Descartar
Mejor respuesta
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
Descartar
Publicaciones relacionadas Respuestas Vistas Actividad
2
jun 23
3584
1
ene 25
11327
3
feb 16
8826
3
abr 20
6469
1
abr 18
8285