[IMP] website_sale: add hook to _get_checkout_steps for easier override

`_get_checkout_steps` didn't provide a friendly way to add steps in the
checkout flow. Developers had to reimplement part of the parent logic in 
their overrides.

This commit introduces `get_checkout_step_list`. This method will allow
an easier override of the checkout steps while keeping the logic to 
return a single step in the parent method.

closes odoo/odoo#158026

Signed-off-by: Valentin Chevalier <vcr@odoo.com>
This commit is contained in:
charliedao
2024-03-20 13:52:22 +00:00
parent 51701be864
commit 59fefc0a02
+14 -6
View File
@@ -564,14 +564,9 @@ class Website(models.Model):
return self.is_view_active('website_sale.address_b2b')
def _get_checkout_steps(self, current_step=None):
def _get_checkout_step_list(self):
""" Return an ordered list of steps according to the current template rendered.
If `current_step` is provided, returns only the corresponding step.
Note: self.ensure_one()
:param str current_step: The xmlid of the current step, defaults to None.
:rtype: list
:return: A list with the following structure:
[
@@ -620,6 +615,19 @@ class Website(models.Model):
'back_button': _lt("Back to cart"),
'back_button_href': '/shop/cart',
}))
return steps
def _get_checkout_steps(self, current_step=None):
""" Return an ordered list of steps according to the current template rendered.
If `current_step` is provided, returns only the corresponding step.
Note: self.ensure_one()
:param str current_step: The xmlid of the current step, defaults to None.
:rtype: list
:return: A list containing the steps generated by :meth:`_get_checkout_step_list`.
"""
self.ensure_one()
steps = self._get_checkout_step_list()
if current_step:
return next(step for step in steps if current_step in step[0])[1]