Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FIX] payment_authorize: always send an amount with the correct decimals
We cannot assume reading the value of a monetary field has the decimals specified by the currency in decimal_places. Right after creating a record with a monetary field it may have a different amount of decimals. To reproduce this: >>> tx = env['payment.transaction'].create({ 'amount': 10.87, 'acquirer_id': env['payment.acquirer'].search([], limit=1).id, 'currency_id': env.ref('base.USD').id, 'reference': 'test' }) >>> tx.id 130 >>> tx.amount 10.870000000000001 <Restart odoo> >>> env['payment.transaction'].browse(130).amount 10.87 Authorize requires us to send a correctly rounded amount. The following response is returned when sending 10.870000000000001: {'messages': {'message': [{'code': 'E00027', 'text': 'The transaction was unsuccessful.'}], 'resultCode': 'Error'}, 'transactionResponse': {'SupplementalDataQualificationIndicator': 0, 'accountNumber': '', 'accountType': '', 'authCode': '', 'avsResultCode': 'P', 'cavvResultCode': '', 'cvvResultCode': '', 'errors': [{'errorCode': '5', 'errorText': 'A valid amount is ' 'required.'}], 'refTransID': '', 'responseCode': '3', 'testRequest': '0', 'transHash': '', 'transHashSha2': '', 'transId': '0'}} To work around the issue always round when we read amount. Lower level solutions were considered in #45248 but for now we'll stick with this higher level and lower risk patch. opw-2188889 closes #45345 Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
- Loading branch information