add delivery/pickup toggle to checkout, rename address fields, and configure Docker container names
This commit is contained in:
parent
2a98fac10d
commit
00ecad960f
@ -380,13 +380,43 @@
|
||||
|
||||
<!-- 4. UBER QUOTE RELOAD SCRIPT (Ensures fee is applied on page load) -->
|
||||
<xpath expr="//h4" position="after">
|
||||
<div id="uber_error" class="alert alert-danger d-none my-3" role="alert">
|
||||
<!-- Error message will be injected here -->
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
document.addEventListener("DOMContentLoaded", function() {
|
||||
const btn = document.querySelector('a[name="website_sale_main_button"]');
|
||||
const errorDiv = document.getElementById('uber_error');
|
||||
|
||||
// Helper to disable button
|
||||
const disableButton = () => {
|
||||
if (btn) {
|
||||
btn.classList.add('disabled', 'btn-secondary');
|
||||
btn.classList.remove('btn-primary');
|
||||
btn.style.pointerEvents = 'none';
|
||||
}
|
||||
};
|
||||
|
||||
// Helper to enable button
|
||||
const enableButton = () => {
|
||||
if (btn) {
|
||||
btn.classList.remove('disabled', 'btn-secondary');
|
||||
btn.classList.add('btn-primary');
|
||||
btn.style.pointerEvents = 'auto';
|
||||
}
|
||||
};
|
||||
|
||||
// Only run if the order is for delivery
|
||||
const isDelivery = "<t t-esc='order.fulfilment_type'/>" === "delivery";
|
||||
if (!isDelivery) return;
|
||||
if (!isDelivery) {
|
||||
enableButton();
|
||||
return;
|
||||
}
|
||||
|
||||
// Address data for re-calculating quote if needed
|
||||
// For delivery, disable by default until quoted
|
||||
disableButton();
|
||||
|
||||
// Address data for re-calculating quote
|
||||
const addressData = {
|
||||
street: "<t t-esc='order.partner_shipping_id.street'/>",
|
||||
city: "<t t-esc='order.partner_shipping_id.city'/>",
|
||||
@ -403,16 +433,32 @@
|
||||
})
|
||||
}).then(r => r.json()).then(data => {
|
||||
if (data.result && data.result.success) {
|
||||
// Refresh the summary if it changed (or just refresh the page once)
|
||||
if (data.result.fee > 0) {
|
||||
// Normally we would just update the UI, but Odoo summary is server-side
|
||||
// reload once to show the fee in the sidebar
|
||||
if (window.location.search.indexOf('quoted=1') === -1) {
|
||||
enableButton();
|
||||
if (errorDiv) errorDiv.classList.add('d-none');
|
||||
|
||||
if (data.result.fee >= 0) {
|
||||
// Refresh page once to show the fee in the sidebar if not already present
|
||||
const hasFee = <t t-esc="any(l.product_id.name == 'Uber Delivery Fee' for l in website_sale_order.order_line) and 'true' or 'false'"/>;
|
||||
if (!hasFee && window.location.search.indexOf('quoted=1') === -1) {
|
||||
window.location.href = window.location.pathname + '?quoted=1';
|
||||
}
|
||||
}
|
||||
} else {
|
||||
disableButton();
|
||||
if (errorDiv) {
|
||||
errorDiv.innerText = (data.result && data.result.error) ? data.result.error : "Uber delivery is not available for this location.";
|
||||
errorDiv.classList.remove('d-none');
|
||||
}
|
||||
}
|
||||
}).catch(err => {
|
||||
console.error("Uber Quote Fetch Error:", err);
|
||||
disableButton();
|
||||
});
|
||||
} else {
|
||||
if (errorDiv) {
|
||||
errorDiv.innerText = "Please provide a valid street address and ZIP code for delivery.";
|
||||
errorDiv.classList.remove('d-none');
|
||||
}
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@ -440,7 +486,7 @@
|
||||
<xpath expr="//tr[@id='order_total_untaxed']" position="after">
|
||||
<t t-set="uber_line" t-value="website_sale_order.order_line.filtered(lambda l: l.product_id.name == 'Uber Delivery Fee')"/>
|
||||
<tr t-if="uber_line">
|
||||
<td class="border-0 pb-2 ps-0 pt-0 text-start text-muted" colspan="2">Delivery</td>
|
||||
<td class="border-0 pb-2 ps-0 pt-0 text-start text-muted" colspan="2">Uber Delivery Fee</td>
|
||||
<td class="text-end border-0 pb-2 pe-0 pt-0">
|
||||
<span t-field="uber_line[0].price_subtotal" t-options='{"widget": "monetary", "display_currency": website_sale_order.currency_id}' class="monetary_field"/>
|
||||
</td>
|
||||
|
||||
@ -18,11 +18,14 @@ class SaleOrder(models.Model):
|
||||
|
||||
fee_line = self.order_line.filtered(lambda l: l.product_id.id == fee_product.id)
|
||||
if fee_line:
|
||||
fee_line.write({'price_unit': amount})
|
||||
fee_line.write({
|
||||
'price_unit': amount,
|
||||
'name': 'Uber Delivery Fee'
|
||||
})
|
||||
else:
|
||||
self.write({'order_line': [(0, 0, {
|
||||
'product_id': fee_product.id,
|
||||
'name': fee_product.name,
|
||||
'name': 'Uber Delivery Fee',
|
||||
'price_unit': amount,
|
||||
'product_uom_qty': 1,
|
||||
})]})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user