Skip to content
Snippets Groups Projects
Unverified Commit af470098 authored by Olivier Dony's avatar Olivier Dony
Browse files

[FIX] website_{quote,sale}: payment tx handling consistency

Both website_sale and website_quote have logic to independently
confirm sales orders when a successful payment transaction is
processed.
Rev 46c5f93b introduced an extra
check and logging for transactions with mismatching amounts in
website_sale, but the same change was not done in website_quote.

Consequently, when both modules were installed, the tx mismatch
check was bypassed by website_quote, and a spurious logging message
was emitted by website_sale if the website_quote logic had executed
first.

This patch makes tx handling consistent in both modules, and avoids
the misleading log message when both modules are installed.
parent 879e2b27
No related branches found
No related tags found
No related merge requests found
# -*- 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
......@@ -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)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment