From 7c2521a79bc9443adab1bc63007e70661a8c22b7 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 9 Jul 2015 11:46:32 +0200 Subject: [PATCH] [FIX] payment_ogone: amount rounding issue The amount to pay must be sent without comma to ogone. e.g., for 66.99 EUR, the amount sent must be 6699. To do that, we simply applied 66.99 * 100, which seems rather good. However, due to the fact how floats are handled in computers, `66.99 * 100` returns 6698.999999999999 and `int(6698.999999999999)` returns 6698 while we expected 6699 Using `float_repr` with `0` as decimal precision instead of using `int` solves this issue. `float_repr(6698.999999999999, 0)` returns 6699, as expected. --- addons/payment_ogone/models/ogone.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/addons/payment_ogone/models/ogone.py b/addons/payment_ogone/models/ogone.py index e3e33c69db9..60864ac4422 100644 --- a/addons/payment_ogone/models/ogone.py +++ b/addons/payment_ogone/models/ogone.py @@ -15,7 +15,7 @@ from openerp.addons.payment_ogone.controllers.main import OgoneController from openerp.addons.payment_ogone.data import ogone from openerp.osv import osv, fields from openerp.tools import float_round, DEFAULT_SERVER_DATE_FORMAT -from openerp.tools.float_utils import float_compare +from openerp.tools.float_utils import float_compare, float_repr _logger = logging.getLogger(__name__) @@ -141,12 +141,11 @@ class PaymentAcquirerOgone(osv.Model): def ogone_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None): base_url = self.pool['ir.config_parameter'].get_param(cr, uid, 'web.base.url') acquirer = self.browse(cr, uid, id, context=context) - ogone_tx_values = dict(tx_values) temp_ogone_tx_values = { 'PSPID': acquirer.ogone_pspid, 'ORDERID': tx_values['reference'], - 'AMOUNT': '%d' % int(float_round(tx_values['amount'], 2) * 100), + 'AMOUNT': float_repr(float_round(tx_values['amount'], 2) * 100, 0), 'CURRENCY': tx_values['currency'] and tx_values['currency'].name or '', 'LANGUAGE': partner_values['lang'], 'CN': partner_values['name'],