[FIX] point_of_sale: avoid rounding error when merging order lines

Before this commit when multiple instances of the same product
were selected in a PoS session, `can_be_merged_with` checked if they
had the same price before merging them in a single order line. However
the order line prices were not rounded. In the case of a floating
point error in order line price calculation, this behavior resulted
in multiple order lines for the same product.

Steps to reproduce the issue:
1. Create a product
2. In the pricelist, create a formula of -10% discount based on cost,
and set the cost as 136.35 $
3. Open a POS session, add the product multiple times
4. The products are not combined in one group, each creates their
own order line

To fix this issue, we need to round the order line prices in this
function.

opw-2854304

closes odoo/odoo#96410

X-original-commit: 254521d302b31acd5b6f6cfbf49c184035b30eb0
Signed-off-by: Masereel Pierre <pim@odoo.com>
This commit is contained in:
Ahmad Khanalizadeh
2022-07-25 12:39:57 +02:00
parent 8b62d124bf
commit 08138a3322
+1 -1
View File
@@ -1668,7 +1668,7 @@ class Orderline extends PosModel {
can_be_merged_with(orderline){
var price = parseFloat(round_di(this.price || 0, this.pos.dp['Product Price']).toFixed(this.pos.dp['Product Price']));
var order_line_price = orderline.get_product().get_price(orderline.order.pricelist, this.get_quantity());
order_line_price = orderline.compute_fixed_price(order_line_price);
order_line_price = round_di(orderline.compute_fixed_price(order_line_price), this.pos.currency.decimal_places);
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){