Skip to content
Snippets Groups Projects
Unverified Commit cd987312 authored by Damien Bouvy's avatar Damien Bouvy
Browse files

[IMP] payment: prevent 'authorize-only' transaction to settle invoice

parent a2b9b3a6
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@ class AccountPayment(models.Model):
_inherit = 'account.payment'
payment_transaction_id = fields.Many2one('payment.transaction', string="Payment Transaction")
payment_token_id = fields.Many2one('payment.token', string="Saved payment token")
payment_token_id = fields.Many2one('payment.token', string="Saved payment token", domain=[('acquirer_id.auto_confirm', '!=', 'authorize')],
help="Note that tokens from acquirers set to only authorize transactions (instead of capturing the amount) are not available.")
payment_type = fields.Selection(selection_add=[('electronic', 'Electronically receive money')])
payment_method_id_code = fields.Char(related='payment_method_id.code')
......@@ -18,14 +19,14 @@ class AccountPayment(models.Model):
def _onchange_partner_id(self):
res = {}
if self.partner_id:
res['domain'] = {'payment_token_id': [('partner_id', '=', self.partner_id.id)]}
res['domain'] = {'payment_token_id': [('partner_id', '=', self.partner_id.id), ('acquirer_id.auto_confirm', '!=', 'authorize')]}
return res
@api.onchange('payment_method_id', 'journal_id')
def _onchange_payment_method(self):
if self.payment_method_id.code == 'electronic':
self.payment_token_id = self.env['payment.token'].search([('partner_id', '=', self.partner_id.id)], limit=1)
self.payment_token_id = self.env['payment.token'].search([('partner_id', '=', self.partner_id.id), ('acquirer_id.auto_confirm', '!=', 'authorize')], limit=1)
else:
self.payment_token_id = False
......@@ -38,6 +39,9 @@ class AccountPayment(models.Model):
return account_payment
def _do_payment(self):
if self.payment_token_id.acquirer_id.auto_confirm == 'authorize':
raise ValidationError('This feature is not available for payment acquirers set to the "Authorize" mode.\n'
'Please use a token from another provider than %s.' % self.payment_token_id.acquirer_id.name)
reference = "PAYMENT-%s-%s" % (self.id, datetime.datetime.now().strftime('%y%m%d_%H%M%S'))
tx = self.env['payment.transaction'].create({
'amount': self.amount,
......
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