From 488d6e97de1ce7e3cdedb148409723dcdda62c0d Mon Sep 17 00:00:00 2001 From: CarlosRoca13 Date: Tue, 24 May 2022 10:30:26 +0000 Subject: [PATCH] [IMP] website_sale: Make options of _search_with_fuzzy inheritable Before this change we would have to use other ways to add filtering forms in e-commerce. For example, using the context of the request in 'product.template' to catch what we need in the _search_get_detail method. After these changes, we will not need to pass the context of the request outside the controller because it will be the _search_with_fuzzy options that will give us the information we need for inheritance. closes odoo/odoo#94858 X-original-commit: d29f2f3ac5f8c3e8109287e0933609bdbe0cadb1 Signed-off-by: William Braeckman (wbr) --- addons/website_sale/controllers/main.py | 39 ++++++++++++++++--------- 1 file changed, 26 insertions(+), 13 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 4e9569405b4..abbcc36c919 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -199,6 +199,23 @@ class WebsiteSale(http.Controller): if not qs or qs.lower() in loc: yield {'loc': loc} + def _get_search_options( + self, category=None, attrib_values=None, pricelist=None, min_price=0.0, max_price=0.0, conversion_rate=1, **post + ): + return { + 'displayDescription': True, + 'displayDetail': True, + 'displayExtraDetail': True, + 'displayExtraLink': True, + 'displayImage': True, + 'allowFuzzy': not post.get('noFuzzy'), + 'category': str(category.id) if category else None, + 'min_price': min_price / conversion_rate, + 'max_price': max_price / conversion_rate, + 'attrib_values': attrib_values, + 'display_currency': pricelist.currency_id, + } + @http.route([ '/shop', '/shop/page/', @@ -266,19 +283,15 @@ class WebsiteSale(http.Controller): if attrib_list: post['attrib'] = attrib_list - options = { - 'displayDescription': True, - 'displayDetail': True, - 'displayExtraDetail': True, - 'displayExtraLink': True, - 'displayImage': True, - 'allowFuzzy': not post.get('noFuzzy'), - 'category': str(category.id) if category else None, - 'min_price': min_price / conversion_rate, - 'max_price': max_price / conversion_rate, - 'attrib_values': attrib_values, - 'display_currency': pricelist.currency_id, - } + options = self._get_search_options( + category=category, + attrib_values=attrib_values, + pricelist=pricelist, + min_price=min_price, + max_price=max_price, + conversion_rate=conversion_rate, + **post + ) # No limit because attributes are obtained from complete product list product_count, details, fuzzy_search_term = website._search_with_fuzzy("products_only", search, limit=None, order=self._get_search_order(post), options=options)