Commit 04141bd8 authored by Fabien Morin's avatar Fabien Morin

clean tests and use sequences


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@27076 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 58928947
...@@ -26,107 +26,26 @@ ...@@ -26,107 +26,26 @@
# #
############################################################################## ##############################################################################
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
from Products.ERP5.tests.testBPMCore import TestBPMMixin
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
from Testing import ZopeTestCase from Products.ERP5Type.tests.Sequence import SequenceList
import transaction from Products.ERP5Type.tests.utils import reindex
from Products.CMFCore.utils import getToolByName
class TestNewPayrollMixin(ERP5ReportTestCase, TestBPMMixin):
class TestNewPayrollMixin(ERP5ReportTestCase):
price_currency = 'currency_module/EUR' price_currency = 'currency_module/EUR'
normal_resource_use_category_list = ['payroll/base_salary']
invoicing_resource_use_category_list = ['payroll/tax']
def getTitle(self): def getTitle(self):
return "Payroll" return "Payroll"
def setSystemPreference(self):
preference_tool = getToolByName(self.portal, 'portal_preferences')
system_preference_list = preference_tool.contentValues(
portal_type='System Preference')
if len(system_preference_list) > 1:
raise AttributeError('More than one System Preference, cannot test')
if len(system_preference_list) == 0:
system_preference = preference_tool.newContent(
portal_type='System Preference')
else:
system_preference = system_preference_list[0]
system_preference.edit(
preferred_invoicing_resource_use_category_list = \
['payroll/tax'],
preferred_normal_resource_use_category_list = \
['payroll/base_salary'],
priority = 1)
if system_preference.getPreferenceState() == 'disabled':
system_preference.enable()
def afterSetUp(self): def afterSetUp(self):
"""Prepare the test.""" """Prepare the test."""
self.portal = self.getPortal()
self.organisation_module = self.portal.organisation_module
self.person_module = self.portal.person_module
self.payroll_service_module = self.portal.payroll_service_module
self.paysheet_model_module = self.portal.paysheet_model_module
self.validateRules()
self.createCategories() self.createCategories()
self.createCurrencies()
self.login()
# creation of payroll services
self.urssaf_id = 'sickness_insurance'
self.labour_id = 'labour'
self.urssaf_slice_list = ['salary_range/france/slice_a',
'salary_range/france/slice_b',
'salary_range/france/slice_c']
self.urssaf_share_list = ['tax_category/employee_share',
'tax_category/employer_share']
self.payroll_service_organisation = self.createOrganisation(title='URSSAF')
self.urssaf = self.createPayrollService(id=self.urssaf_id,
title='State Insurance',
product_line='state_insurance',
variation_base_category_list=['tax_category', 'salary_range'],
variation_category_list=self.urssaf_slice_list + \
self.urssaf_share_list,
use='payroll/tax')
self.labour = self.createPayrollService(id=self.labour_id,
title='Labour',
product_line='labour',
use='payroll/base_salary')
self.setSystemPreference() self.setSystemPreference()
def _safeTic(self):
"""Like tic, but swallowing errors, usefull for teardown"""
try:
transaction.commit()
self.tic()
except RuntimeError:
pass
def beforeTearDown(self): def beforeTearDown(self):
"""Clear everything for next test.""" pass
self._safeTic()
for module in [ 'organisation_module',
'person_module',
'currency_module',
'payroll_service_module',
'paysheet_model_module',
'accounting_module']:
folder = getattr(self.getPortal(), module, None)
if folder:
[x.unindexObject() for x in folder.objectValues()]
self._safeTic()
folder.manage_delObjects([x.getId() for x in folder.objectValues()])
self._safeTic()
# cancel remaining messages
activity_tool = self.getPortal().portal_activities
for message in activity_tool.getMessageList():
activity_tool.manageCancel(message.object_path, message.method_id)
ZopeTestCase._print('\nCancelling active message %s.%s()\n'
% (message.object_path, message.method_id) )
transaction.commit()
def login(self): def login(self):
uf = self.getPortal().acl_users uf = self.getPortal().acl_users
...@@ -135,6 +54,7 @@ class TestNewPayrollMixin(ERP5ReportTestCase): ...@@ -135,6 +54,7 @@ class TestNewPayrollMixin(ERP5ReportTestCase):
user = uf.getUserById('admin').__of__(uf) user = uf.getUserById('admin').__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
@reindex
def createCategories(self): def createCategories(self):
"""Create the categories for our test. """ """Create the categories for our test. """
# create categories # create categories
...@@ -145,8 +65,6 @@ class TestNewPayrollMixin(ERP5ReportTestCase): ...@@ -145,8 +65,6 @@ class TestNewPayrollMixin(ERP5ReportTestCase):
self.getPortal().portal_categories.newContent(\ self.getPortal().portal_categories.newContent(\
portal_type='Base Category', portal_type='Base Category',
id=base_cat) id=base_cat)
transaction.commit()
self.tic()
path = self.getPortal().portal_categories[base_cat] path = self.getPortal().portal_categories[base_cat]
for cat in cat_string.split("/")[1:] : for cat in cat_string.split("/")[1:] :
if not cat in path.objectIds() : if not cat in path.objectIds() :
...@@ -156,8 +74,6 @@ class TestNewPayrollMixin(ERP5ReportTestCase): ...@@ -156,8 +74,6 @@ class TestNewPayrollMixin(ERP5ReportTestCase):
title=cat.replace('_', ' ').title(),) title=cat.replace('_', ' ').title(),)
else: else:
path = path[cat] path = path[cat]
transaction.commit()
self.tic()
# check categories have been created # check categories have been created
for cat_string in self.getNeededCategoryList() : for cat_string in self.getNeededCategoryList() :
self.assertNotEquals(None, self.assertNotEquals(None,
...@@ -166,378 +82,259 @@ class TestNewPayrollMixin(ERP5ReportTestCase): ...@@ -166,378 +82,259 @@ class TestNewPayrollMixin(ERP5ReportTestCase):
def getNeededCategoryList(self): def getNeededCategoryList(self):
"""return a list of categories that should be created.""" """return a list of categories that should be created."""
return ('region/europe/west/france', return ('tax_category/employer_share',
'salary_range/france/forfait',
'salary_range/france/slice_a',
'salary_range/france/slice_b',
'salary_range/france/slice_c',
'tax_category/employer_share',
'tax_category/employee_share', 'tax_category/employee_share',
'base_amount/deductible_tax', 'base_amount/deductible_tax',
'base_amount/non_deductible_tax',
'base_amount/bonus',
'base_amount/base_salary', 'base_amount/base_salary',
'base_amount/net_salary',
'grade/worker', 'grade/worker',
'grade/engineer', 'grade/engineer',
'quantity_unit/time/month', 'quantity_unit/time/month',
'group/demo_group', 'product_line/labour',
'product_line/base_salary', 'product_line/state_insurance',
'product_line/payroll_tax_1',
'product_line/payroll_tax_2',
'use/payroll/tax', 'use/payroll/tax',
'use/payroll/base_salary', 'use/payroll/base_salary',
'trade_phase/payroll/france/urssaf', 'trade_phase/payroll/france/urssaf',
) )
def createCurrencies(self):
"""Create some currencies.
This script will reuse existing currencies, because we want currency ids
to be stable, as we use them as categories.
"""
currency_module = self.getCurrencyModule()
if not hasattr(currency_module, 'EUR'):
self.EUR = currency_module.newContent(
portal_type = 'Currency',
reference = "EUR", id = "EUR", base_unit_quantity=0.001 )
self.USD = currency_module.newContent(
portal_type = 'Currency',
reference = "USD", id = "USD" )
self.YEN = currency_module.newContent(
portal_type = 'Currency',
reference = "YEN", id = "YEN" )
transaction.commit()
self.tic()
else:
self.EUR = currency_module.EUR
self.USD = currency_module.USD
self.YEN = currency_module.YEN
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """ """ """
return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting', return ('erp5_base', 'erp5_pdm', 'erp5_trade', 'erp5_accounting',
'erp5_invoicing', 'erp5_payroll', 'erp5_mrp', 'erp5_bpm') 'erp5_invoicing', 'erp5_payroll', 'erp5_mrp', 'erp5_bpm')
def createPerson(self, title, def createPayrollService(self):
career_subordination_value=None, career_grade=None, **kw): module = self.portal.getDefaultModule(portal_type='Payroll Service')
""" return module.newContent(portal_type='Payroll Service')
Create some Pesons so that we have something to feed.
"""
person_module = self.portal.getDefaultModule(portal_type='Person')
person = person_module.newContent(portal_type='Person')
person.edit(
title=title,
career_subordination_value=career_subordination_value,
career_grade=career_grade)
transaction.commit()
self.tic()
return person
def createOrganisation(self, title, **kw):
organisation = self.organisation_module.newContent( \
portal_type='Organisation',
title=title)
transaction.commit()
self.tic()
return organisation
def createPayrollService(self, id='', title='',
variation_base_category_list=None,
variation_category_list=None, product_line=None, **kw):
if variation_category_list == None:
variation_category_list=[]
if variation_base_category_list == None:
variation_category_list=[]
if hasattr(self.payroll_service_module, id):
self.payroll_service_module.manage_delObjects([id])
payroll_service = self.payroll_service_module.newContent(
title=title,
portal_type='Payroll Service',
id=id,
quantity_unit='time/month',
product_line=product_line,
**kw)
payroll_service.setVariationBaseCategoryList(variation_base_category_list)
payroll_service.setVariationCategoryList(variation_category_list)
transaction.commit()
self.tic()
return payroll_service
def createModel(self, title='',
person_title='', person_career_grade='',
organisation_title='',
variation_settings_category_list=None,
price_currency=''):
"""
Create a model
"""
if variation_settings_category_list == None:
variation_settings_category_list = []
organisation = self.createOrganisation(organisation_title)
person = self.createPerson(title=person_title,
career_subordination_value=organisation,
career_grade=person_career_grade)
paysheet_model = self.paysheet_model_module.newContent( \
portal_type='Pay Sheet Model')
paysheet_model.edit(\
title=title,
variation_settings_category_list=['salary_range/france',],
destination_section_value=organisation,
source_section_value=person,)
paysheet_model.setPriceCurrency(price_currency)
transaction.commit()
self.tic()
return paysheet_model
class TestNewPayroll(TestNewPayrollMixin):
def test_01_basicPaySheetCalculation(self): def stepCreateUrssafPayrollService(self, sequence=None, **kw):
''' node = self.createPayrollService()
test applyTransformation method. It should create new movements node.edit(title='Urssaf',
''' product_line='state_insurance', quantity_unit='time/month',
model = self.createModel('Homer Model', 'Homer Simpson', 'worker', variation_base_category_list=['tax_category', 'salary_range'],
'Nexedi', [], self.price_currency) use='payroll/tax')
sequence.edit(urssaf_payroll_service = node)
share_list = ['tax_category/employee_share',
'tax_category/employer_share'] def stepCreateLabourPayrollService(self, sequence=None, **kw):
node = self.createPayrollService()
# add a model line node.edit(title='Labour', quantity_unit='time/month',
model_line1 = model.newContent(portal_type='Pay Sheet Model Line', product_line='labour', use='payroll/base_salary')
title='Urssaf', sequence.edit(labour_payroll_service = node)
int_index=2,
resource_value=self.urssaf, def createModel(self):
variation_category_list=share_list, module = self.portal.getDefaultModule(portal_type='Pay Sheet Model')
source_value=self.payroll_service_organisation, return module.newContent(portal_type='Pay Sheet Model')
base_application_list=[ 'base_amount/base_salary'],
base_contribution_list=['base_amount/deductible_tax']) def createPerson(self):
# if the line has cells with different tax categories, new properties are module = self.portal.getDefaultModule(portal_type='Person')
# added to this line. return module.newContent(portal_type='Person')
model_line1.setResourceValue(self.urssaf)
model_line1.setVariationCategoryList(['tax_category/employee_share', def createOrganisation(self):
'tax_category/employer_share']) module = self.portal.getDefaultModule(portal_type='Organisation')
transaction.commit() return module.newContent(portal_type='Organisation')
self.tic()
def stepCreateEmployee(self, sequence=None, **kw):
# create movement employer = sequence.get('employer')
cell1 = model_line1.newCell('tax_category/employee_share', node = self.createPerson()
node.edit(title='Employee',
career_subordination_value=employer)
sequence.edit(employee = node)
def stepCreateEmployer(self, sequence=None, **kw):
node = self.createOrganisation()
node.edit(title='Employer')
sequence.edit(employer = node)
def stepCreateBasicModel(self, sequence=None, **kw):
model = self.createModel()
employer = sequence.get('employer')
employee = sequence.get('employee')
model.edit(destination_section_value=employer,
source_section_value=employee)
sequence.edit(model = model)
def createModelLine(self, document, **kw):
return document.newContent(portal_type='Pay Sheet Model Line', **kw)
def stepModelCreateUrssafModelLine(self, sequence=None, **kw):
model = sequence.get('model')
model_line = self.createModelLine(model)
model_line.edit(title='Urssaf',
int_index=2,
trade_phase='trade_phase/payroll/france/urssaf',
resource_value=sequence.get('urssaf_payroll_service'),
variation_category_list=['tax_category/employee_share',
'tax_category/employer_share'],
base_application_list=[ 'base_amount/base_salary'],
base_contribution_list=['base_amount/deductible_tax'])
sequence.edit(urssaf_model_line = model_line)
def stepCreateMovementOnUrssafModelLine(self, sequence=None, **kw):
model_line = sequence.get('urssaf_model_line')
cell1 = model_line.newCell('tax_category/employee_share',
portal_type='Pay Sheet Cell', portal_type='Pay Sheet Cell',
base_id='movement', base_id='movement',
mapped_value_property_list=('quantity', 'price'),) mapped_value_property_list=('quantity', 'price'))
cell1.edit(price=0.1, tax_category='employee_share') cell1.edit(price=0.1, tax_category='employee_share')
cell2 = model_line.newCell('tax_category/employer_share',
cell2 = model_line1.newCell('tax_category/employer_share',
portal_type='Pay Sheet Cell', portal_type='Pay Sheet Cell',
base_id='movement', base_id='movement',
mapped_value_property_list=('quantity', 'price'),) mapped_value_property_list=('quantity', 'price'))
cell2.edit(price=0.5, tax_category='employer_share') cell2.edit(price=0.5, tax_category='employer_share')
transaction.commit() sequence.edit(urssaf_model_line_cell1 = cell1)
self.tic() sequence.edit(urssaf_model_line_cell2 = cell2)
# create paysheet def createPaysheet(self, sequence=None, **kw):
paysheet_module = self.portal.getDefaultModule(\ module = self.portal.getDefaultModule(portal_type='Pay Sheet Transaction')
portal_type='Pay Sheet Transaction') return module.newContent(portal_type='Pay Sheet Transaction')
paysheet = paysheet_module.newContent(\
portal_type='Pay Sheet Transaction', def stepCreateBasicPaysheet(self, sequence=None, **kw):
title='test 1', paysheet = self.createPaysheet()
specialise_value=model, paysheet.edit(title='test 1',
source_section_value=model.getSourceSectionValue(), specialise_value=sequence.get('model'),
destination_section_value=model.getDestinationSectionValue()) source_section_value=sequence.get('employee'),
paysheet.setPriceCurrency('currency_module/EUR') destination_section_value=sequence.get('employer'))
transaction.commit() sequence.edit(paysheet = paysheet)
self.tic()
def createPaysheetLine(self, document, **kw):
# add an input line (the salary) in the paysheet return document.newContent(portal_type='Pay Sheet Line', **kw)
labour_line = paysheet.newContent(portal_type='Pay Sheet Line',
resource_value=self.labour, def stepPaysheetCreateLabourPaySheetLine(self, sequence=None, **kw):
source_section_value=model.getSourceSectionValue(), paysheet = sequence.get('paysheet')
destination_section_value=model.getDestinationSectionValue(), paysheet_line = self.createPaysheetLine(paysheet)
int_index=1, paysheet_line.edit(title='Labour',
price=20, int_index=1,
quantity=150, price=20,
base_application_list=[], quantity=150,
base_contribution_list=['base_amount/base_salary', resource_value=sequence.get('labour_payroll_service'),
'base_amount/gross_salary']) base_contribution_list=[ 'base_amount/base_salary'])
self.assertEqual(labour_line.getTotalPrice(), 3000.0) sequence.edit(labour_paysheet_line = paysheet_line)
# check updateAggregatedMovement method return def stepCheckUpdateAggregatedMovementReturn(self, sequence=None, **kw):
# XXX updateAggregatedMovement have to be tested in a generic way (not on model = sequence.get('model')
# payroll but context independant). Currently, there is no test for that paysheet = sequence.get('paysheet')
movement_dict = model.updateAggregatedAmountList(context=paysheet) movement_dict = model.updateAggregatedAmountList(context=paysheet)
movement_to_delete = movement_dict['movement_to_delete_list'] movement_to_delete = movement_dict['movement_to_delete_list']
movement_to_add = movement_dict['movement_to_add_list'] movement_to_add = movement_dict['movement_to_add_list']
self.assertEquals(len(movement_to_delete), 0) self.assertEquals(len(movement_to_delete), 0)
self.assertEquals(len(movement_to_add), 2) self.assertEquals(len(movement_to_add), 2)
# calculate the pay sheet def stepPaysheetApplyTransformation(self, sequence=None, **kw):
paysheet = sequence.get('paysheet')
paysheet.applyTransformation() paysheet.applyTransformation()
transaction.commit()
self.tic()
# check lines were created def stepCheckPaysheetLineAreCreated(self, sequence=None, **kw):
paysheet = sequence.get('paysheet')
paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line') paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
self.assertEqual(len(paysheet_line_list), 2) self.assertEqual(len(paysheet_line_list), 2)
self.assertEqual(len(paysheet.getMovementList(portal_type=\ self.assertEqual(len(paysheet.getMovementList(portal_type=\
'Pay Sheet Cell')), 2) 'Pay Sheet Cell')), 2)
# check the amount in the cells of the created paysheet lines def stepCheckPaysheetLineAmounts(self, sequence=None, **kw):
paysheet = sequence.get('paysheet')
paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
for paysheet_line in paysheet_line_list: for paysheet_line in paysheet_line_list:
service = paysheet_line.getResourceId() service = paysheet_line.getResourceTitle()
if service == self.urssaf_id: if service == 'Urssaf':
cell1 = paysheet_line.getCell('tax_category/employee_share') cell1 = paysheet_line.getCell('tax_category/employee_share')
self.assertEquals(cell1.getQuantity(), 3000) self.assertEquals(cell1.getQuantity(), 3000)
self.assertEquals(cell1.getPrice(), 0.1) self.assertEquals(cell1.getPrice(), 0.1)
cell2 = paysheet_line.getCell('tax_category/employer_share') cell2 = paysheet_line.getCell('tax_category/employer_share')
self.assertEquals(cell2.getQuantity(), 3000) self.assertEquals(cell2.getQuantity(), 3000)
self.assertEquals(cell2.getPrice(), 0.5) self.assertEquals(cell2.getPrice(), 0.5)
elif service == self.labour_id: elif service == 'Labour':
self.assertEqual(paysheet_line.getTotalPrice(), 3000.0) self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
else: else:
self.fail("Unknown service for line %s" % paysheet_line) self.fail("Unknown service for line %s" % paysheet_line)
# check that after the line creation, updateAggregatedAmountList return def stepCheckUpdateAggregatedAmountListReturnNothing(self, sequence=None, **kw):
# nothing paysheet = sequence.get('paysheet')
model = sequence.get('model')
movement_dict = model.updateAggregatedAmountList(context=paysheet) movement_dict = model.updateAggregatedAmountList(context=paysheet)
movement_to_delete = movement_dict['movement_to_delete_list'] movement_to_delete = movement_dict['movement_to_delete_list']
movement_to_add = movement_dict['movement_to_add_list'] movement_to_add = movement_dict['movement_to_add_list']
self.assertEquals(len(movement_to_delete), 0) self.assertEquals(len(movement_to_delete), 0)
self.assertEquals(len(movement_to_add), 0) self.assertEquals(len(movement_to_add), 0)
def test_02_setSourceOnMovementUsingBusinessProcess(self): def stepCreateUrssafRoubaixOrganisation(self, sequence=None, **kw):
''' node = self.createOrganisation()
check that the sources and destinations of all sort (section, bank) are node.edit(title='Urssaf de Roubaix Tourcoing')
provided by the business process and define on every line of the paysheet sequence.edit(urssaf_roubaix = node)
transaction
'''
model = self.createModel('Homer Model', 'Homer Simpson', 'worker',
'Nexedi', [], self.price_currency)
# create Business Process
business_process_module = self.portal.getDefaultModule(portal_type=\
'Business Process')
business_process = business_process_module.newContent(portal_type=\
'Business Process')
path = business_process.newContent(portal_type='Business Path')
path.setTradePhaseList(['trade_phase/payroll/france/urssaf'])
organisation_module = self.portal.getDefaultModule(portal_type=\
'Organisation')
urssaf_roubaix = organisation_module.newContent(portal_type='Organisation',
title='Urssaf de Roubaix Tourcoing')
path.setSourceDecisionValue(urssaf_roubaix) def stepModifyBusinessPathTradePhase(self, sequence=None, **kw):
business_path = sequence.get('business_path')
business_path.setTradePhaseList(['trade_phase/payroll/france/urssaf'])
business_path.setSourceDecisionValue(sequence.get('urssaf_roubaix'))
sequence.edit(business_path=business_path)
# set the business process on the specialise list of the model def stepSpecialiseBusinessProcessOnModel(self, sequence=None, **kw):
model = sequence.get('model')
business_process = sequence.get('business_process')
model.setSpecialiseValueList(business_process) model.setSpecialiseValueList(business_process)
share_list = ['tax_category/employee_share', def stepCheckSourceSectionOnMovements(self, sequence=None, **kw):
'tax_category/employer_share'] '''Check that the cell contain urssaf_roubaix as source section. This should
be the case if getAggregatedAmountList from PaySheetModelLine is able to
# add a model line use Business Process to find the good source_section'''
model_line1 = model.newContent(portal_type='Pay Sheet Model Line', paysheet = sequence.get('paysheet')
title='Urssaf',
int_index=2,
trade_phase='trade_phase/payroll/france/urssaf',
resource_value=self.urssaf,
variation_category_list=share_list,
source_value=self.payroll_service_organisation,
base_application_list=[ 'base_amount/base_salary'],
base_contribution_list=['base_amount/deductible_tax'])
# if the line has cells with different tax categories, new properties are
# added to this line.
model_line1.setResourceValue(self.urssaf)
model_line1.setVariationCategoryList(['tax_category/employee_share',
'tax_category/employer_share'])
transaction.commit()
self.tic()
# create movement
cell1 = model_line1.newCell('tax_category/employee_share',
portal_type='Pay Sheet Cell',
base_id='movement',
mapped_value_property_list=('quantity', 'price'),)
cell1.edit(price=0.1, tax_category='employee_share')
cell2 = model_line1.newCell('tax_category/employer_share',
portal_type='Pay Sheet Cell',
base_id='movement',
mapped_value_property_list=('quantity', 'price'),)
cell2.edit(price=0.5, tax_category='employer_share')
transaction.commit()
self.tic()
# create paysheet
paysheet_module = self.portal.getDefaultModule(\
portal_type='Pay Sheet Transaction')
paysheet = paysheet_module.newContent(\
portal_type='Pay Sheet Transaction',
title='test 1',
specialise_value=model,
source_section_value=model.getSourceSectionValue(),
destination_section_value=model.getDestinationSectionValue())
paysheet.setPriceCurrency('currency_module/EUR')
transaction.commit()
self.tic()
# add an input line (the salary) in the paysheet
labour_line = paysheet.newContent(portal_type='Pay Sheet Line',
resource_value=self.labour,
source_section_value=model.getSourceSectionValue(),
destination_section_value=model.getDestinationSectionValue(),
int_index=1,
price=20,
quantity=150,
base_application_list=[],
base_contribution_list=['base_amount/base_salary',
'base_amount/gross_salary'])
self.assertEqual(labour_line.getTotalPrice(), 3000.0)
# check updateAggregatedMovement method return
# XXX updateAggregatedMovement have to be tested in a generic way (not on
# payroll but context independant). Currently, there is no test for that
movement_dict = model.updateAggregatedAmountList(context=paysheet)
movement_to_delete = movement_dict['movement_to_delete_list']
movement_to_add = movement_dict['movement_to_add_list']
self.assertEquals(len(movement_to_delete), 0)
self.assertEquals(len(movement_to_add), 2)
# calculate the pay sheet
paysheet.applyTransformation()
transaction.commit()
self.tic()
# check lines were created
paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line') paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
self.assertEqual(len(paysheet_line_list), 2) urssaf_roubaix = sequence.get('urssaf_roubaix')
self.assertEqual(len(paysheet.getMovementList(portal_type=\
'Pay Sheet Cell')), 2)
# check the amount in the cells of the created paysheet lines
for paysheet_line in paysheet_line_list: for paysheet_line in paysheet_line_list:
service = paysheet_line.getResourceId() service = paysheet_line.getResourceTitle()
if service == self.urssaf_id: if service == 'Urssaf':
cell1 = paysheet_line.getCell('tax_category/employee_share') cell1 = paysheet_line.getCell('tax_category/employee_share')
self.assertEquals(cell1.getQuantity(), 3000)
self.assertEquals(cell1.getPrice(), 0.1)
# check source_section
self.assertEquals(cell1.getSourceSectionValue(), urssaf_roubaix) self.assertEquals(cell1.getSourceSectionValue(), urssaf_roubaix)
cell2 = paysheet_line.getCell('tax_category/employer_share') cell2 = paysheet_line.getCell('tax_category/employer_share')
self.assertEquals(cell2.getQuantity(), 3000)
self.assertEquals(cell2.getPrice(), 0.5)
# check source_section
self.assertEquals(cell2.getSourceSectionValue(), urssaf_roubaix) self.assertEquals(cell2.getSourceSectionValue(), urssaf_roubaix)
elif service == self.labour_id: elif service == 'Labour':
self.assertEqual(paysheet_line.getTotalPrice(), 3000.0) pass
else: else:
self.fail("Unknown service for line %s" % paysheet_line) self.fail("Unknown service for line %s" % paysheet_line)
# check that after the line creation, updateAggregatedAmountList return class TestNewPayroll(TestNewPayrollMixin):
# nothing COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING = """
movement_dict = model.updateAggregatedAmountList(context=paysheet) CreateUrssafPayrollService
movement_to_delete = movement_dict['movement_to_delete_list'] CreateLabourPayrollService
movement_to_add = movement_dict['movement_to_add_list'] CreateEmployer
self.assertEquals(len(movement_to_delete), 0) CreateEmployee
self.assertEquals(len(movement_to_add), 0) CreateBasicModel
ModelCreateUrssafModelLine
CreateMovementOnUrssafModelLine
CreateBasicPaysheet
PaysheetCreateLabourPaySheetLine
Tic
"""
def test_01_basicPaySheetCalculation(self):
'''
test applyTransformation method. It should create new movements
'''
sequence_list = SequenceList()
sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
CheckUpdateAggregatedMovementReturn
PaysheetApplyTransformation
Tic
CheckPaysheetLineAreCreated
CheckPaysheetLineAmounts
CheckUpdateAggregatedAmountListReturnNothing
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
def test_02_setSourceOnMovementUsingBusinessProcess(self):
sequence_list = SequenceList()
sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
CreateBusinessProcess
CreateBusinessPath
CreateUrssafRoubaixOrganisation
ModifyBusinessPathTradePhase
SpecialiseBusinessProcessOnModel
Tic
CheckUpdateAggregatedMovementReturn
PaysheetApplyTransformation
Tic
CheckSourceSectionOnMovements
"""
sequence_list.addSequenceString(sequence_string)
sequence_list.play(self)
import unittest import unittest
def test_suite(): 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