+
+
+
+
+
+
+ Community
+
+
+ Enterprise
+
+
+ Odoo.sh
+
+
+
+
+
+
+
+
+
+ In the Website/Shop Interface, Users have the
+ Capability to Specify Product Quantities Using Decimal
+ Values rather than being Limited to Whole Numbers.
+
+
Website Decimal Quantity
+
+
+
+

+
+
+
+

+
+
+
+

+
+
+

+
+
+
+
+
+
+
Key
+ Highlights
+
+
+
+
+

+
+
+
+
+ Allows to Select Quantity in Decimal for Products in Website.
+
+
+
+
+
+

+
+
+
+
+ Allows Users to Select Product in Decimal
+ Quantities from Product and Cart Page in Website/Shop.
+
+
+
+
+
+
+

+
+
+
+
+ Simultaneous Price Calculation in the Cart
+ According to the Selected Decimal Quantities.
+
+
+
+
+
+
+
+
+
Website Decimal Quantity
+
+ Are you ready to make your business more
+ organized?
+
Improve now!
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
+
+ Decimal Product Quantity in
+
+ Product Page.
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+ Decimal Product Quantity in
+
+ Cart Page.
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+ Simultaneous Price
+
+ Calculation in Cart.
+
+
+
+
+
+

+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Allows to Select Quantity in Decimal for Products in Website.
+
+
+
+
+
+
+
+
+
+
+
+ Allows Users to Select Product in Decimal
+ Quantities from Product and Cart Page in Website/Shop.
+
+
+
+
+
+
+
+
+
+
+ Simultaneous Price Calculation in the Cart
+ According to the Selected Decimal Quantities.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Pricing for decimal quantities
+ is handled based on your price
+ computation rules. If you set unit
+ prices for products that support decimals,
+ Odoo will calculate the price accordingly
+ based on the fractional quantity
+ selected by the customer.
+
+
+
+
+
+
+
+
+ Yes, if you use decimal
+ quantities in the Website/Shop interface,
+ the invoices generated for these orders
+ will reflect the fractional quantities
+ selected by the customers.
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ Latest Release 18.0.1.0.0
+
+
+ 12th November, 2024
+
+
+
+
+
+
+
+
+
+
+
+
+ Related Products
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/website_decimal_quantity/static/src/js/website_sale.js b/website_decimal_quantity/static/src/js/website_sale.js
new file mode 100644
index 000000000..fc806cc34
--- /dev/null
+++ b/website_decimal_quantity/static/src/js/website_sale.js
@@ -0,0 +1,84 @@
+/** @odoo-module **/
+
+import publicWidget from "@web/legacy/js/public/public_widget";
+import wSaleUtils from "@website_sale/js/website_sale_utils";
+import { rpc } from "@web/core/network/rpc";
+import { Component } from "@odoo/owl";
+
+
+publicWidget.registry.WebsiteSale.include({
+ /**
+* This module extends the website_sale module to support decimal quantity input for adding products to the cart.
+* It overrides the _onClickAddCartJSON function from sale.VariantMixin to add support for decimal quantity input,
+* and extends the WebsiteSale widget to handle updating cart quantities when a decimal quantity is entered.
+*/
+ _onClickAddCartJSON(ev) {
+ ev.preventDefault();
+ var $link = $(ev.currentTarget);
+ var $input = $link.closest('.input-group').find("input");
+ var min = parseFloat($input.data("min") || 0);
+ var max = parseFloat($input.data("max") || Infinity);
+ var previousQty = parseFloat($input.val() || 0, 10);
+ var quantity = ($link.has(".fa-minus").length ? -0.1 : 0.1) + previousQty;
+ var newQt = quantity > min ? (quantity < max ? quantity : max) : min;
+ if (newQt !== previousQty) {
+ var newQty = newQt.toFixed(1);
+ $input.val(newQty).trigger('change');
+ }
+ newQty = newQt.toFixed(1);
+ return false;
+ },
+ /** Override the function _changeCartQuantity for changing the cart quantity **/
+ _changeCartQuantity: function ($input, value, $dom_optional, line_id, productIDs) {
+ $($dom_optional).toArray().forEach((elem) => {
+
+ $(elem).find('.js_quantity').text(value);
+ productIDs.push($(elem).find('span[data-product-id]').data('product-id'));
+ });
+ $input.data('update_change', true);
+
+ rpc("/shop/cart/update_json", {
+ line_id: line_id,
+ product_id: parseInt($input.data('product-id'), 10),
+ set_qty: value,
+ display: true,
+ }).then((data) => {
+ $input.data('update_change', false);
+ var check_value = parseFloat($input.val());
+ if (isNaN(check_value)) {
+ check_value = 1;
+ }
+ if (value !== check_value) {
+ $input.trigger('change');
+ return;
+ }
+ if (!data.cart_quantity) {
+ return window.location = '/shop/cart';
+ }
+ $input.val(data.quantity);
+ $('.js_quantity[data-line-id='+line_id+']').val(data.quantity).text(data.quantity);
+
+ wSaleUtils.updateCartNavBar(data);
+ wSaleUtils.showWarning(data.notification_info.warning);
+ // Propagating the change to the express checkout forms
+ Component.env.bus.trigger('cart_amount_changed', [data.amount, data.minor_amount]);
+ });
+ },
+/** Override the function _onChangeCartQuantity **/
+ _onChangeCartQuantity: function (ev) {
+ ev.preventDefault();
+ var $input = $(ev.currentTarget);
+ if ($input.data('update_change')) {
+ return;
+ }
+ var value = parseFloat($input.val() || 0, 10);
+ if (isNaN(value)) {
+ value = 1;
+ }
+ var $dom = $input.closest('tr');
+ var $dom_optional = $dom.nextUntil(':not(.optional_product.info)');
+ var line_id = parseInt($input.data('line-id'), 10);
+ var productIDs = [parseInt($input.data('product-id'), 10)];
+ this._changeCartQuantity($input, value, $dom_optional, line_id, productIDs);
+ },
+});