Skip to content

Commit 7cb73d4

Browse files
committed
[FIX] website_sale: prevent error when changing the delivery address
Currently, an error occurs when the user changing the delivery address in the website. Steps to reproduce: - Install the website_sale module and enable the Demo payment provider. - Go to Website > Shop > Add a product to Cart > View cart > Checkout. - Ensure there are at least two different delivery addresses > Confirm > Pay now. - Quickly press the browser’s back button twice. - Select a different delivery address. Error: ValueError: Expected singleton: sale.order() Root Cause: At [1], the code calls order.ensure_one(). When the cart (sale.order) is empty, leads to an error. Fix: This commit prevents a traceback on the frontend when a user attempts to change the delivery address and safely redirects them to the shop page. [1]: https://github.com/odoo/odoo/blob/88c9a45ee1ff8dde871865723c3387c059af8289/addons/delivery/models/delivery_carrier.py#L157 sentry-6869972801 closes odoo#233326 X-original-commit: 2b57313 Signed-off-by: Valentin Chevalier <vcr@odoo.com> Signed-off-by: Utsav Maru (utma) <utma@odoo.com>
1 parent 27b0568 commit 7cb73d4

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed

addons/website_sale/static/src/interactions/checkout.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,25 @@ export class Checkout extends Interaction {
3333
await this.waitFor(this._prepareDeliveryMethods());
3434
}
3535

36+
async start() {
37+
// Monitor when the page is restored from the bfcache.
38+
const boundOnNavigationBack = this._onNavigationBack.bind(this);
39+
window.addEventListener("pageshow", boundOnNavigationBack);
40+
this.registerCleanup(() => window.removeEventListener("pageshow", boundOnNavigationBack));
41+
}
42+
43+
/**
44+
* Reload the page when the page is restored from the bfcache.
45+
*
46+
* @param {PageTransitionEvent} event - The pageshow event.
47+
* @private
48+
*/
49+
_onNavigationBack(event) {
50+
if (event.persisted) {
51+
window.location.reload();
52+
}
53+
}
54+
3655
/**
3756
* Set the billing or delivery address on the order and update the corresponding card.
3857
*

0 commit comments

Comments
 (0)