[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
This commit is contained in:
Nicolas Martinelli
2018-10-08 13:16:51 +00:00
parent 1b5f14713b
commit a4e46846d7
+2 -1
View File
@@ -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;