From b2e421bff27409db8f4fd317d0c13e252e7ca667 Mon Sep 17 00:00:00 2001 From: "Merel Geens (mege)" Date: Thu, 2 Feb 2023 10:19:58 +0000 Subject: [PATCH] [FIX] sale_loyalty: round real points for coupon `_get_real_points_for_coupon` subtracts several floats which can result in rounding errors when a comparison is made in `action_confirm` that checks if the result is smaller than 0. If the result is something like -1 * 10^-14, Odoo will tell the user the coupon is invalid, which is false. To prevent this from happening, we round according to the associated currency of the points. opw-3120442 closes odoo/odoo#112995 X-original-commit: 59c43f5cc460f311388540558e0fb0731b02cbc2 Signed-off-by: Yannick Tivisse (yti) --- addons/sale_loyalty/models/sale_order.py | 1 + 1 file changed, 1 insertion(+) diff --git a/addons/sale_loyalty/models/sale_order.py b/addons/sale_loyalty/models/sale_order.py index 810c7e02acf..5a8ba806a95 100644 --- a/addons/sale_loyalty/models/sale_order.py +++ b/addons/sale_loyalty/models/sale_order.py @@ -494,6 +494,7 @@ class SaleOrder(models.Model): points += self.coupon_point_ids.filtered(lambda p: p.coupon_id == coupon).points # Points already used by rewards points -= sum(self.order_line.filtered(lambda l: l.coupon_id == coupon).mapped('points_cost')) + points = coupon.currency_id.round(points) return points def _add_points_for_coupon(self, coupon_points):