[FIX] website_sale_aplicoop: clear cart when group order cutoff has passed

Previously, when a user reopened a group order whose cutoff day had
already passed, the /eskaera/check-status response correctly triggered
the localStorage cart clear, but _autoLoadDraftOnInit immediately
re-fetched the previous cycle's draft sale.order from /eskaera/load-draft
(which only guarded on group_order.state, not cutoff_date) and the stale
items reappeared in the cart, confusing users.

Add a cutoff_date < today guard to load_draft_cart so the endpoint
returns the existing clear_cart unavailable response, and short-circuit
_autoLoadDraftOnInit on the frontend via a _skipDraftAutoLoad flag set
in _checkGroupOrderStatus to avoid the now-pointless XHR round trip.

Covered by a new regression test in tests/test_group_order_status_endpoint.py.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
GitHub Copilot 2026-05-28 13:51:37 +02:00
parent 98ffcdaefb
commit b01794c319
3 changed files with 43 additions and 1 deletions

View file

@ -117,6 +117,11 @@
console.log("Attempting to auto-load draft order...");
var self = this;
if (this._skipDraftAutoLoad) {
console.log("Auto-load draft skipped (order closed or cutoff passed)");
return;
}
// Only auto-load if cart is empty
var cartItemsCount = Object.keys(this.cart).length;
if (cartItemsCount > 0) {
@ -506,6 +511,7 @@
shouldClear = true;
}
}
self._skipDraftAutoLoad = shouldClear;
if (shouldClear) {
console.log(
"[groupOrderShop] check-status: clearing cart (reason:",