From b7181334a9857d1012335dd396c5a85d97eee4c2 Mon Sep 17 00:00:00 2001 From: "Antoine Vandevenne (anv)" Date: Tue, 19 Jul 2022 15:12:47 +0000 Subject: [PATCH] [REF] payment: reuse the transaction status template wherever possible The alert block content and style for the transaction status after payment were computed in two different places: In the dedicated `payment.transaction_status` QWeb template, and in the /payment/confirmation` route's controller which, for some reason, was re-inventing the wheel instead of relying on the dedicated template. This commit combines the slightly different behaviors in the template and gets rid of the duplicated logic in the controller to: - Handle the states 'draft' and 'error'. - Always show the transaction's state message, and not only when the transaction was in a state for which there exists no pre-defined message (`draft` and `error`). task-2924873 closes odoo/odoo#96348 Signed-off-by: Antoine Vandevenne (anv) --- addons/payment/__manifest__.py | 1 + addons/payment/controllers/portal.py | 33 ++--------- .../static/src/scss/payment_templates.scss | 3 + .../views/payment_portal_templates.xml | 12 +--- addons/payment/views/payment_templates.xml | 57 ++++++++++++------- .../views/payment_transfer_templates.xml | 2 +- 6 files changed, 48 insertions(+), 60 deletions(-) create mode 100644 addons/payment/static/src/scss/payment_templates.scss diff --git a/addons/payment/__manifest__.py b/addons/payment/__manifest__.py index 241c9c32c0c..4b7e5b17484 100644 --- a/addons/payment/__manifest__.py +++ b/addons/payment/__manifest__.py @@ -36,6 +36,7 @@ 'assets': { 'web.assets_frontend': [ 'payment/static/src/scss/portal_payment.scss', + 'payment/static/src/scss/payment_templates.scss', 'payment/static/src/scss/payment_form.scss', 'payment/static/lib/jquery.payment/jquery.payment.js', 'payment/static/src/js/checkout_form.js', diff --git a/addons/payment/controllers/portal.py b/addons/payment/controllers/portal.py index 8a87eabd0e2..08d0207f5bc 100644 --- a/addons/payment/controllers/portal.py +++ b/addons/payment/controllers/portal.py @@ -371,7 +371,7 @@ class PaymentPortal(portal.CustomerPortal): @http.route('/payment/confirmation', type='http', methods=['GET'], auth='public', website=True) def payment_confirm(self, tx_id, access_token, **kwargs): - """ Display the payment confirmation page with the appropriate status message to the user. + """ Display the payment confirmation page to the user. :param str tx_id: The transaction to confirm, as a `payment.transaction` id :param str access_token: The access token used to verify the user @@ -388,36 +388,11 @@ class PaymentPortal(portal.CustomerPortal): ): raise werkzeug.exceptions.NotFound # Don't leak info about existence of an id - # Fetch the appropriate status message configured on the acquirer - if tx_sudo.state == 'draft': - status = 'info' - message = tx_sudo.state_message \ - or _("This payment has not been processed yet.") - elif tx_sudo.state == 'pending': - status = 'warning' - message = tx_sudo.acquirer_id.pending_msg - elif tx_sudo.state == 'authorized': - status = 'success' - message = tx_sudo.acquirer_id.auth_msg - elif tx_sudo.state == 'done': - status = 'success' - message = tx_sudo.acquirer_id.done_msg - elif tx_sudo.state == 'cancel': - status = 'danger' - message = tx_sudo.acquirer_id.cancel_msg - else: - status = 'danger' - message = tx_sudo.state_message \ - or _("An error occurred during the processing of this payment.") + # Stop monitoring the transaction now that it reached a final state. + PaymentPostProcessing.remove_transactions(tx_sudo) # Display the payment confirmation page to the user - PaymentPostProcessing.remove_transactions(tx_sudo) - render_values = { - 'tx': tx_sudo, - 'status': status, - 'message': message - } - return request.render('payment.confirm', render_values) + return request.render('payment.confirm', qcontext={'tx': tx_sudo}) else: # Display the portal homepage to the user return request.redirect('/my/home') diff --git a/addons/payment/static/src/scss/payment_templates.scss b/addons/payment/static/src/scss/payment_templates.scss new file mode 100644 index 00000000000..ed602ff2d66 --- /dev/null +++ b/addons/payment/static/src/scss/payment_templates.scss @@ -0,0 +1,3 @@ +div#o_payment_status_alert > p { + margin-bottom: 0; +} diff --git a/addons/payment/views/payment_portal_templates.xml b/addons/payment/views/payment_portal_templates.xml index 5e9ef2eeb80..04df08baaf6 100644 --- a/addons/payment/views/payment_portal_templates.xml +++ b/addons/payment/views/payment_portal_templates.xml @@ -113,8 +113,6 @@ diff --git a/addons/payment_transfer/views/payment_transfer_templates.xml b/addons/payment_transfer/views/payment_transfer_templates.xml index c0e3ef37d97..713d1de908a 100644 --- a/addons/payment_transfer/views/payment_transfer_templates.xml +++ b/addons/payment_transfer/views/payment_transfer_templates.xml @@ -8,7 +8,7 @@