diff --git a/addons/website_quote/models/payment.py b/addons/website_quote/models/payment.py index f632292e8f745a746f4702c50dff3b225f6761b2..70a9e85326fd786013bbae751f7aaf109d3f10d1 100644 --- a/addons/website_quote/models/payment.py +++ b/addons/website_quote/models/payment.py @@ -1,8 +1,12 @@ # -*- coding: utf-8 -*- +import logging + from openerp import SUPERUSER_ID from openerp.osv import orm, fields +from openerp.tools import float_compare +_logger = logging.getLogger(__name__) class PaymentTransaction(orm.Model): _inherit = 'payment.transaction' @@ -22,9 +26,17 @@ class PaymentTransaction(orm.Model): 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.acquirer_id.auto_confirm == 'at_pay_confirm' and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: - self.pool['sale.order'].action_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=dict(context, send_email=True)) - elif tx and tx.state not in ['cancel', 'error'] 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) + + if tx and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: + amount_matches = float_compare(tx.amount, tx.sale_order_id.amount_total, 2) == 0 + if amount_matches: + if tx.state == 'done' and tx.acquirer_id.auto_confirm == 'at_pay_confirm': + _logger.info('<%s> transaction completed, auto-confirming order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + self.pool['sale.order'].action_confirm(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=dict(context, send_email=True)) + elif tx and tx.state not in ['cancel', 'error'] and tx.sale_order_id and tx.sale_order_id.state in ['draft']: + _logger.info('<%s> transaction pending/to confirm manually, sending quote email for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) + self.pool['sale.order'].force_quotation_send(cr, SUPERUSER_ID, [tx.sale_order_id.id], context=context) + else: + _logger.warning('<%s> transaction MISMATCH for order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id) return res diff --git a/addons/website_sale/models/payment.py b/addons/website_sale/models/payment.py index 05e3f9e4bbbe92a51d89f09939a136ce1fd43af7..b3e88a0ae79e2cf2cbfecd7068e72deba4e40bb5 100644 --- a/addons/website_sale/models/payment.py +++ b/addons/website_sale/models/payment.py @@ -29,9 +29,9 @@ class PaymentTransaction(orm.Model): tx = getattr(self, tx_find_method_name)(cr, uid, data, context=context) _logger.info('<%s> transaction processed: tx ref:%s, tx amount: %s', acquirer_name, tx.reference if tx else 'n/a', tx.amount if tx else 'n/a') - if tx and tx.sale_order_id: + if tx and tx.sale_order_id and tx.sale_order_id.state in ['draft', 'sent']: # verify SO/TX match, excluding tx.fees which are currently not included in SO - amount_matches = (tx.sale_order_id.state in ['draft', 'sent'] and float_compare(tx.amount, tx.sale_order_id.amount_total, 2) == 0) + amount_matches = float_compare(tx.amount, tx.sale_order_id.amount_total, 2) == 0 if amount_matches: if tx.state == 'done' and tx.acquirer_id.auto_confirm == 'at_pay_confirm': _logger.info('<%s> transaction completed, auto-confirming order %s (ID %s)', acquirer_name, tx.sale_order_id.name, tx.sale_order_id.id)