From 6e84d601c0bd0233c2a65d50fd5618662e96f88c Mon Sep 17 00:00:00 2001 From: Akim Juillerat Date: Tue, 2 Jan 2024 18:54:42 +0000 Subject: [PATCH] [IMP] website_sale: Add hook for custom search domain In case we want to search on other fields than name or default_code, or eventually on the descriptions, we need to reverse the domain that is built using AND and OR operators from osv.expression which is something we would prefer to avoid anytime. By adding a hook to add custom domains, it allows to search on whatever extra fields we would like to search on. closes odoo/odoo#159340 X-original-commit: 54c0b97594fb1f489163e993afd0df12cf877501 Signed-off-by: Victor Feyens (vfe) --- addons/website_sale/controllers/main.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index a8becd705f8..4326d5b998b 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -177,6 +177,9 @@ class WebsiteSale(payment_portal.PaymentPortal): order = post.get('order') or request.env['website'].get_current_website().shop_default_sort return 'is_published desc, %s, id desc' % order + def _add_search_subdomains_hook(self, search): + return [] + def _get_shop_domain(self, search, category, attrib_values, search_in_description=True): domains = [request.website.sale_product_domain()] if search: @@ -188,6 +191,9 @@ class WebsiteSale(payment_portal.PaymentPortal): if search_in_description: subdomains.append([('website_description', 'ilike', srch)]) subdomains.append([('description_sale', 'ilike', srch)]) + extra_subdomain = self._add_search_subdomains_hook(srch) + if extra_subdomain: + subdomains.append(extra_subdomain) domains.append(expression.OR(subdomains)) if category: