[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 <las@odoo.com>
This commit is contained in:
Julien Van Roy
2023-01-26 18:51:01 +01:00
parent 0499bc1687
commit f2a64b03e1
2 changed files with 17 additions and 0 deletions
+1
View File
@@ -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'])]}"/>
</div>
<field name="country_code" invisible="1"/>
<field name="company_id" invisible="1"/>
<field name="currency_id" invisible="1"/>
<field name="pricelist_id" invisible="1"/>
+16
View File
@@ -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)
# ------------------------------------------------------