[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
This commit is contained in:
parent
88ab3db5f2
commit
899acef186
|
@ -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 = {
|
||||
|
|
Loading…
Reference in New Issue