From 2a1af9d09770c43118a75eee56640f32b019ec88 Mon Sep 17 00:00:00 2001
From: Julien Muchembled <jm@nexedi.com>
Date: Thu, 27 Jun 2013 17:56:48 +0200
Subject: [PATCH] payroll: fix cumulated taxable net salary in reports

---
 ...ansaction_getOtherInformationsDataDict.xml | 15 ++++++-----
 ...PaySheetTransaction_getYearToDateSlice.xml | 25 ++++++-------------
 bt5/erp5_payroll_l10n_fr/bt/revision          |  2 +-
 product/ERP5/tests/testPayroll_l10n_fr.py     |  9 ++++---
 4 files changed, 21 insertions(+), 30 deletions(-)

diff --git a/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getOtherInformationsDataDict.xml b/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getOtherInformationsDataDict.xml
index 216793b972..bdbc457cff 100644
--- a/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getOtherInformationsDataDict.xml
+++ b/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getOtherInformationsDataDict.xml
@@ -182,13 +182,12 @@ def getPaymentConditionText(paysheet):\n
           date)\n
   return \'\'\n
 \n
-gross_salary = getMovementTotalPriceFromCategory(\\\n
-    base_contribution=\'base_contribution/base_amount/payroll/report/salary/gross\',\n
+base_contribution = \'base_contribution/base_amount/payroll/report/salary/gross\'\n
+gross_salary = getMovementTotalPriceFromCategory(base_contribution,\n
     contribution_share=\'contribution_share/employee\')\n
-\n
-year_to_date_gross_salary = paysheet.PaySheetTransaction_getYearToDateSlice()\n
-year_to_date_slice_a = paysheet.PaySheetTransaction_getYearToDateSlice(\'salary_range/france/tranche_a\')\n
-year_to_date_slice_b = paysheet.PaySheetTransaction_getYearToDateSlice(\'salary_range/france/tranche_b\')\n
+year_to_date_gross_salary = paysheet.PaySheetTransaction_getYearToDateSlice(base_contribution)\n
+year_to_date_slice_a = paysheet.PaySheetTransaction_getYearToDateSlice(base_contribution, \'salary_range/france/tranche_a\')\n
+year_to_date_slice_b = paysheet.PaySheetTransaction_getYearToDateSlice(base_contribution, \'salary_range/france/tranche_b\')\n
 \n
 worked_hour_count = paysheet.getWorkTimeAnnotationLineQuantity(0)\n
 year_to_date_worked_hour_count = worked_hour_count + \\\n
@@ -208,8 +207,8 @@ year_to_date_bonus_worked_hour_amount = portal.PaySheetTransaction_getYearToDate
     base_contribution=\'base_contribution/base_amount/payroll/report/overtime\', \\\n
     contribution_share=\'contribution_share/employee\') or 0\n
 \n
-year_to_date_taxable_net_salary = portal.PaySheetTransaction_getYearToDateBaseContributionTotalPrice(\\\n
-    paysheet=paysheet, base_contribution_list=\'payroll/report/salary/net\') + salaire_net_imposable\n
+year_to_date_taxable_net_salary = paysheet.PaySheetTransaction_getYearToDateSlice(\n
+    \'base_contribution/base_amount/payroll/base/income_tax\')\n
 \n
 def unicodeDict(d):\n
   for k, v in d.items():\n
diff --git a/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getYearToDateSlice.xml b/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getYearToDateSlice.xml
index 154ed8980c..bef4aaa35f 100644
--- a/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getYearToDateSlice.xml
+++ b/bt5/erp5_payroll_l10n_fr/SkinTemplateItem/portal_skins/erp5_payroll_l10n_fr/PaySheetTransaction_getYearToDateSlice.xml
@@ -50,9 +50,7 @@
         </item>
         <item>
             <key> <string>_body</string> </key>
-            <value> <string encoding="cdata"><![CDATA[
-
-\'\'\'\n
+            <value> <string>\'\'\'\n
   This script get year to date amount for the slice corresponding to slice_path\n
   of the model.\n
 \'\'\'\n
@@ -73,12 +71,12 @@ paysheet_list = [r.getObject() for r in accounting_module.searchFolder(**search_
 paysheet_list.append(context)\n
 yearly_slice_amount = 0\n
 \n
-for paysheet in paysheet_list :\n
-  gross_salary=paysheet.PaySheetTransaction_getMovementTotalPriceFromCategory(\\\n
-        base_contribution=\'base_contribution/base_amount/payroll/report/salary/gross\',\n
+for paysheet in paysheet_list:\n
+  salary = paysheet.PaySheetTransaction_getMovementTotalPriceFromCategory(\n
+        base_contribution=base_contribution,\n
         contribution_share=\'contribution_share/employee\')\n
   if slice_path is None:\n
-    yearly_slice_amount += gross_salary\n
+    yearly_slice_amount += salary\n
     continue\n
   model = paysheet.getSpecialiseValue().getEffectiveModel(\\\n
       start_date=paysheet.getStartDate(),\n
@@ -89,21 +87,14 @@ for paysheet in paysheet_list :\n
       return 0.0\n
     plafond_max = slice.getQuantityRangeMax()\n
     plafond_min = slice.getQuantityRangeMin()\n
-    slice_amount = 0\n
-    if gross_salary < plafond_max:\n
-      slice_amount = gross_salary - plafond_min\n
-    else:\n
-      slice_amount = plafond_max - plafond_min\n
-    yearly_slice_amount += slice_amount\n
+    yearly_slice_amount += min(salary, plafond_max) - plafond_min\n
 \n
 return yearly_slice_amount\n
-
-
-]]></string> </value>
+</string> </value>
         </item>
         <item>
             <key> <string>_params</string> </key>
-            <value> <string>slice_path=None</string> </value>
+            <value> <string>base_contribution, slice_path=None</string> </value>
         </item>
         <item>
             <key> <string>id</string> </key>
diff --git a/bt5/erp5_payroll_l10n_fr/bt/revision b/bt5/erp5_payroll_l10n_fr/bt/revision
index acfba60953..83248fb9df 100644
--- a/bt5/erp5_payroll_l10n_fr/bt/revision
+++ b/bt5/erp5_payroll_l10n_fr/bt/revision
@@ -1 +1 @@
-141
\ No newline at end of file
+142
\ No newline at end of file
diff --git a/product/ERP5/tests/testPayroll_l10n_fr.py b/product/ERP5/tests/testPayroll_l10n_fr.py
index 5b3fd242af..637f5bcffc 100644
--- a/product/ERP5/tests/testPayroll_l10n_fr.py
+++ b/product/ERP5/tests/testPayroll_l10n_fr.py
@@ -77,6 +77,7 @@ class TestPayroll_l10n_fr(TestPayrollMixin):
       paysheet.stop()
     self.tic()
 
+    base_contribution = 'base_contribution/base_amount/payroll/report/salary/gross'
     # here, check how much is contributed to the slices
     # the slices defined for this tax are :
     # - 0 to 200
@@ -84,14 +85,14 @@ class TestPayroll_l10n_fr(TestPayrollMixin):
     # - 400 to 5000
     # the salary is of 3000
     self.assertEquals(400, # 200 from the 1st paysheet + 200 from the 2e
-        paysheet_list[1].PaySheetTransaction_getYearToDateSlice(\
-            'salary_range/france/slice_0_to_200'))
+        paysheet_list[1].PaySheetTransaction_getYearToDateSlice(
+            base_contribution, 'salary_range/france/slice_0_to_200'))
     self.assertEquals(400, # 200 from the 1st paysheet + 200 from the 2e
         paysheet_list[1].PaySheetTransaction_getYearToDateSlice(\
-            'salary_range/france/slice_200_to_400'))
+            base_contribution, 'salary_range/france/slice_200_to_400'))
     self.assertEquals(5200, # (3000 - 400)*2
         paysheet_list[1].PaySheetTransaction_getYearToDateSlice(\
-            'salary_range/france/slice_400_to_5000'))
+            base_contribution, 'salary_range/france/slice_400_to_5000'))
 
   def test_01_getYearToDateSlice(self):
     '''Check that is possible to calculate the total amount spend on a slice
-- 
2.30.9