diff --git a/odex25_ensan/odex_takaful/models/donation_details_lines.py b/odex25_ensan/odex_takaful/models/donation_details_lines.py index b08b7728f..a44af72f0 100644 --- a/odex25_ensan/odex_takaful/models/donation_details_lines.py +++ b/odex25_ensan/odex_takaful/models/donation_details_lines.py @@ -388,6 +388,7 @@ class DonationsDetailsLines(models.Model): "donation_types": 'donation', "name": product.name, "donation_qty": _qty, + "donation_amount": product.lst_price }) else: if existing: diff --git a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py index 1d2ea1bb2..63336a5a3 100644 --- a/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py +++ b/odex25_ensan/odex_takaful/models/takaful_sponorship_model.py @@ -328,6 +328,7 @@ class TakafulSponsorship(models.Model): "donation_types": 'donation', "name": product.name, "donation_qty": _qty, + "donation_amount": product.lst_price }) else: # remove if qty <= 0 diff --git a/odex25_ensan/odex_takaful/static/src/js/donation_catalog_controls.js b/odex25_ensan/odex_takaful/static/src/js/donation_catalog_controls.js index f4160cad6..b8faa33cb 100644 --- a/odex25_ensan/odex_takaful/static/src/js/donation_catalog_controls.js +++ b/odex25_ensan/odex_takaful/static/src/js/donation_catalog_controls.js @@ -3,6 +3,13 @@ // Attach event handlers immediately using event delegation // Odoo converts 'name' attribute to 'data-name' in rendered HTML +$(document).on('click', 'button[data-name="add_quantity_button_request"]', function(e) { + e.preventDefault(); + e.stopPropagation(); + handleQuantityChange($(this), 'first_add'); + return false; // ensure Odoo's default kanban action handler does not run +}); + $(document).on('click', 'button[data-name="add_quantity_button_so"]', function(e) { e.preventDefault(); e.stopPropagation(); @@ -24,6 +31,9 @@ window.__dc_add = function(btn) { window.__dc_remove = function(btn) { return __dc_handle(btn, 'remove'); }; +window.__dc_first_add = function(btn) { + return __dc_handle(btn, 'first_add'); +}; function __dc_handle(btn, operation) { try { @@ -36,6 +46,7 @@ function __dc_handle(btn, operation) { } async function handleQuantityChange($button, operation) { + // Get the kanban record (product card) container const $kanbanRecord = $button.closest('.o_kanban_record'); if (!$kanbanRecord.length) { @@ -43,24 +54,26 @@ async function handleQuantityChange($button, operation) { } // Get quantity display element from the button's parent container using stable custom classes - const $container = $button.closest('.dc-qty-controls'); - const $quantityDisplay = $container.find('.dc-qty-badge'); - - if (!$quantityDisplay.length) { - return; + let $container = $button.closest('.dc-qty-controls'); + if (operation === 'first_add'){ + $container = $kanbanRecord.find('.dc-qty-controls') } + let $quantityDisplay = $container.find('.dc-qty-badge'); + // if (!$quantityDisplay.length) { + // return; + // } // Extract product ID from the image URL const $img = $kanbanRecord.find('.o_kanban_image img'); - if (!$img.length) { - return; - } + // if (!$img.length) { + // return; + // } const imgSrc = $img.attr('src'); const match = imgSrc.match(/[&?]id=(\d+)/); - if (!match || !match[1]) { - return; - } + // if (!match || !match[1]) { + // return; + // } const productId = parseInt(match[1]); let currentQuantity = parseFloat($quantityDisplay.text()) || 0; @@ -68,10 +81,6 @@ async function handleQuantityChange($button, operation) { // Prevent going below zero for remove operation if (operation === 'remove' && currentQuantity <= 0) { - $quantityDisplay.addClass('bg-warning').removeClass('bg-secondary'); - setTimeout(() => { - $quantityDisplay.removeClass('bg-warning').addClass('bg-secondary'); - }, 300); return; } @@ -108,16 +117,22 @@ async function handleQuantityChange($button, operation) { // Calculate new quantity let newQuantity = currentQuantity; - if (operation === 'add') { - newQuantity += 1; - } else if (operation === 'remove') { - newQuantity -= 1; + if (operation === 'first_add'){ + $button.addClass('d-none'); + $kanbanRecord.find('.dc-qty-controls').removeClass("d-none"); + } + + if (operation === 'add' || operation === 'first_add') { + newQuantity = newQuantity + 1; + } + + if (operation === 'remove') { + newQuantity = newQuantity - 1; } // Update display optimistically $quantityDisplay.text(newQuantity.toFixed(2)); - try { // Call server to update quantity await $.ajax({ @@ -139,22 +154,13 @@ async function handleQuantityChange($button, operation) { throw info; }); - // Visual feedback - flash color based on operation - if (operation === 'add') { - $quantityDisplay.addClass('bg-success').removeClass('bg-secondary'); - } else { - $quantityDisplay.addClass('bg-info').removeClass('bg-secondary'); - } - setTimeout(() => { - $quantityDisplay.removeClass('bg-success bg-info').addClass('bg-secondary'); - }, 300); } catch (error) { // Revert on error $quantityDisplay.text(currentQuantity.toFixed(2)); - $quantityDisplay.addClass('bg-danger').removeClass('bg-secondary'); + // $quantityDisplay.addClass('bg-danger').removeClass('bg-secondary'); setTimeout(() => { - $quantityDisplay.removeClass('bg-danger').addClass('bg-secondary'); + // $quantityDisplay.removeClass('bg-danger').addClass('bg-secondary'); }, 1000); } finally { // Re-enable buttons diff --git a/odex25_ensan/odex_takaful/views/product_views.xml b/odex25_ensan/odex_takaful/views/product_views.xml index 4396d1eab..bdc236ef2 100644 --- a/odex25_ensan/odex_takaful/views/product_views.xml +++ b/odex25_ensan/odex_takaful/views/product_views.xml @@ -4,34 +4,37 @@ product.template - - - + + +
-
+ style="min-height: 100px;width: 25%;"> +
Product + alt="Product" class="o_image_64_contain" style="width: 100%;object-fit: cover;height: 100px;"/>
+
+ Amount: + +
-
+ style="justify-content: space-between;"> +
- +
-
    + @@ -40,77 +43,51 @@ -
+ +
- - + + - - - - - - - - - - -
- - - - - - - - +
+
+
+ +
+
+ +
+
+ +
+
- - - - - - - - - - - - - - - - - - -
@@ -119,6 +96,7 @@ + product.template.tree.sponsorship @@ -126,23 +104,24 @@
-
- - - + + +
odex.takaful.product.template.form.view product.template - + - + - + \ No newline at end of file