Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FW][FIX] payment_authorize: always send an amount with the correct decimals #45357

Conversation

@fw-bot
Copy link
Contributor

fw-bot commented Feb 14, 2020

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

Forward-Port-Of: #45345

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

X-original-commit: 7485927
@robodoo robodoo added the seen 🙂 label Feb 14, 2020
@fw-bot

This comment has been minimized.

Copy link
Contributor Author

fw-bot commented Feb 14, 2020

This PR targets saas-13.1 and is part of the forward-port chain. Further PRs will be created up to master.

More info at https://github.com/odoo/odoo/wiki/Mergebot-and-Forwardbot#forward-port

@robodoo robodoo added the forwardport label Feb 14, 2020
@C3POdoo C3POdoo added the OE label Feb 14, 2020
@robodoo robodoo added the CI 🤖 label Feb 14, 2020
@robodoo robodoo added the r+ 👌 label Feb 14, 2020
robodoo pushed a commit that referenced this pull request Feb 14, 2020
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 #45357

X-original-commit: 7485927
Signed-off-by: Nicolas Martinelli (nim) <nim@odoo.com>
@robodoo robodoo closed this Feb 14, 2020
@robodoo robodoo deployed to merge Feb 14, 2020 Active
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

4 participants
You can’t perform that action at this time.