Skip to content

Commit 289b551

Browse files
authored
Merge pull request #30 from cormaza/13.0-fix-sales_product_filter
[13.0][FIX] sales_product_filter, change domain process to search in variants when comes from product template search
2 parents bf341b3 + f043ee9 commit 289b551

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

sales_product_filter/models/sale_order.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from odoo import api, fields, models
2+
from odoo.osv.expression import AND
23

34

45
class 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+
2839
class 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

Comments
 (0)