11from odoo import api , fields , models
2+ from odoo .osv .expression import AND
23
34
45class SaleOrderLine (models .Model ):
@@ -25,6 +26,16 @@ def search(self, args, offset=0, limit=None, order=None, count=False):
2526 return super (ProductProduct , self ).search (args , offset , limit , order , count )
2627
2728
29+ def add_product_variant_to_domain (args ):
30+ new_args = []
31+ for arg in args :
32+ if isinstance (arg , (list , tuple )):
33+ new_args .append ((f"product_variant_ids.{ arg [0 ]} " , arg [1 ], arg [2 ]))
34+ else :
35+ new_args .append (arg )
36+ return new_args
37+
38+
2839class ProductTemplate (models .Model ):
2940
3041 _inherit = "product.template"
@@ -33,11 +44,15 @@ class ProductTemplate(models.Model):
3344 def name_search (self , name = "" , args = None , operator = "ilike" , limit = 100 ):
3445 if self .env ["sale.product.filter" ].get_user_domains ():
3546 args = self .env ["sale.product.filter" ].get_user_domains ()
47+ args = add_product_variant_to_domain (args )
3648 return super (ProductTemplate , self ).name_search (name , args , operator , limit )
3749
3850 def search (self , args , offset = 0 , limit = None , order = None , count = False ):
3951 if self .env ["sale.product.filter" ].get_user_domains ():
4052 if not args :
4153 args = []
42- args += self .env ["sale.product.filter" ].get_user_domains ()
54+ domain = self .env ["sale.product.filter" ].get_user_domains ()
55+ domain = add_product_variant_to_domain (domain )
56+ if domain :
57+ args = AND ([args , domain ])
4358 return super (ProductTemplate , self ).search (args , offset , limit , order , count )
0 commit comments