From e4fd4cc3f2e744a2064bda8b33d16d4a3077a26e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?J=C3=A9rome=20Perrin?= <jerome@nexedi.com>
Date: Tue, 17 Jun 2008 08:38:17 +0000
Subject: [PATCH] Previously, if ratio was set to 0 or None on a model line, it
 was assumed that the ratio was 100%. We want to separate it in two different
 cases:  - ratio is 0 -> the line should not be created.  - ratio is not set
 (ie. None) -> this means that no ratio apply here, it's a    simple amount,
 so ratio default to 100% Move this in the default calculation script so that
 it's possible to change the behaviour. Add tests for those two cases (price =
 None and price = 0)

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21632 20353a03-c40f-0410-a6d1-a30d3c3de9de
---
 product/ERP5/Document/PaySheetTransaction.py |  5 +-
 product/ERP5/tests/testPayroll.py            | 53 +++++++++++++++++++-
 2 files changed, 53 insertions(+), 5 deletions(-)

diff --git a/product/ERP5/Document/PaySheetTransaction.py b/product/ERP5/Document/PaySheetTransaction.py
index 310c217fc5..0818818c73 100644
--- a/product/ERP5/Document/PaySheetTransaction.py
+++ b/product/ERP5/Document/PaySheetTransaction.py
@@ -195,9 +195,6 @@ class PaySheetTransaction(Invoice):
     # create cell_list
     for cell in good_cell_list:
       paycell = payline.newCell(base_id=base_id, *cell['category_list'])
-      # if the price aven't be completed, it should be set to 1 (=100%)
-      if not cell['price']:
-        cell['price'] = 1
       paycell.edit(mapped_value_property_list=('price', 'quantity'),
                    force_update=1,
                    **cell)
@@ -483,7 +480,7 @@ class PaySheetTransaction(Invoice):
         quantity = cell_dict['quantity']
         price = cell_dict['price']
 
-        if quantity:
+        if quantity and price:
           cell_list.append(cell_dict)
 
           # update the base_participation
diff --git a/product/ERP5/tests/testPayroll.py b/product/ERP5/tests/testPayroll.py
index b0d436287d..7d8d8cb101 100644
--- a/product/ERP5/tests/testPayroll.py
+++ b/product/ERP5/tests/testPayroll.py
@@ -224,7 +224,7 @@ class TestPayrollMixin(ERP5ReportTestCase):
             'base_amount/%s' % self.base_amount_base_salary,
             'grade/%s' % self.grade_worker,
             'grade/%s' % self.grade_engineer,
-            'quantity_unit/time/mounth',
+            'quantity_unit/time/month',
             'group/demo_group',
             'product_line/base_salary',
             'product_line/payroll_tax_1',
@@ -1373,6 +1373,57 @@ class TestPayroll(TestPayrollMixin):
     self.assertEquals(1, cell.getPrice())
     self.assertEquals(100, cell.getQuantity())
 
+  def test_createPaySheetLineNonePrice(self):
+    # test the creation of lines when the price is not set, but only the
+    # quantity. This means that no ratio is applied on this line.
+    line = self.model.newContent(
+          id='line',
+          portal_type='Pay Sheet Model Line',
+          resource_value=self.labour,
+          variation_category_list=['tax_category/employee_share'],)
+    line.updateCellRange(base_id='movement')
+    cell = line.newCell('tax_category/employee_share',
+                        portal_type='Pay Sheet Cell',
+                        base_id='movement')
+    cell.setMappedValuePropertyList(('quantity', 'price'))
+    cell.setVariationCategoryList(('tax_category/employee_share',))
+    cell.setQuantity(5)
+
+    pay_sheet = self.createPaySheet(self.model)
+    
+    pay_sheet.PaySheetTransaction_createAllPaySheetLineList()
+    pay_sheet_line_list = pay_sheet.contentValues(portal_type='Pay Sheet Line')
+    self.assertEquals(1, len(pay_sheet_line_list))
+    pay_sheet_line = pay_sheet_line_list[0]
+    self.assertEquals(self.labour, pay_sheet_line.getResourceValue())
+    cell = pay_sheet_line.getCell('tax_category/employee_share',
+                                  base_id='movement')
+    self.assertNotEquals(None, cell)
+    self.assertEquals(1, cell.getPrice())
+    self.assertEquals(5, cell.getQuantity())
+    
+  def test_createPaySheetLineZeroPrice(self):
+    # test the creation of lines when the price is set to zero: the line should
+    # not be created.
+    line = self.model.newContent(
+          id='line',
+          portal_type='Pay Sheet Model Line',
+          resource_value=self.labour,
+          variation_category_list=['tax_category/employee_share'],)
+    line.updateCellRange(base_id='movement')
+    cell = line.newCell('tax_category/employee_share',
+                        portal_type='Pay Sheet Cell',
+                        base_id='movement')
+    cell.setMappedValuePropertyList(('quantity', 'price'))
+    cell.setVariationCategoryList(('tax_category/employee_share',))
+    cell.setQuantity(5)
+    cell.setPrice(0)
+
+    pay_sheet = self.createPaySheet(self.model)
+    
+    pay_sheet.PaySheetTransaction_createAllPaySheetLineList()
+    pay_sheet_line_list = pay_sheet.contentValues(portal_type='Pay Sheet Line')
+    self.assertEquals(0, len(pay_sheet_line_list))
     
   def test_paysheet_consistency(self):
     # minimal test for checkConsistency on a Pay Sheet Transaction and its
-- 
2.30.9