From df0ae7e4d155a180f5e49e85f18ce52bf503c22c Mon Sep 17 00:00:00 2001
From: Denis Ledoux <dle@openerp.com>
Date: Wed, 28 May 2014 14:02:56 +0200
Subject: [PATCH] [FIX] payment_paypal: wrong handling fees computation formula

---
 addons/payment_paypal/models/paypal.py     | 7 +++++--
 addons/payment_paypal/tests/test_paypal.py | 2 +-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/addons/payment_paypal/models/paypal.py b/addons/payment_paypal/models/paypal.py
index a5e31e9571cc..ffa5de1bf7a2 100644
--- a/addons/payment_paypal/models/paypal.py
+++ b/addons/payment_paypal/models/paypal.py
@@ -90,9 +90,12 @@ class AcquirerPaypal(osv.Model):
             return 0.0
         country = self.pool['res.country'].browse(cr, uid, country_id, context=context)
         if country and acquirer.company_id.country_id.id == country.id:
-            fees = amount * (1 + acquirer.fees_dom_var / 100.0) + acquirer.fees_dom_fixed - amount
+            percentage = acquirer.fees_dom_var
+            fixed = acquirer.fees_dom_fixed
         else:
-            fees = amount * (1 + acquirer.fees_int_var / 100.0) + acquirer.fees_int_fixed - amount
+            percentage = acquirer.fees_int_var
+            fixed = acquirer.fees_int_fixed
+        fees = (percentage / 100.0 * amount + fixed ) / (1 - percentage / 100.0)
         return fees
 
     def paypal_form_generate_values(self, cr, uid, id, partner_values, tx_values, context=None):
diff --git a/addons/payment_paypal/tests/test_paypal.py b/addons/payment_paypal/tests/test_paypal.py
index 01f40ddd0944..5638c5cd602b 100644
--- a/addons/payment_paypal/tests/test_paypal.py
+++ b/addons/payment_paypal/tests/test_paypal.py
@@ -148,7 +148,7 @@ class PaypalForm(PaypalCommon):
         for form_input in tree.input:
             if form_input.get('name') in ['handling']:
                 handling_found = True
-                self.assertEqual(form_input.get('value'), '1.56', 'paypal: wrong computed fees')
+                self.assertEqual(form_input.get('value'), '1.57', 'paypal: wrong computed fees')
         self.assertTrue(handling_found, 'paypal: fees_active did not add handling input in rendered form')
 
     @mute_logger('openerp.addons.payment_paypal.models.paypal', 'ValidationError')
-- 
GitLab