From 58f7cbc1ef9aab564fc145b2663556f33a3c3bd4 Mon Sep 17 00:00:00 2001 From: mega-odoo Date: Wed, 9 Aug 2023 16:04:46 +0530 Subject: [PATCH] [FIX] website_payment: handle an error for empty donation amount When a user pays a donation with an empty amount value, the system passes this value as an empty string, which is leading to a type-casting error because an empty string cannot be directly converted to a numerical value like a float. Error: `ValueError: could not convert string to float: ` To handle this situation, we should use '_cast_as_int' and '_cast_as_float' methods because these methods provide try-except blocks, effectively handling these types of errors. This ensures that when an empty amount value is encountered, the system manages the error. sentry-4376573159 closes odoo/odoo#134026 X-original-commit: cae9f647b9e032aedfccc528d124acc639ecbf7f Signed-off-by: Antoine Vandevenne (anv) --- addons/website_payment/controllers/portal.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/addons/website_payment/controllers/portal.py b/addons/website_payment/controllers/portal.py index befa71237e1..f83d37f716f 100644 --- a/addons/website_payment/controllers/portal.py +++ b/addons/website_payment/controllers/portal.py @@ -23,8 +23,8 @@ class PaymentPortal(payment_portal.PaymentPortal): :raise: werkzeug.exceptions.NotFound if the access token is invalid """ kwargs['is_donation'] = True - kwargs['currency_id'] = int(kwargs.get('currency_id', request.env.company.currency_id.id)) - kwargs['amount'] = float(kwargs.get('amount', 25)) + kwargs['currency_id'] = self._cast_as_int(kwargs.get('currency_id')) or request.env.company.currency_id.id + kwargs['amount'] = self._cast_as_float(kwargs.get('amount')) or 25.0 kwargs['donation_options'] = kwargs.get('donation_options', json_safe.dumps(dict(customAmount="freeAmount"))) if request.env.user._is_public():