From 53f72dcab154376190d71cd21f3d5d75e5960776 Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Fri, 12 Oct 2018 12:51:32 +0000 Subject: [PATCH] [FIX] website_sale: /shop 500 error if category is not model converter The /shop route can take a `category` argument (a model converter). `/shop/category/` But if that `category` argument is passed through URL query string (?category=9), it will raise an error when doing `category.can_access_from_current_website()` as it is an integer since it did not went through the model converter Note: Among probably others, that type of route is used when changing product order on shop Closes #27490, closes #27724 --- addons/website_sale/controllers/main.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 24be13bf049..c157b585669 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -189,8 +189,11 @@ class WebsiteSale(ProductConfiguratorController): '''/shop/category//page/''' ], type='http', auth="public", website=True) def shop(self, page=0, category=None, search='', ppg=False, **post): - if category and not category.can_access_from_current_website(): - raise NotFound() + if category: + category = request.env['product.public.category'].search([('id', '=', int(category))], limit=1) + if not category or not category.can_access_from_current_website(): + raise NotFound() + if ppg: try: ppg = int(ppg) @@ -200,11 +203,6 @@ class WebsiteSale(ProductConfiguratorController): else: ppg = PPG - if category: - category = request.env['product.public.category'].search([('id', '=', int(category))], limit=1) - if not category: - raise NotFound() - attrib_list = request.httprequest.args.getlist('attrib') attrib_values = [[int(x) for x in v.split("-")] for v in attrib_list if v] attributes_ids = {v[0] for v in attrib_values}