From 899acef186276c4b2a40492b492fe021d4222066 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Fri, 13 Feb 2015 15:33:01 +0100 Subject: [PATCH] [FIX] payment: unique reference constraint The payment transactions references must be unique, but for states within draft, pending, done states, not if the transaction has been canceled or in error. Otherwise, this is not possible to create a new payment transaction for an ecommerce order for which the payment has been canceled by the acquirer For instance, when the customer lands on Ogone, then hit the cancel button opw-627914 --- addons/payment/models/payment_acquirer.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index 0990fcab90f..5d4dcf0688d 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -371,8 +371,15 @@ class PaymentTransaction(osv.Model): help='Reference of the customer in the acquirer database'), } - _sql_constraints = [ - ('reference_uniq', 'UNIQUE(reference)', 'The payment transaction reference must be unique!'), + def _check_reference(self, cr, uid, ids, context=None): + transaction = self.browse(cr, uid, ids[0], context=context) + if transaction.state not in ['cancel', 'error']: + if self.search(cr, uid, [('reference', '=', transaction.reference), ('id', '!=', transaction.id)], context=context, count=True): + return False + return True + + _constraints = [ + (_check_reference, 'The payment transaction reference must be unique!', ['reference', 'state']), ] _defaults = {