add delivery vs. pickup checkout toggle, customize address form, and containerize Odoo services
This commit is contained in:
parent
ccc8dcd753
commit
0b867b9315
@ -409,6 +409,53 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
|
||||||
|
<!-- 4. UBER QUOTE ON REVIEW PAGE -->
|
||||||
|
<template id="chennora_checkout_review_uber" inherit_id="website_sale.checkout" name="Chennora Checkout Review Uber">
|
||||||
|
<xpath expr="//div[@id='wrap']" position="inside">
|
||||||
|
<script type="text/javascript">
|
||||||
|
document.addEventListener("DOMContentLoaded", function() {
|
||||||
|
// Only run if the order is for delivery
|
||||||
|
const isDelivery = "<t t-esc='website_sale_order.fulfilment_type'/>" === "delivery";
|
||||||
|
if (!isDelivery) return;
|
||||||
|
|
||||||
|
// Address data for re-calculating quote if needed
|
||||||
|
const addressData = {
|
||||||
|
street: "<t t-esc='website_sale_order.partner_shipping_id.street'/>",
|
||||||
|
city: "<t t-esc='website_sale_order.partner_shipping_id.city'/>",
|
||||||
|
zip: "<t t-esc='website_sale_order.partner_shipping_id.zip'/>",
|
||||||
|
country: "<t t-esc='website_sale_order.partner_shipping_id.country_id.name'/>"
|
||||||
|
};
|
||||||
|
|
||||||
|
if (addressData.street && addressData.zip) {
|
||||||
|
fetch('/shop/uber/quote', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: {'Content-Type': 'application/json'},
|
||||||
|
body: JSON.stringify({
|
||||||
|
params: { address_data: addressData }
|
||||||
|
})
|
||||||
|
}).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
|
||||||
|
// If we just added it to the cart, the page needs a refresh to show correctly
|
||||||
|
// But to avoid loops, only refresh if the amount was previously 0
|
||||||
|
const totalStr = document.querySelector('#amount_total_summary .oe_currency_value')?.innerText || '0';
|
||||||
|
const subtotalStr = document.querySelector('.monetary_field span')?.innerText || '0';
|
||||||
|
// Simple check: if summary doesn't seem to have the fee, refresh
|
||||||
|
// Better yet: just update the local UI? No, safest is to reload once.
|
||||||
|
if (window.location.search.indexOf('quoted=1') === -1) {
|
||||||
|
window.location.href = window.location.pathname + '?quoted=1';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
</xpath>
|
||||||
|
</template>
|
||||||
|
|
||||||
<!-- Custom Wizard - Rename Shipping step to Billing safely without python errors -->
|
<!-- Custom Wizard - Rename Shipping step to Billing safely without python errors -->
|
||||||
<template id="chennora_wizard_checkout_custom" inherit_id="website_sale.wizard_checkout" name="Chennora Wizard Custom" priority="99">
|
<template id="chennora_wizard_checkout_custom" inherit_id="website_sale.wizard_checkout" name="Chennora Wizard Custom" priority="99">
|
||||||
<xpath expr="//*[@t-call='website.step_wizard']" position="after">
|
<xpath expr="//*[@t-call='website.step_wizard']" position="after">
|
||||||
|
|||||||
@ -8,8 +8,15 @@ class SaleOrder(models.Model):
|
|||||||
config = self.env['uber.config'].sudo().search([('active', '=', True)], limit=1)
|
config = self.env['uber.config'].sudo().search([('active', '=', True)], limit=1)
|
||||||
if config and config.delivery_product_id:
|
if config and config.delivery_product_id:
|
||||||
fee_product = config.delivery_product_id
|
fee_product = config.delivery_product_id
|
||||||
# Check if fee line exists
|
# Ensure product is published so website_sale doesn't remove it from cart
|
||||||
fee_line = self.order_line.filtered(lambda l: l.product_id == fee_product)
|
if not fee_product.website_published:
|
||||||
|
fee_product.sudo().write({'website_published': True})
|
||||||
|
|
||||||
|
# Set fulfillment type on order
|
||||||
|
if hasattr(self, 'fulfilment_type'):
|
||||||
|
self.write({'fulfilment_type': 'delivery'})
|
||||||
|
|
||||||
|
fee_line = self.order_line.filtered(lambda l: l.product_id.id == fee_product.id)
|
||||||
if fee_line:
|
if fee_line:
|
||||||
fee_line.write({'price_unit': amount})
|
fee_line.write({'price_unit': amount})
|
||||||
else:
|
else:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user