From fedede859edeba4f20e8258ebd272de479b1261a Mon Sep 17 00:00:00 2001 From: William Braeckman Date: Thu, 10 Nov 2022 09:56:51 +0000 Subject: [PATCH] [FIX] website_sale: fix traceback with express checkout It can happen that the payment transaction route is called without the amount kwargs, the code would crash in that case as we tried to access it either way. We moved the code after setting the default amount in the kwargs to avoid a crash. closes odoo/odoo#105576 X-original-commit: c124fb3292439a6237f16eff406c0a7d375cab65 Signed-off-by: William Braeckman (wbr) --- addons/website_sale/controllers/main.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/addons/website_sale/controllers/main.py b/addons/website_sale/controllers/main.py index dc127243818..c46c2928a06 100644 --- a/addons/website_sale/controllers/main.py +++ b/addons/website_sale/controllers/main.py @@ -1732,9 +1732,6 @@ class PaymentPortal(payment_portal.PaymentPortal): if order_sudo.state == "cancel": raise ValidationError(_("The order has been canceled.")) - if tools.float_compare(kwargs['amount'], order_sudo.amount_total, precision_rounding=order_sudo.currency_id.rounding): - raise ValidationError(_("The cart has been updated. Please refresh the page.")) - kwargs.update({ 'reference_prefix': None, # Allow the reference to be computed based on the order 'sale_order_id': order_id, # Include the SO to allow Subscriptions to tokenize the tx @@ -1742,6 +1739,10 @@ class PaymentPortal(payment_portal.PaymentPortal): kwargs.pop('custom_create_values', None) # Don't allow passing arbitrary create values if not kwargs.get('amount'): kwargs['amount'] = order_sudo.amount_total + + if tools.float_compare(kwargs['amount'], order_sudo.amount_total, precision_rounding=order_sudo.currency_id.rounding): + raise ValidationError(_("The cart has been updated. Please refresh the page.")) + tx_sudo = self._create_transaction( custom_create_values={'sale_order_ids': [Command.set([order_id])]}, **kwargs, )