Commit da98d69d authored by Jérome Perrin's avatar Jérome Perrin

get the payroll service provider from the model line, or from an annotation

line with source_annotation_line_reference reference


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@21440 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 79860c6a
......@@ -173,7 +173,6 @@ class PaySheetTransaction(Invoice):
title=title,
description=description,
destination=self.getSourceSection(),
source_section=resource_value.getSource(),
resource_value=resource_value,
destination_section=self.getDestinationSection(),
variation_base_category_list=('tax_category',
......@@ -185,9 +184,10 @@ class PaySheetTransaction(Invoice):
# add cells categories to the Pay Sheet Line
# it's a sort of inheritance of sub-object data
if categories is not None:
if categories:
categories_list = payline.getCategoryList()
categories_list.extend(categories)
# XXX editing categories directly is wrong !
payline.edit(categories=categories_list)
base_id = 'movement'
......@@ -356,6 +356,23 @@ class PaySheetTransaction(Invoice):
base_amount_list = model_line.getBaseAmountList()
resource = service.getRelativeUrl()
# get the service provider, either on the model line, or using the
# annotation line reference.
source_section = None
source_annotation_line_reference = \
model_line.getSourceAnnotationLineReference()
if model_line.getSource():
source_section = model_line.getSource()
elif source_annotation_line_reference:
for annotation_line in paysheet.contentValues(
portal_type='Annotation Line'):
annotation_line_reference = annotation_line.getReference() \
or annotation_line.getId()
if annotation_line_reference == source_annotation_line_reference \
and annotation_line.getSource():
source_section = annotation_line.getSource()
break
if model_line.getDescription():
desc = model_line.getDescription()
# if the model_line description is empty, the payroll service
......@@ -491,6 +508,7 @@ class PaySheetTransaction(Invoice):
pay_sheet_line = paysheet.createPaySheetLine(
title=title,
resource=resource,
source_section=source_section,
int_index=int_index,
desc=desc,
base_amount_list=base_amount_list,
......
......@@ -125,20 +125,18 @@ class TestPayrollMixin(ERP5TypeTestCase):
self.salary_share_list = ['tax_category/'+self.tax_category_employee_share,]
payroll_service_organisation = self.createOrganisation(id='urssaf',
title='URSSAF')
self.urssaf=self.createPayrollService(id=self.urssaf_id,
self.payroll_service_organisation = self.createOrganisation(
id='urssaf', title='URSSAF')
self.urssaf = self.createPayrollService(id=self.urssaf_id,
title='State Insurance',
organisation=payroll_service_organisation,
base_amount_list=['deductible_tax',],
product_line='state_insurance',
variation_base_category_list=['tax_category', 'salary_range'],
variation_category_list=self.urssaf_slice_list + \
self.urssaf_share_list)
self.labour=self.createPayrollService(id=self.labour_id,
self.labour = self.createPayrollService(id=self.labour_id,
title='Labour',
organisation=None,
product_line='labour',
base_amount_list=['base_salary', 'gross_salary'],
variation_base_category_list=['tax_category', 'salary_range'],
......@@ -288,9 +286,10 @@ class TestPayrollMixin(ERP5TypeTestCase):
self.tic()
return organisation
def createPayrollService(self, id='', title='', organisation='',
def createPayrollService(self, id='', title='',
base_amount_list=None, variation_base_category_list=None,
variation_category_list=None, product_line=None, **kw):
payroll_service_portal_type = 'Payroll Service'
payroll_service_module = self.portal.getDefaultModule(\
portal_type=payroll_service_portal_type)
......@@ -304,14 +303,13 @@ class TestPayrollMixin(ERP5TypeTestCase):
if hasattr(payroll_service_module, id):
payroll_service_module.manage_delObjects([id])
payroll_service = payroll_service_module.newContent(\
payroll_service = payroll_service_module.newContent(
title=title,
portal_type = self.payroll_service_portal_type,
id = id,
source_value = organisation,
quantity_unit = 'time/month',
product_line = product_line,
base_amount_list = base_amount_list)
portal_type=self.payroll_service_portal_type,
id=id,
quantity_unit='time/month',
product_line=product_line,
base_amount_list=base_amount_list)
payroll_service.setVariationBaseCategoryList(variation_base_category_list)
payroll_service.setVariationCategoryList(variation_category_list)
get_transaction().commit()
......@@ -378,8 +376,16 @@ class TestPayrollMixin(ERP5TypeTestCase):
self.france_settings_slice_c, self.plafond*4, self.plafond*8))
return slice_list
def createModelLine(self, model, id, variation_category_list,
resource, slice_list, share_list, values, editable=False,
def createModelLine(self,
model,
id,
variation_category_list,
resource,
slice_list,
share_list,
values,
editable=False,
source_value=None,
base_amount_list=['base_salary']):
'''
test the function addModelLine and test if the model line has been
......@@ -411,14 +417,14 @@ class TestPayrollMixin(ERP5TypeTestCase):
if hasattr(model, id):
model.manage_delObjects([id])
model_line = model.newContent(\
portal_type = self.paysheet_model_line_portal_type,
id = id,
resource_value = resource,
source_section_value = model.getSourceSectionValue(),
editable = editable,
base_amount_list = base_amount_list,
variation_category_list = variation_category_list,)
model_line = model.newContent(
portal_type=self.paysheet_model_line_portal_type,
id=id,
resource_value=resource,
source_value=source_value,
editable=editable,
base_amount_list=base_amount_list,
variation_category_list=variation_category_list,)
get_transaction().commit()
self.tic()
......@@ -467,6 +473,7 @@ class TestPayrollMixin(ERP5TypeTestCase):
Calcul the given paysheet like if you hace click on the 'Calculation of
the Pay Sheet Transaction' action button.
XXX Editable line are not yet take into account
XXX this method should not exist ! use the standard method
'''
paysheet_line_list = \
paysheet.createPaySheetLineList()
......@@ -626,10 +633,12 @@ class TestPayroll(TestPayrollMixin):
model_line1 = self.createModelLine(model=self.model,
id=model_line_id1,
variation_category_list=variation_category_list_urssaf,
resource=self.urssaf, share_list=self.urssaf_share_list,
resource=self.urssaf,
share_list=self.urssaf_share_list,
slice_list=self.urssaf_slice_list,
values=[[[None, 0.01], [None, 0.02], [None, 0.03]], [[None, 0.04],
[None, 0.05], [None, 0.06]]])
[None, 0.05], [None, 0.06]]],
source_value=self.payroll_service_organisation)
model_line2 = self.createModelLine(model=self.model,
id=model_line_id2,
......@@ -668,6 +677,9 @@ class TestPayroll(TestPayrollMixin):
self.assertEqualAmounts(pay_sheet_line, correct_value_slice_list,
base_salary, i)
self.assertEquals(
[self.payroll_service_organisation.getRelativeUrl()],
pay_sheet_line._getCategoryMembershipList('source_section'))
elif service == self.labour_id:
cell = pay_sheet_line.getCell(\
......@@ -675,6 +687,8 @@ class TestPayroll(TestPayrollMixin):
'salary_range/'+ self.france_settings_forfait)
value = cell.getTotalPrice()
self.assertEqual(base_salary, value)
self.assertEquals([],
pay_sheet_line._getCategoryMembershipList('source_section'))
else:
self.fail("Unknown service for line %s" % pay_sheet_line)
......@@ -1436,7 +1450,6 @@ class TestPayroll(TestPayrollMixin):
paysheet.PaySheetTransaction_applyModel()
self.assertEquals(2, len(paysheet.contentValues()))
def test_apply_model_empty_line(self):
# apply a model with some empty lines
eur = self.portal.currency_module.EUR
......@@ -1478,6 +1491,59 @@ class TestPayroll(TestPayrollMixin):
paysheet.PaySheetTransaction_applyModel()
self.assertEquals(2, len(paysheet.contentValues()))
def test_calculate_paysheet_source_annotation_line_reference(self):
# the payroll service provider can be specified using the reference of an
# annotation line.
eur = self.portal.currency_module.EUR
employee = self.portal.person_module.newContent(
portal_type='Person',
title='Employee')
employer = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Employer')
provider = self.portal.organisation_module.newContent(
portal_type='Organisation',
title='Payroll Service Provider')
model = self.portal.paysheet_model_module.newContent(
portal_type='Pay Sheet Model',
source_section_value=employee,
destination_section_value=employer,
price_currency_value=eur,)
model_line = model.newContent(
portal_type='Pay Sheet Model Line',
resource_value=self.urssaf,
variation_category_list=['tax_category/employee_share'],
source_annotation_line_reference='tax1')
model_line.updateCellRange(base_id='movement')
cell = model_line.newCell('tax_category/employee_share',
portal_type='Pay Sheet Cell',
base_id='movement')
cell.setMappedValuePropertyList(('quantity', 'price'))
cell.setPrice(10)
cell.setQuantity(10)
annotation = model.newContent(
portal_type='Annotation Line',
reference='tax1',
source_value=provider)
paysheet = self.portal.accounting_module.newContent(
portal_type='Pay Sheet Transaction',
specialise_value=model)
paysheet.PaySheetTransaction_applyModel()
paysheet.createPaySheetLineList()
paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
self.assertEquals(1, len(paysheet_line_list))
paysheet_line = paysheet_line_list[0]
self.assertEquals([provider.getRelativeUrl()],
paysheet_line._getCategoryMembershipList('source_section'))
self.assertEquals(self.urssaf, paysheet_line.getResourceValue())
self.assertEquals(100, paysheet_line.getTotalPrice())
self.assertEquals(['tax_category/employee_share'],
paysheet_line.getVariationCategoryList())
import unittest
def test_suite():
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment