[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) <anv@odoo.com>
This commit is contained in:
@@ -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():
|
||||
|
||||
Reference in New Issue
Block a user