summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Martinelli <nim@odoo.com>2018-04-10 11:41:47 +0200
committerNicolas Martinelli <nim-odoo@users.noreply.github.com>2018-04-10 16:05:23 +0200
commitb7462ca224a0e4a423e1c230f0d2e46a1b9c34fa (patch)
tree910da97e6f5bfb2c518f565146352b6e82e9fcec
parent076cf05c2ecbd5d2157dc910c475a0d4def9b3a1 (diff)
[FIX] payment_authorize: number of decimals
- Create a SO of 56.16 - Send the payment link to the customer At payment, the transaction is refused by Authorize because of an invalid amount. When looking closely, the data sent to Authorize contains the amount 56.160000000001. This is due to the float representation. To avoid this, we use `float_repr` instead of `str`. opw-1832468
-rw-r--r--addons/payment_authorize/models/payment.py4
-rw-r--r--addons/payment_authorize/tests/test_authorize.py4
2 files changed, 4 insertions, 4 deletions
diff --git a/addons/payment_authorize/models/payment.py b/addons/payment_authorize/models/payment.py
index 6b299dc999d..4efeabd54e3 100644
--- a/addons/payment_authorize/models/payment.py
+++ b/addons/payment_authorize/models/payment.py
@@ -11,7 +11,7 @@ import time
from odoo import _, api, fields, models
from odoo.addons.payment.models.payment_acquirer import ValidationError
from odoo.addons.payment_authorize.controllers.main import AuthorizeController
-from odoo.tools.float_utils import float_compare
+from odoo.tools.float_utils import float_compare, float_repr
from odoo.tools.safe_eval import safe_eval
_logger = logging.getLogger(__name__)
@@ -64,7 +64,7 @@ class PaymentAcquirerAuthorize(models.Model):
temp_authorize_tx_values = {
'x_login': self.authorize_login,
'x_trans_key': self.authorize_transaction_key,
- 'x_amount': str(values['amount']),
+ 'x_amount': float_repr(values['amount'], values['currency'].decimal_places if values['currency'] else 2),
'x_show_form': 'PAYMENT_FORM',
'x_type': 'AUTH_CAPTURE' if not self.capture_manually else 'AUTH_ONLY',
'x_method': 'CC',
diff --git a/addons/payment_authorize/tests/test_authorize.py b/addons/payment_authorize/tests/test_authorize.py
index b2f1f8e3393..40d0d960b50 100644
--- a/addons/payment_authorize/tests/test_authorize.py
+++ b/addons/payment_authorize/tests/test_authorize.py
@@ -51,7 +51,7 @@ class AuthorizeForm(AuthorizeCommon):
form_values = {
'x_login': self.authorize.authorize_login,
'x_trans_key': self.authorize.authorize_transaction_key,
- 'x_amount': '320.0',
+ 'x_amount': '56.16',
'x_show_form': 'PAYMENT_FORM',
'x_type': 'AUTH_CAPTURE',
'x_method': 'CC',
@@ -87,7 +87,7 @@ class AuthorizeForm(AuthorizeCommon):
form_values['x_fp_hash'] = self._authorize_generate_hashing(form_values)
# render the button
- res = self.authorize.render('SO004', 320.0, self.currency_usd.id, values=self.buyer_values)
+ res = self.authorize.render('SO004', 56.16, self.currency_usd.id, values=self.buyer_values)
# check form result
tree = objectify.fromstring(res)