From f2a64b03e1e6d8ac4a0b32db96ea06f379123e9b Mon Sep 17 00:00:00 2001 From: Julien Van Roy Date: Mon, 23 Jan 2023 14:32:40 +0000 Subject: [PATCH] [IMP] sale,website_sale: add hooks to the checkout flow Add hooks before rendering the `website_sale.cart` and `website_sale.extra_info` templates. This allows to pass flags to trigger style variation in the checkout wizard (add an extra step). In addition, add the country_code to the sale_order view form, since it will be needed everytime we add l10n_* fields in this view (with attrs based on `country_code`). Related: https://github.com/odoo/enterprise/pull/35050/commits/fce5e682946cfa7d9e19c0c3c6abfab3dcbcc54a. task-3089169 closes odoo/odoo#108181 Related: odoo/enterprise#35050 Signed-off-by: Laurent Smet --- addons/sale/views/sale_order_views.xml | 1 + addons/website_sale/controllers/main.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/addons/sale/views/sale_order_views.xml b/addons/sale/views/sale_order_views.xml index 865b5ec2c46..5318c97f063 100644 --- a/addons/sale/views/sale_order_views.xml +++ b/addons/sale/views/sale_order_views.xml @@ -280,6 +280,7 @@ confirm="This will update all unit prices based on the currently set pricelist." attrs="{'invisible': ['|', ('show_update_pricelist', '=', False), ('state', 'in', ['sale', 'done', 'cancel'])]}"/> + diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index 3f0e3c111b5..626f4e39535 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -731,6 +731,13 @@ class WebsiteSale(http.Controller): order_sudo._cart_update_pricelist(update_pricelist=True) return request.redirect(redirect) + def _cart_values(self, **post): + """ + This method is a hook to pass additional values when rendering the 'website_sale.cart' template (e.g. add + a flag to trigger a style variation) + """ + return {} + @http.route(['/shop/cart'], type='http', auth="public", website=True, sitemap=False) def cart(self, access_token=None, revive='', **post): """ @@ -775,6 +782,7 @@ class WebsiteSale(http.Controller): # force no-cache so IE11 doesn't cache this XHR return request.render("website_sale.cart_popover", values, headers={'Cache-Control': 'no-cache'}) + values.update(self._cart_values(**post)) return request.render("website_sale.cart", values) @http.route(['/shop/cart/update'], type='http', auth="public", methods=['POST'], website=True) @@ -1380,6 +1388,13 @@ class WebsiteSale(http.Controller): # ------------------------------------------------------ # Extra step # ------------------------------------------------------ + def _extra_info_values(self, **post): + """ + This method is a hook to pass additional values when rendering the 'website_sale.extra_info' template (e.g. add + a flag to trigger a style variation) + """ + return {} + @http.route(['/shop/extra_info'], type='http', auth="public", website=True, sitemap=False) def extra_info(self, **post): # Check that this option is activated @@ -1400,6 +1415,7 @@ class WebsiteSale(http.Controller): 'partner': order.partner_id.id, 'order': order, } + values.update(self._extra_info_values(**post)) return request.render("website_sale.extra_info", values) # ------------------------------------------------------