From 36fdb2ff499136b8f5a6c1c1d842251c5e6e2c5b Mon Sep 17 00:00:00 2001 From: Romain Derie Date: Tue, 9 Jul 2019 18:09:10 +0200 Subject: [PATCH] [FIX] website_sale: restore possibility to remove promo code pricelist Since 5c9cea4ee7e, it was not possible to remove an applied promo code pricelist by adding an empty promo code on checkout (eg removing the one shown in the promo code input). Indeed, when sending an empty promo code, the `search()` done in the controller would not find any pricelist as promo would be en empty string. For the rest, check code on mentionned commit. See `sale_get_order()` method docstring about `code` param: "If empty, it's a special case to reset the pricelist with the first available else the default.". Fixes #34633 --- addons/website_sale/controllers/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 74f779667f1..d58b2447829 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -332,9 +332,11 @@ class WebsiteSale(http.Controller): @http.route(['/shop/pricelist'], type='http', auth="public", website=True) def pricelist(self, promo, **post): redirect = post.get('r', '/shop/cart') - pricelist = request.env['product.pricelist'].sudo().search([('code', '=', promo)], limit=1) - if not pricelist or (pricelist and not request.website.is_pricelist_available(pricelist.id)): - return request.redirect("%s?code_not_available=1" % redirect) + # empty promo code is used to reset/remove pricelist (see `sale_get_order()`) + if promo: + pricelist = request.env['product.pricelist'].sudo().search([('code', '=', promo)], limit=1) + if (not pricelist or (pricelist and not request.website.is_pricelist_available(pricelist.id))): + return request.redirect("%s?code_not_available=1" % redirect) request.website.sale_get_order(code=promo) return request.redirect(redirect)