From e94be1856c0a156000ba226d547ba6c18bd1caea Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Tue, 22 Mar 2016 15:45:15 +0100 Subject: [PATCH] [FIX] website_sale: non-blocking order confirmation fail When validating a payment transaction, if the cart (order) cannot be confirmed or the email cannot be sent for any reason (instance, the email template is broken), the transaction must continue, so the payment transaction can be set to `done` or `pending`. In other words, not sending the confirmation email or not confirming the sale order must not be blocking to mark the payment transaction as done. opw-672486 --- addons/website_sale/models/payment.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/addons/website_sale/models/payment.py b/addons/website_sale/models/payment.py index a76bba4bca8..6129de092aa 100644 --- a/addons/website_sale/models/payment.py +++ b/addons/website_sale/models/payment.py @@ -1,8 +1,11 @@ # -*- coding: utf-8 -*- +import logging from openerp import SUPERUSER_ID from openerp.osv import orm, fields +_logger = logging.getLogger(__name__) + class PaymentTransaction(orm.Model): _inherit = 'payment.transaction' @@ -19,12 +22,15 @@ class PaymentTransaction(orm.Model): res = super(PaymentTransaction, self).form_feedback(cr, uid, data, acquirer_name, context=context) # fetch the tx, check its state, confirm the potential SO - tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name - if hasattr(self, tx_find_method_name): - tx = getattr(self, tx_find_method_name)(cr, uid, data, context=context) - if tx and tx.state == 'done' and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: - self.pool['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=dict(context, send_email=True)) - elif tx and tx.state not in ['cancel'] and tx.sale_order_id and tx.sale_order_id.state in ['draft']: - self.pool['sale.order'].force_quotation_send(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context) + try: + tx_find_method_name = '_%s_form_get_tx_from_data' % acquirer_name + if hasattr(self, tx_find_method_name): + tx = getattr(self, tx_find_method_name)(cr, uid, data, context=context) + if tx and tx.state == 'done' and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: + self.pool['sale.order'].action_button_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=dict(context, send_email=True)) + elif tx and tx.state not in ['cancel'] and tx.sale_order_id and tx.sale_order_id.state in ['draft']: + self.pool['sale.order'].force_quotation_send(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context) + except Exception: + _logger.exception('Fail to confirm the order or send the confirmation email%s', tx and ' for the transaction %s' % tx.reference or '') return res