[FIX] website_sale_aplicoop: wire home delivery preference through all save flows

Three bugs prevented home_delivery from reaching sale.order:

1. #home-delivery-btn (shop sidebar) had no JS handler — clicking it did
   nothing. Now it toggles active state and persists choice to sessionStorage.

2. _executeSaveCartAsDraft (Save Cart button) never included is_delivery in
   the request body. Now reads the toggle button state (or the page-level
   data-home-delivery-enabled fallback) and sends is_delivery correctly.

3. #home-delivery-checkbox on checkout page was unchecked by default and
   always shown. Now it is pre-checked when group_order.home_delivery is
   True, wrapped in t-if to hide it when delivery is not configured, and
   synced bidirectionally with sessionStorage so the shop-page toggle state
   carries over to checkout.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
GitHub Copilot 2026-05-20 17:57:07 +02:00
parent a1899483c5
commit 27097004fb
2 changed files with 61 additions and 2 deletions

View file

@ -503,16 +503,17 @@
</t>
</div>
<div class="oe_structure oe_empty mb-4" data-name="After Summary" />
<t t-if="group_order.home_delivery">
<div class="card border-0 shadow-sm mb-4">
<div class="card-body">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="home-delivery-checkbox" name="home_delivery" />
<input type="checkbox" class="form-check-input" id="home-delivery-checkbox" name="home_delivery" checked="checked" />
<label class="form-check-label fw-bold" for="home-delivery-checkbox">Home Delivery</label>
</div>
<div id="delivery-info-alert" class="alert alert-info mt-3 d-none">
<p class="mb-2">
<i class="fa fa-truck" aria-hidden="true" t-translation="off" />
<t t-if="group_order.delivery_date and group_order.home_delivery">
<t t-if="group_order.delivery_date">
<strong>Delivery Information:</strong> Your order will be delivered at
<t t-esc="day_names[(int(group_order.pickup_day) + 1) % 7]" />
<t t-esc="group_order.delivery_date.strftime('%d/%m/%Y')" />
@ -525,6 +526,7 @@
</div>
</div>
</div>
</t>
<div class="checkout-actions d-grid gap-3" id="checkout-form-labels">
<button class="btn btn-success btn-lg" id="confirm-order-btn" t-attf-data-order-id="{{ group_order.id }}" t-att-data-confirmed-label="labels.get('order_saved_as_draft', 'Order saved as draft')" t-att-data-pickup-label="labels.get('pickup_day_label', 'Pickup Day')" t-att-aria-label="labels.get('save_order_as_draft', 'Save order as draft')" t-att-data-bs-title="labels.get('save_draft', 'Save Draft')" data-bs-toggle="tooltip">
<i class="fa fa-save" aria-hidden="true" t-translation="off" />