From a4e46846d73ea042731eecdb47322c206968a32e Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 8 Oct 2018 13:16:51 +0000 Subject: [PATCH] [FIX] point_of_sale: float comparison - Create the following pricelist for product A: 4 Units: 2.88 3 Units: 3.45 2 Units: 4.85 1 Units: 7.50 - In the POS, click several time on A to add in the cart The 2 first units are merged in a single line, but from the third one a new line is created. This is because of the float reproesentation of 4.85, which becomes 4.8500000000000005. opw-1887586 closes odoo/odoo#27539 --- addons/point_of_sale/static/src/js/models.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/addons/point_of_sale/static/src/js/models.js b/addons/point_of_sale/static/src/js/models.js index 185e41332a5..07393366aed 100644 --- a/addons/point_of_sale/static/src/js/models.js +++ b/addons/point_of_sale/static/src/js/models.js @@ -1508,6 +1508,7 @@ exports.Orderline = Backbone.Model.extend({ // when we add an new orderline we want to merge it with the last line to see reduce the number of items // in the orderline. This returns true if it makes sense to merge the two can_be_merged_with: function(orderline){ + var price = parseFloat(round_di(this.price || 0, this.pos.dp['Product Price']).toFixed(this.pos.dp['Product Price'])); if( this.get_product().id !== orderline.get_product().id){ //only orderline of the same product can be merged return false; }else if(!this.get_unit() || !this.get_unit().is_pos_groupable){ @@ -1516,7 +1517,7 @@ exports.Orderline = Backbone.Model.extend({ return false; }else if(this.get_discount() > 0){ // we don't merge discounted orderlines return false; - }else if(this.price !== orderline.get_product().get_price(orderline.order.pricelist, this.get_quantity())){ + }else if(price !== orderline.get_product().get_price(orderline.order.pricelist, this.get_quantity())){ return false; }else if(this.product.tracking == 'lot') { return false;