From cc8c036f878fcf03c6c547fdc9760fbf5bc23759 Mon Sep 17 00:00:00 2001
From: "Anh Thao Pham (pta)" <pta@odoo.com>
Date: Thu, 9 Jul 2020 13:23:06 +0000
Subject: [PATCH] [FIX] payment: use currency precision when comparing amounts
 in Payment Link wizard

In Sales, in Payment Link generation wizard, when entering manually the total of the quotation
as Amount, it can happen that the Validation Error asking to set an Amount smaller than the total
is triggered.

opw-2287794

closes odoo/odoo#54309

X-original-commit: a7034b75383f23f309d97a86cbde7d9f8176ed6d
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
---
 addons/payment/wizards/payment_link_wizard.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/addons/payment/wizards/payment_link_wizard.py b/addons/payment/wizards/payment_link_wizard.py
index 57b3ec1282d0..54de9a31d963 100644
--- a/addons/payment/wizards/payment_link_wizard.py
+++ b/addons/payment/wizards/payment_link_wizard.py
@@ -7,7 +7,7 @@ from werkzeug import urls
 
 from odoo import api, fields, models, _
 from odoo.exceptions import ValidationError
-from odoo.tools import ustr, consteq
+from odoo.tools import ustr, consteq, float_compare
 
 
 class PaymentLinkWizard(models.TransientModel):
@@ -46,7 +46,7 @@ class PaymentLinkWizard(models.TransientModel):
 
     @api.onchange('amount', 'description')
     def _onchange_amount(self):
-        if self.amount_max < self.amount:
+        if float_compare(self.amount_max, self.amount, precision_rounding=self.currency_id.rounding or 0.01) == -1:
             raise ValidationError(_("Please set an amount smaller than %s.") % (self.amount_max))
         if self.amount <= 0:
             raise ValidationError(_("The value of the payment amount must be positive."))
-- 
GitLab