diff options
| author | Nicolas Martinelli <nim@odoo.com> | 2018-05-09 14:10:51 +0200 |
|---|---|---|
| committer | Nicolas Martinelli <nim-odoo@users.noreply.github.com> | 2018-05-15 08:33:06 +0200 |
| commit | 429bcd9464928c21b0bdc3e99280cd50bf0c36b8 (patch) | |
| tree | 35d97e4eb5f3cff8bbf16275875bf694bb6e278f | |
| parent | 45b4a4a4dd09fa6d8a2e18e52adf542f015124d7 (diff) | |
[FIX] payment_sips: special characters
The field `transactionReference` of Sips must contain only
alphanumerical characters. Previous commit 31dc6b888eeb2d787f5675 solved
the special case of several attempts to pay, but a much simpler case may
appear in v11. Paying an invoice is likely to fail since the reference
contains by default `/`.
In the previous commit, we could simply modify the common `payment`
module code. In this specific case, however, we only change the
reference if the acquirer is Sips.
opw-1841483
| -rw-r--r-- | addons/account_payment/models/payment.py | 2 | ||||
| -rw-r--r-- | addons/payment/models/payment_acquirer.py | 4 | ||||
| -rw-r--r-- | addons/payment_sips/models/payment.py | 11 | ||||
| -rw-r--r-- | addons/sale_payment/models/payment.py | 2 |
4 files changed, 17 insertions, 2 deletions
diff --git a/addons/account_payment/models/payment.py b/addons/account_payment/models/payment.py index 389cfa206e1..cfc90258289 100644 --- a/addons/account_payment/models/payment.py +++ b/addons/account_payment/models/payment.py @@ -159,7 +159,7 @@ class PaymentTransaction(models.Model): 'currency_id': invoice.currency_id.id, 'partner_id': invoice.partner_id.id, 'partner_country_id': invoice.partner_id.country_id.id, - 'reference': self.get_next_reference(invoice.number), + 'reference': self._get_next_reference(invoice.number, acquirer=acquirer), 'account_invoice_id': invoice.id, } if add_tx_values: diff --git a/addons/payment/models/payment_acquirer.py b/addons/payment/models/payment_acquirer.py index efd6573c778..98992c2a679 100644 --- a/addons/payment/models/payment_acquirer.py +++ b/addons/payment/models/payment_acquirer.py @@ -685,6 +685,10 @@ class PaymentTransaction(models.Model): @api.model def get_next_reference(self, reference): + return self._get_next_reference(reference) + + @api.model + def _get_next_reference(self, reference, acquirer=None): ref_suffix = 1 init_ref = reference while self.env['payment.transaction'].sudo().search_count([('reference', '=', reference)]): diff --git a/addons/payment_sips/models/payment.py b/addons/payment_sips/models/payment.py index 46464b7d60c..60e4d9f3153 100644 --- a/addons/payment_sips/models/payment.py +++ b/addons/payment_sips/models/payment.py @@ -4,6 +4,7 @@ import json import logging +import re from hashlib import sha256 from werkzeug import urls @@ -111,6 +112,16 @@ class AcquirerSips(models.Model): return self.environment == 'prod' and self.sips_prod_url or self.sips_test_url +class PaymentTransactionSips(models.Model): + _inherit = 'payment.transaction' + + @api.model + def _get_next_reference(self, reference, acquirer=None): + if acquirer and acquirer.provider == 'sips': + reference = re.sub(r'[^0-9a-zA-Z]+', 'x' , reference) + return super(PaymentTransactionSips, self)._get_next_reference(reference, acquirer=acquirer) + + class TxSips(models.Model): _inherit = 'payment.transaction' diff --git a/addons/sale_payment/models/payment.py b/addons/sale_payment/models/payment.py index 831af37550f..f710b63630f 100644 --- a/addons/sale_payment/models/payment.py +++ b/addons/sale_payment/models/payment.py @@ -182,7 +182,7 @@ class PaymentTransaction(models.Model): 'currency_id': order.pricelist_id.currency_id.id, 'partner_id': order.partner_id.id, 'partner_country_id': order.partner_id.country_id.id, - 'reference': self.get_next_reference(order.name), + 'reference': self._get_next_reference(order.name, acquirer=acquirer), 'sale_order_id': order.id, } if add_tx_values: |
