diff options
| author | Toufik Benjaa <tbe@odoo.com> | 2018-04-20 18:15:42 +0200 |
|---|---|---|
| committer | Toufik Benjaa <tbe@odoo.com> | 2018-04-23 16:28:08 +0200 |
| commit | e34b8b07b4c1bfb3c91fbf156fb38866bf28a74b (patch) | |
| tree | fdddef2a15abca0a75409bc4b4c4a9a8aebef395 | |
| parent | eccb2bcf765237480f802933ada6dadc916d269d (diff) | |
[FIX] stripe: Fix float representation error
- Stripe needs to have the amount in integer, so we have to multiply by 100 the amount.
Which sometimes create float representation errors and remove/add ~1 cent on some transactions (i.e 72.60€)
| -rw-r--r-- | addons/payment_stripe/models/payment.py | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/addons/payment_stripe/models/payment.py b/addons/payment_stripe/models/payment.py index 1adebf763b6..62c2fd937bd 100644 --- a/addons/payment_stripe/models/payment.py +++ b/addons/payment_stripe/models/payment.py @@ -8,6 +8,7 @@ from odoo import api, fields, models, _ from odoo.addons.payment.models.payment_acquirer import ValidationError from odoo.exceptions import UserError from odoo.tools.safe_eval import safe_eval +from odoo.tools.float_utils import float_round _logger = logging.getLogger(__name__) @@ -106,7 +107,7 @@ class PaymentTransactionStripe(models.Model): def _create_stripe_charge(self, acquirer_ref=None, tokenid=None, email=None): api_url_charge = 'https://%s/charges' % (self.acquirer_id._get_stripe_api_url()) charge_params = { - 'amount': int(self.amount if self.currency_id.name in INT_CURRENCIES else self.amount*100), + 'amount': int(self.amount if self.currency_id.name in INT_CURRENCIES else float_round(self.amount * 100, 2)), 'currency': self.currency_id.name, 'metadata[reference]': self.reference, 'description': self.reference, @@ -135,7 +136,7 @@ class PaymentTransactionStripe(models.Model): refund_params = { 'charge': self.acquirer_reference, - 'amount': int(self.amount*100), # by default, stripe refund the full amount (we don't really need to specify the value) + 'amount': int(float_round(self.amount * 100, 2)), # by default, stripe refund the full amount (we don't really need to specify the value) 'metadata[reference]': self.reference, } |
