[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.
This commit is contained in:
Denis Ledoux 2015-07-09 11:46:32 +02:00
parent f3e4d0a2e8
commit 7c2521a79b
1 changed files with 2 additions and 3 deletions

View File

@ -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'],