implement Uber delivery fee integration on checkout page and update docker container naming conventions

This commit is contained in:
Alaguraj0361 2026-04-06 20:52:34 +05:30
parent d121f6f492
commit 46ef774508

View File

@ -1,15 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<!-- Display Uber fee in the 'Delivery' row of the total summary -->
<!-- Display Uber fee in the total summary -->
<template id="chennora_total_uber_display" inherit_id="website_sale.total" name="Chennora Total Uber Display">
<!-- Intercept Subtotal to subtract Uber fee if it was included -->
<xpath expr="//tr[@id='order_total_untaxed']//span[@t-field='website_sale_order.amount_untaxed']" position="replace">
<t t-set="uber_line" t-value="website_sale_order.order_line.filtered(lambda l: l.product_id.name == 'Uber Delivery Fee')"/>
<t t-set="uber_fee" t-value="sum(uber_line.mapped('price_subtotal')) if uber_line else 0.0"/>
<span t-esc="website_sale_order.amount_untaxed - uber_fee" t-options='{"widget": "monetary", "display_currency": website_sale_order.currency_id}' class="monetary_field"/>
</xpath>
<!-- Add/Update Delivery Row -->
<!-- Add Uber Delivery Row without touching the existing Subtotal to avoid JS crashes -->
<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" id="uber_delivery_row">
@ -30,9 +23,13 @@
<!-- Custom Checkout Page Logic -->
<template id="chennora_checkout_custom" inherit_id="website_sale.checkout" name="Chennora Checkout Custom" priority="99">
<!-- 1. Script for Uber Quote -->
<xpath expr="//h4[1]" position="before">
<!-- Add error banner -->
<xpath expr="//div[hasclass('oe_cart')]" position="before">
<div id="uber_error" class="alert alert-danger d-none my-3" role="alert"></div>
</xpath>
<!-- Script for Uber Quote -->
<xpath expr="//footer" position="after">
<script type="text/javascript">
(function() {
function initUberQuote() {
@ -42,19 +39,16 @@
const errorDiv = document.getElementById('uber_error');
if (!btn) {
console.warn("Uber: Checkout button not found, retrying...");
setTimeout(initUberQuote, 500);
return;
}
// Helper to disable button
const disableButton = () => {
btn.classList.add('disabled', 'btn-secondary');
btn.classList.remove('btn-primary');
btn.style.pointerEvents = 'none';
};
// Helper to enable button
const enableButton = () => {
btn.classList.remove('disabled', 'btn-secondary');
btn.classList.add('btn-primary');
@ -67,7 +61,7 @@
return;
}
// For delivery, disable by default
// For delivery, disable by default to force check
disableButton();
const addressData = {
@ -78,18 +72,16 @@
};
if (addressData.street &amp;&amp; addressData.zip) {
console.log("Uber: Requesting quote for", addressData);
fetch('/shop/uber/quote', {
method: 'POST',
headers: {'Content-Type': 'application/json'},
body: JSON.stringify({ params: { address_data: addressData } })
}).then(r => r.json()).then(data => {
console.log("Uber: Quote result", data.result);
console.log("Uber: Result", data.result);
if (data.result &amp;&amp; data.result.success) {
enableButton();
if (errorDiv) errorDiv.classList.add('d-none');
// Refresh if fee not shown
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'"/>" === "true";
if (!hasFee &amp;&amp; window.location.search.indexOf('quoted=1') === -1) {
window.location.href = window.location.pathname + '?quoted=1';
@ -97,12 +89,13 @@
} else {
disableButton();
if (errorDiv) {
errorDiv.innerText = (data.result &amp;&amp; data.result.error) ? data.result.error : "Delivery not available.";
errorDiv.innerText = (data.result &amp;&amp; data.result.error) ? data.result.error : "Uber delivery is not available for this address.";
errorDiv.classList.remove('d-none');
}
}
}).catch(err => {
console.error("Uber: Fetch error", err);
console.error("Uber Fetch error", err);
enableButton(); // Fallback to let them try to payment
});
}
}