|  | @ -4,7 +4,6 @@ import publicWidget from "@web/legacy/js/public/public_widget"; | 
			
		
	
		
		
			
				
					|  |  | import wSaleUtils from "@website_sale/js/website_sale_utils"; |  |  | import wSaleUtils from "@website_sale/js/website_sale_utils"; | 
			
		
	
		
		
			
				
					|  |  | import { Component } from "@odoo/owl"; |  |  | import { Component } from "@odoo/owl"; | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  | publicWidget.registry.WebsiteSale.include({ |  |  | publicWidget.registry.WebsiteSale.include({ | 
			
		
	
		
		
			
				
					|  |  |  /** |  |  |  /** | 
			
		
	
		
		
			
				
					|  |  | * This module extends the website_sale module to support decimal quantity input for adding products to the cart. |  |  | * This module extends the website_sale module to support decimal quantity input for adding products to the cart. | 
			
		
	
	
		
		
			
				
					|  | @ -13,29 +12,34 @@ publicWidget.registry.WebsiteSale.include({ | 
			
		
	
		
		
			
				
					|  |  | */ |  |  | */ | 
			
		
	
		
		
			
				
					|  |  |     _onClickAddCartJSON(ev) { |  |  |     _onClickAddCartJSON(ev) { | 
			
		
	
		
		
			
				
					|  |  |         ev.preventDefault(); |  |  |         ev.preventDefault(); | 
			
		
	
		
		
			
				
					
					|  |  |         var $link = $(ev.currentTarget); |  |  |         const $link = $(ev.currentTarget); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var $input = $link.closest('.input-group').find("input"); |  |  |         const $input = $link.closest('.input-group').find("input"); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var min = parseFloat($input.data("min") || 0); |  |  |         const min = parseFloat($input.attr("min")) || 0.01; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var max = parseFloat($input.data("max") || Infinity); |  |  |         const max = parseFloat($input.attr("max")) || Infinity; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var previousQty = parseFloat($input.val() || 0, 10); |  |  |         const step = parseFloat($input.attr("step")) || 0.1; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var quantity = ($link.has(".fa-minus").length ? -0.1 : 0.1) + previousQty; |  |  |         const previousQty = parseFloat($input.val()) || 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var newQt = quantity > min ? (quantity < max ? quantity : max) : min; |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if (newQt !== previousQty) { |  |  |         const isMinus = $link.find(".fa-minus").length > 0; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             var newQty = newQt.toFixed(1); |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             $input.val(newQty).trigger('change'); |  |  |         let newQty = isMinus ? previousQty - step : previousQty + step; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         } |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         newQty = newQt.toFixed(1); |  |  |         if (newQty < min) newQty = min; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |         if (newQty > max) newQty = max; | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         const precision = step < 1 ? step.toString().split('.')[1]?.length || 1 : 0; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         newQty = parseFloat(newQty.toFixed(precision)); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         $input.val(newQty).trigger('change'); | 
			
		
	
		
		
			
				
					|  |  |         return false; |  |  |         return false; | 
			
		
	
		
		
			
				
					|  |  |     }, |  |  |     }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |     /**  Override the function  _changeCartQuantity for changing the cart quantity **/ |  |  |     /**  Override the function  _changeCartQuantity for changing the cart quantity **/ | 
			
		
	
		
		
			
				
					
					|  |  |     _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) { |  |  |     _changeCartQuantity($input, value, $dom_optional, line_id, productIDs) { | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |         $($dom_optional).toArray().forEach((elem) => { |  |  |         $($dom_optional).toArray().forEach((elem) => { | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  |  | 
			
		
	
		
		
			
				
					|  |  |             $(elem).find('.js_quantity').text(value); |  |  |             $(elem).find('.js_quantity').text(value); | 
			
		
	
		
		
			
				
					|  |  |             productIDs.push($(elem).find('span[data-product-id]').data('product-id')); |  |  |             productIDs.push($(elem).find('span[data-product-id]').data('product-id')); | 
			
		
	
		
		
			
				
					|  |  |         }); |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |         $input.data('update_change', true); |  |  |  | 
			
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         $input.data('update_change', true); | 
			
		
	
		
		
			
				
					|  |  |         this.rpc("/shop/cart/update_json", { |  |  |         this.rpc("/shop/cart/update_json", { | 
			
		
	
		
		
			
				
					|  |  |             line_id: line_id, |  |  |             line_id: line_id, | 
			
		
	
		
		
			
				
					|  |  |             product_id: parseInt($input.data('product-id'), 10), |  |  |             product_id: parseInt($input.data('product-id'), 10), | 
			
		
	
	
		
		
			
				
					|  | @ -43,41 +47,64 @@ publicWidget.registry.WebsiteSale.include({ | 
			
		
	
		
		
			
				
					|  |  |             display: true, |  |  |             display: true, | 
			
		
	
		
		
			
				
					|  |  |         }).then((data) => { |  |  |         }).then((data) => { | 
			
		
	
		
		
			
				
					|  |  |             $input.data('update_change', false); |  |  |             $input.data('update_change', false); | 
			
		
	
		
		
			
				
					
					|  |  |             var check_value = parseFloat($input.val()); |  |  |             let check_value = parseFloat($input.val()); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             if (isNaN(check_value)) { |  |  |             if (isNaN(check_value)) check_value = value; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |                 check_value = 1; |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					|  |  |             } |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |             if (value !== check_value) { |  |  |             if (value !== check_value) { | 
			
		
	
		
		
			
				
					|  |  |                 $input.trigger('change'); |  |  |                 $input.trigger('change'); | 
			
		
	
		
		
			
				
					|  |  |                 return; |  |  |                 return; | 
			
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |             if (!data.cart_quantity) { |  |  |             if (!data.cart_quantity) { | 
			
		
	
		
		
			
				
					
					|  |  |                 return window.location = '/shop/cart'; |  |  |                 return (window.location = '/shop/cart'); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |             } |  |  |             } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |             $input.val(data.quantity); |  |  |             $input.val(data.quantity); | 
			
		
	
		
		
			
				
					
					|  |  |             $('.js_quantity[data-line-id='+line_id+']').val(data.quantity).text(data.quantity); |  |  |             $('.js_quantity[data-line-id=' + line_id + ']').val(data.quantity).text(data.quantity); | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  | 
 |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |             wSaleUtils.updateCartNavBar(data); |  |  |             wSaleUtils.updateCartNavBar(data); | 
			
		
	
		
		
			
				
					|  |  |             wSaleUtils.showWarning(data.notification_info.warning); |  |  |             wSaleUtils.showWarning(data.notification_info.warning); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |             // Propagating the change to the express checkout forms
 |  |  |             // Propagating the change to the express checkout forms
 | 
			
		
	
		
		
			
				
					|  |  |             Component.env.bus.trigger('cart_amount_changed', [data.amount, data.minor_amount]); |  |  |             Component.env.bus.trigger('cart_amount_changed', [data.amount, data.minor_amount]); | 
			
		
	
		
		
			
				
					|  |  |         }); |  |  |         }); | 
			
		
	
		
		
			
				
					|  |  |     }, |  |  |     }, | 
			
		
	
		
		
			
				
					
					|  |  | /**  Override the function  _onChangeCartQuantity **/ |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |     _onChangeCartQuantity: function (ev) { |  |  |    /**  Override the function  _onChangeCartQuantity **/ | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |     _onChangeCartQuantity(ev) { | 
			
		
	
		
		
			
				
					|  |  |         ev.preventDefault(); |  |  |         ev.preventDefault(); | 
			
		
	
		
		
			
				
					
					|  |  |         var $input = $(ev.currentTarget); |  |  |         const $input = $(ev.currentTarget); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         if ($input.data('update_change')) { |  |  |         if ($input.data('update_change')) return; | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |             return; |  |  | 
 | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         } |  |  |         let value = parseFloat($input.val()); | 
			
				
				
			
		
	
		
		
			
				
					|  |  |         var value = parseFloat($input.val() || 0, 10); |  |  |  | 
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |         if (isNaN(value)) { |  |  |         if (isNaN(value)) { | 
			
		
	
		
		
			
				
					
					|  |  |             value = 1; |  |  |             value = parseFloat($input.attr("min")) || 0.01; | 
			
				
				
			
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  |         } else if (value < 0) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             value = parseFloat($input.attr("min")) || 0.01; | 
			
		
	
		
		
			
				
					|  |  |         } |  |  |         } | 
			
		
	
		
		
			
				
					
					|  |  |         var $dom = $input.closest('tr'); |  |  |         const $dom = $input.closest('tr'); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var $dom_optional = $dom.nextUntil(':not(.optional_product.info)'); |  |  |         const $dom_optional = $dom.nextUntil(':not(.optional_product.info)'); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var line_id = parseInt($input.data('line-id'), 10); |  |  |         const line_id = parseInt($input.data('line-id'), 10); | 
			
				
				
			
		
	
		
		
			
				
					
					|  |  |         var productIDs = [parseInt($input.data('product-id'), 10)]; |  |  |         const productIDs = [parseInt($input.data('product-id'), 10)]; | 
			
				
				
			
		
	
		
		
	
		
		
	
		
		
	
		
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |         this._changeCartQuantity($input, value, $dom_optional, line_id, productIDs); |  |  |         this._changeCartQuantity($input, value, $dom_optional, line_id, productIDs); | 
			
		
	
		
		
			
				
					|  |  |     }, |  |  |     }, | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     async _onClickDelete(ev) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         ev.preventDefault(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         ev.stopPropagation(); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         const tr = ev.currentTarget.closest('tr'); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         const line_id = parseInt(tr.dataset.lineId); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         const $input = $(tr).find('.js_quantity'); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         if (!line_id || !$input.length) { | 
			
		
	
		
		
			
				
					|  |  |  |  |  |             return; | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         await this._changeCartQuantity($input, 0, [], line_id, []); | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         $(tr).fadeOut(300, () => $(tr).remove()); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |         setTimeout(() => window.location.reload(), 400); | 
			
		
	
		
		
			
				
					|  |  |  |  |  |     } | 
			
		
	
		
		
			
				
					|  |  |  |  |  | 
 | 
			
		
	
		
		
			
				
					|  |  | }); |  |  | }); | 
			
		
	
	
		
		
			
				
					|  | 
 |