testPayroll.py 156 KB
Newer Older
1 2
##############################################################################
#
3
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
4 5 6
#          Fabien Morin <fabien.morin@gmail.com>
#
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsibility of assessing all potential
8 9
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
10
# guarantees and support are strongly adviced to contract a Free Software
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
28
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5ReportTestCase
29
from Products.ERP5.tests.testTradeModelLine import TestTradeModelLineMixin
30
from AccessControl.SecurityManagement import newSecurityManager
31 32
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5Type.tests.utils import reindex
33
from DateTime import DateTime
34 35
import transaction

36
class TestPayrollMixin(ERP5ReportTestCase, TestTradeModelLineMixin):
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
  BUSINESS_PATH_CREATION_SEQUENCE_STRING = """
               CreateBusinessProcess
               CreateBusinessPath
               CreateUrssafRoubaixOrganisation
               ModifyBusinessPathTradePhase
               ModelSpecialiseBusinessProcess
               Tic
  """
  COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING = """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreatePriceCurrency
               CreateBasicModel
52
               Tic
53 54 55 56 57 58 59 60
               ModelCreateUrssafModelLine
               UrssafModelLineCreateMovements
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
               Tic
  """ + BUSINESS_PATH_CREATION_SEQUENCE_STRING


61 62 63 64 65 66 67
  def getTitle(self):
    return "Payroll"

  def afterSetUp(self):
    """Prepare the test."""
    self.createCategories()

68
  @reindex
69
  def beforeTearDown(self):
70 71 72 73 74 75 76 77 78 79 80
    transaction.abort()
    for module in (
      self.portal.organisation_module,
      self.portal.person_module,
      self.portal.paysheet_model_module,
      self.portal.accounting_module,
      self.portal.business_process_module,
      self.portal.service_module,
      self.portal.portal_simulation,):
      module.manage_delObjects(list(module.objectIds()))

81

82
  def login(self):
83
    uf = self.getPortal().acl_users
84
    uf._doAddUser('admin', '', ['Manager', 'Assignee', 'Assignor',
85 86 87 88
                               'Associate', 'Auditor', 'Author'], [])
    user = uf.getUserById('admin').__of__(uf)
    newSecurityManager(None, user)

89
  @reindex
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
  def createCategories(self):
    """Create the categories for our test. """
    # create categories
    for cat_string in self.getNeededCategoryList() :
      base_cat = cat_string.split("/")[0]
      # if base_cat not exist, create it
      if getattr(self.getPortal().portal_categories, base_cat, None) == None:
        self.getPortal().portal_categories.newContent(\
                                          portal_type='Base Category',
                                          id=base_cat)
      path = self.getPortal().portal_categories[base_cat]
      for cat in cat_string.split("/")[1:] :
        if not cat in path.objectIds() :
          path = path.newContent(
                    portal_type='Category',
                    id=cat,
                    title=cat.replace('_', ' ').title(),)
        else:
          path = path[cat]
    # check categories have been created
    for cat_string in self.getNeededCategoryList() :
      self.assertNotEquals(None,
                self.getCategoryTool().restrictedTraverse(cat_string),
                cat_string)

  def getNeededCategoryList(self):
    """return a list of categories that should be created."""
117 118
    return ('contribution_share/employer',
            'contribution_share/employee',
119 120 121 122
            'base_amount/payroll/base/income_tax',
            'base_amount/payroll/base/contribution',
            'base_amount/payroll/report/salary/net',
            'base_amount/payroll/report/salary/gross',
123 124
            'grade/worker',
            'grade/engineer',
125
            'quantity_unit/time/month',
126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
            'product_line/labour',
            'product_line/state_insurance',
            'use/payroll/tax',
            'use/payroll/base_salary',
            'use/payroll/output',
            'trade_phase/payroll/france/urssaf',
            'trade_phase/payroll/france/labour',
            'time/hours',
            'salary_range/france',
            'salary_range/france/slice_a',
            'salary_range/france/slice_b',
            'salary_range/france/slice_c',
            'salary_range/france/forfait',
            'salary_range/france/slice_0_to_200',
            'salary_range/france/slice_200_to_400',
            'salary_range/france/slice_400_to_5000',
            'salary_range/france/slice_600_to_800',
            'marital_status/married',
            'marital_status/single',
145
            'group/demo_group',
146 147 148
           )

  def getBusinessTemplateList(self):
149
    return TestTradeModelLineMixin.getBusinessTemplateList(self) + ('erp5_payroll', )
150

151 152 153 154 155 156 157 158
  def createService(self):
    module = self.portal.getDefaultModule(portal_type='Service')
    return module.newContent(portal_type='Service')

  def stepCreateUrssafService(self, sequence=None, **kw):
    node = self.createService()
    node.edit(title='Urssaf',
        product_line='state_insurance', quantity_unit='time/month',
159
        variation_base_category_list=['contribution_share', 'salary_range'],
160
        use='payroll/tax')
161 162
    node.setVariationCategoryList(['contribution_share/employee',
                                   'contribution_share/employer',
Fabien Morin's avatar
Fabien Morin committed
163 164 165 166 167
                                    'salary_range/france/slice_0_to_200',
                                    'salary_range/france/slice_200_to_400',
                                    'salary_range/france/slice_400_to_5000',
                                    'salary_range/france/slice_600_to_800',
                                   ])
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    sequence.edit(urssaf_service = node)

  def stepCreateLabourService(self, sequence=None, **kw):
    node = self.createService()
    node.edit(title='Labour', quantity_unit='time/month',
        product_line='labour', use='payroll/base_salary')
    sequence.edit(labour_service = node)

  def stepCreateLabourOutputService(self, sequence=None, **kw):
    '''In case we want to have the labour line in the model, the use category
    should not be base_salary (=input) because in this case the line will be
    added on each calculation'''
    node = self.createService()
    node.edit(title='Labour', quantity_unit='time/month',
        product_line='labour', use='payroll/output')
    sequence.edit(labour_service = node)

  def stepCreateBonusService(self, sequence=None, **kw):
    node = self.createService()
    node.edit(title='Bonus', quantity_unit='time/month',
188
        variation_base_category_list=['contribution_share'],
189
        product_line='labour', use='payroll/base_salary')
190 191
    node.setVariationCategoryList(['contribution_share/employee',
                                   'contribution_share/employer'])
192 193 194 195 196
    sequence.edit(bonus_service = node)

  def stepCreateOldAgeInsuranaceService(self, sequence=None, **kw):
    node = self.createService()
    node.edit(title='Old Age Insurance', quantity_unit='time/month',
197
        variation_base_category_list=['contribution_share', 'salary_range'],
198
        product_line='state_insurance', use='payroll/tax')
199 200
    node.setVariationCategoryList(['contribution_share/employee',
                                   'contribution_share/employer'])
201 202 203 204 205
    sequence.edit(old_age_insurance_service = node)

  def stepCreateSicknessInsuranceService(self, sequence=None, **kw):
    node = self.createService()
    node.edit(title='Sickness Insurance', quantity_unit='time/month',
206
        variation_base_category_list=['contribution_share', 'salary_range'],
207
        product_line='state_insurance', use='payroll/tax')
208 209
    node.setVariationCategoryList(['contribution_share/employee',
                                   'contribution_share/employer'])
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240
    sequence.edit(sickness_insurance_service = node)

  def createModel(self):
    module = self.portal.getDefaultModule(portal_type='Pay Sheet Model')
    return module.newContent(portal_type='Pay Sheet Model')

  def createPerson(self):
    module = self.portal.getDefaultModule(portal_type='Person')
    return module.newContent(portal_type='Person')

  def createOrganisation(self):
    module = self.portal.getDefaultModule(portal_type='Organisation')
    return module.newContent(portal_type='Organisation')

  def stepCreateEmployee(self, sequence=None, **kw):
    employer = sequence.get('employer')
    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,
241 242 243 244 245 246
        source_section_value=employee,
        effective_date=DateTime(2009,01,01),
        expiration_date=DateTime(2009,12,31),
        version='001',
        reference='basic_model',
    )
247
    sequence.edit(model = model)
248 249

  def addSlice(self, model, slice, min_value, max_value, base_id='cell'):
250
    '''add a new slice in the model'''
251
    slice_value = model.newCell(slice, portal_type='Pay Sheet Model Slice',
252
        base_id=base_id)
253 254 255
    slice_value.setQuantityRangeMax(max_value)
    slice_value.setQuantityRangeMin(min_value)
    return slice_value
Fabien Morin's avatar
Fabien Morin committed
256

257 258 259 260
  def stepSetCurrencyOnModel(self, sequence=None, **kw):
    model = sequence.get('model')
    currency = sequence.get('price_currency')
    model.setPriceCurrencyValue(currency)
261

262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
  def stepCreateModelWithSlices(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)
    model.setVariationSettingsCategoryList(\
        ['salary_range/france'])
    self.addSlice(model, 'salary_range/france/slice_0_to_200', 0, 200)
    self.addSlice(model, 'salary_range/france/slice_200_to_400', 200, 400)
    self.addSlice(model, 'salary_range/france/slice_400_to_5000', 400, 5000)
    self.addSlice(model, 'salary_range/france/slice_600_to_800', 600, 800)
    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',
                    reference='urssaf_model_line',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
286 287
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
288 289
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
290 291 292 293 294 295 296 297 298
    sequence.edit(urssaf_model_line = model_line)

  def stepModelCreateUrssafModelLineWithSlices(self, sequence=None, **kw):
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='Urssaf',
                    reference='urssaf_model_line_2',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
299 300
                    variation_category_list=['contribution_share/employee',
                                       'contribution_share/employer',
301 302 303
                                       'salary_range/france/slice_0_to_200',
                                       'salary_range/france/slice_200_to_400',
                                       'salary_range/france/slice_400_to_5000'],
304 305
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
306 307 308 309 310 311 312 313 314
    sequence.edit(urssaf_model_line_with_slices = model_line)

  def stepModelCreateUrssafModelLineWithComplexSlices(self, sequence=None, **kw):
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='Urssaf',
                    reference='urssaf_model_line_3',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
315 316
                    variation_category_list=['contribution_share/employee',
                                       'contribution_share/employer',
317 318
                                       'salary_range/france/slice_200_to_400',
                                       'salary_range/france/slice_600_to_800'],
319 320
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
321 322 323 324 325 326 327 328 329 330 331 332
    sequence.edit(urssaf_model_line_with_slices = model_line)

  def stepPaysheetCreateUrssafModelLine(self, sequence=None, **kw):
    '''The model line created here have the same reference than the model line
    created in stepModelCreateUrssafModelLine. This is used for line
    overloading tests'''
    paysheet = sequence.get('paysheet')
    model_line = self.createModelLine(paysheet)
    model_line.edit(title='Urssaf',
                    reference='urssaf_model_line',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
333 334
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
335 336
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
337 338 339 340
    sequence.edit(urssaf_model_line = model_line)

  def stepUrssafModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line')
341
    cell1 = model_line.newCell('contribution_share/employee',
342 343 344
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
345 346
    cell1.edit(price=0.1, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
347 348 349
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
350
    cell2.edit(price=0.5, contribution_share='employer')
351 352 353

  def stepUrssafModelLineCreateMovementsWithQuantityOnly(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line')
354
    cell1 = model_line.newCell('contribution_share/employee',
355 356 357
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
358 359
    cell1.edit(quantity=-100, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
360 361 362
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
363
    cell2.edit(quantity=-200, contribution_share='employer')
364 365 366

  def stepUrssafModelLineWithSlicesCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line_with_slices')
367
    cell1 = model_line.newCell('contribution_share/employee',
368
        'salary_range/france/slice_0_to_200',
369 370 371
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
372
    cell1.edit(price=0.1, contribution_share='employee',
373
        salary_range='france/slice_0_to_200')
374
    cell2 = model_line.newCell('contribution_share/employer',
375
        'salary_range/france/slice_0_to_200',
376 377 378
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
379
    cell2.edit(price=0.2, contribution_share='employer',
380
        salary_range='france/slice_0_to_200')
381
    cell3 = model_line.newCell('contribution_share/employee',
382
        'salary_range/france/slice_200_to_400',
383 384 385
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
386
    cell3.edit(price=0.3, contribution_share='employee',
387
        salary_range='france/slice_200_to_400')
388
    cell4 = model_line.newCell('contribution_share/employer',
389
        'salary_range/france/slice_200_to_400',
390 391 392
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
393
    cell4.edit(price=0.4, contribution_share='employer',
394
        salary_range='france/slice_200_to_400')
395
    cell5 = model_line.newCell('contribution_share/employee',
396
        'salary_range/france/slice_400_to_5000',
397 398 399
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
400
    cell5.edit(price=0.5, contribution_share='employee',
401
        salary_range='france/slice_400_to_5000')
402
    cell6 = model_line.newCell('contribution_share/employer',
403
        'salary_range/france/slice_400_to_5000',
404 405 406
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
407
    cell6.edit(price=0.6, contribution_share='employer',
408 409 410 411 412
        salary_range='france/slice_400_to_5000')

  def stepUrssafModelLineWithComplexSlicesCreateMovements(self,
      sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line_with_slices')
413
    cell1 = model_line.newCell('contribution_share/employee',
414
        'salary_range/france/slice_200_to_400',
415 416 417
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
418
    cell1.edit(price=0.1, contribution_share='employee',
419
        salary_range='france/slice_200_to_400')
420
    cell2 = model_line.newCell('contribution_share/employer',
421
        'salary_range/france/slice_200_to_400',
422 423 424
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
425
    cell2.edit(price=0.2, contribution_share='employer',
426
        salary_range='france/slice_200_to_400')
427
    cell3 = model_line.newCell('contribution_share/employee',
428
        'salary_range/france/slice_600_to_800',
429 430 431
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
432
    cell3.edit(price=0.3, contribution_share='employee',
433
        salary_range='france/slice_600_to_800')
434
    cell4 = model_line.newCell('contribution_share/employer',
435
        'salary_range/france/slice_600_to_800',
436 437 438
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
439
    cell4.edit(price=0.4, contribution_share='employer',
440 441 442 443
        salary_range='france/slice_600_to_800')

  def stepPaysheetUrssafModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line')
444
    cell1 = model_line.newCell('contribution_share/employee',
445 446 447
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
448 449
    cell1.edit(price=0.3, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
450 451 452
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
453
    cell2.edit(price=0.7, contribution_share='employer')
454 455 456 457 458 459 460 461 462 463 464 465

  def createPaysheet(self, sequence=None, **kw):
    module = self.portal.getDefaultModule(portal_type='Pay Sheet Transaction')
    return module.newContent(portal_type='Pay Sheet Transaction')

  def stepCreateBasicPaysheet(self, sequence=None, **kw):
    paysheet = self.createPaysheet()
    paysheet.edit(title='test 1',
                  specialise_value=sequence.get('model'),
                  source_section_value=sequence.get('employee'),
                  destination_section_value=sequence.get('employer'),
                  resource_value=sequence.get('price_currency'),
466 467
                  start_date=DateTime(2009,06,01),
                  stop_date=DateTime(2009,06,30))
468 469 470 471 472 473 474 475 476 477 478 479
    sequence.edit(paysheet = paysheet)

  def createPaysheetLine(self, document, **kw):
    return document.newContent(portal_type='Pay Sheet Line', **kw)

  def stepPaysheetCreateLabourPaySheetLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line = self.createPaysheetLine(paysheet)
    paysheet_line.edit(title='Labour',
                    price=20,
                    quantity=150,
                    resource_value=sequence.get('labour_service'),
480 481
                    base_contribution_list=['base_amount/payroll/base/contribution',
                                            'base_amount/payroll/report/salary/gross'])
482 483 484 485 486 487 488
    sequence.edit(labour_paysheet_line = paysheet_line)

  def stepPaysheetCreateBonusPaySheetLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line = self.createPaysheetLine(paysheet)
    paysheet_line.edit(title='Bonus',
                    resource_value=sequence.get('bonus_service'),
489 490
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
491
                    base_contribution_list=[ 'base_amount/payroll/base/contribution'])
492 493 494 495
    sequence.edit(bonus_paysheet_line = paysheet_line)

  def stepPaysheetCreateBonusPaySheetLineMovements(self, sequence=None, **kw):
    paysheet_line = sequence.get('bonus_paysheet_line')
496
    cell1 = paysheet_line.newCell('contribution_share/employee',
497 498 499
        portal_type='Pay Sheet Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
500 501
    cell1.edit(quantity=1000, price=1, contribution_share='employee')
    cell2 = paysheet_line.newCell('contribution_share/employer',
502 503 504
        portal_type='Pay Sheet Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
505
    cell2.edit(quantity=1000, price=1, contribution_share='employer')
506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593

  def checkUpdateAggregatedAmountListReturn(self, model, paysheet,
      expected_movement_to_delete_count, expected_movement_to_add_count):
    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),
        expected_movement_to_delete_count)
    self.assertEquals(len(movement_to_add), expected_movement_to_add_count)

  def stepCheckUpdateAggregatedAmountListReturn(self, sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 0, 2)

  def stepCheckUpdateAggregatedAmountListReturnUsingSlices(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 0, 6)

  def stepCheckUpdateAggregatedAmountListReturnUsingComplexSlices(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 0, 4)

  def stepCheckUpdateAggregatedAmountListReturnUsingPredicate(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 0, 4)

  def stepCheckUpdateAggregatedAmountListReturnAfterChangePredicate(self,
      sequence=None, **kw):
    # the marital status of the employe is change in the way that sickness
    # insurance model_line will not be applied but old age insurance yes.
    # So two movements will be deleted (from sickness insurance) and two should
    # be added (from old age insurance)
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 2, 2)

  def stepCheckUpdateAggregatedAmountListReturnAfterRemoveLine(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 2, 0)

  def stepPaysheetApplyTransformation(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet.applyTransformation()

  def stepCheckPaysheetLineAreCreated(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 2)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 2) # 2 because labour line contain no movement

  def stepCheckNoPaysheetLineAreCreated(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 0)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 0) # 2 because labour line contain no movement

  def stepCheckPaysheetLineAreCreatedUsingBonus(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 3)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 4) # 4 because labour line contain no movement
                               # 2 for bonus, and 2 for urssaf

  def stepCheckThereIsOnlyOnePaysheetLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 1)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 0) # 0 because labour line contain no movement

  def stepCheckPaysheetLineAreCreatedUsingSlices(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 2)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 6) # 6 because labour line contain no movement and
594
                               # because of the 3 slice and 2 contribution_shares
595 596 597 598 599 600 601

  def stepCheckPaysheetLineAreCreatedUsingComplexSlices(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 2)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 4) # 4 because labour line contain no movement and
602
                               # because of the 2 slice and 2 contribution_shares
603 604 605 606 607 608 609

  def stepCheckPaysheetLineAreCreatedUsingWith3Lines(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 3)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 4) # 4 because labour line contain no movement and
610
                               # because of the two lines and 2 contribution_shares
611 612 613
                               # (urssaf and sickness insurance. old age
                               # insurance does not match predicate)

614 615 616 617 618 619
  def stepCheckPaysheetLineAreCreatedAfterUpdateWithLinesWithSameResource(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 3)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 8) # 8 because labour line contain no movement and
620 621
                               # because of the 3 slice and 2 contribution_shares
                               # + the first model line with 2 contribution_shares
622

623 624 625 626 627 628
  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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
629
        cell1 = paysheet_line.getCell('contribution_share/employee')
630 631
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.1)
632
        cell2 = paysheet_line.getCell('contribution_share/employer')
633 634 635 636 637 638 639 640 641 642 643 644 645
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineWithBonusAmounts(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
646
        cell1 = paysheet_line.getCell('contribution_share/employee')
647 648
        self.assertEquals(cell1.getQuantity(), 4000)
        self.assertEquals(cell1.getPrice(), 0.1)
649
        cell2 = paysheet_line.getCell('contribution_share/employer')
650 651 652 653 654
        self.assertEquals(cell2.getQuantity(), 4000)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      elif service == 'Bonus':
655
        cell1 = paysheet_line.getCell('contribution_share/employee')
656
        self.assertEquals(cell1.getTotalPrice(), 1000)
657
        cell2 = paysheet_line.getCell('contribution_share/employer')
658 659 660 661 662 663 664 665 666 667
        self.assertEquals(cell2.getTotalPrice(), 1000)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineAmountsWithQuantityOnly(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
668
        cell1 = paysheet_line.getCell('contribution_share/employee')
669 670
        self.assertEquals(cell1.getQuantity(), -100)
        self.assertEquals(cell1.getPrice(), 1)
671
        cell2 = paysheet_line.getCell('contribution_share/employer')
672 673 674 675 676 677 678 679 680 681 682 683 684
        self.assertEquals(cell2.getQuantity(), -200)
        self.assertEquals(cell2.getPrice(), 1)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineAmountsUsingSlices(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
685
        cell1 = paysheet_line.getCell('contribution_share/employee',
686 687 688
            'salary_range/france/slice_0_to_200')
        self.assertEquals(cell1.getQuantity(), 200)
        self.assertEquals(cell1.getPrice(), 0.1)
689
        cell2 = paysheet_line.getCell('contribution_share/employer',
690 691 692
            'salary_range/france/slice_0_to_200')
        self.assertEquals(cell2.getQuantity(), 200)
        self.assertEquals(cell2.getPrice(), 0.2)
693
        cell3 = paysheet_line.getCell('contribution_share/employee',
694 695 696
            'salary_range/france/slice_200_to_400')
        self.assertEquals(cell3.getQuantity(), 200)
        self.assertEquals(cell3.getPrice(), 0.3)
697
        cell4 = paysheet_line.getCell('contribution_share/employer',
698 699 700
            'salary_range/france/slice_200_to_400')
        self.assertEquals(cell4.getQuantity(), 200)
        self.assertEquals(cell4.getPrice(), 0.4)
701
        cell5 = paysheet_line.getCell('contribution_share/employee',
702 703 704
            'salary_range/france/slice_400_to_5000')
        self.assertEquals(cell5.getQuantity(), 2600)
        self.assertEquals(cell5.getPrice(), 0.5)
705
        cell6 = paysheet_line.getCell('contribution_share/employer',
706 707 708 709 710 711 712 713 714 715 716 717 718 719
            'salary_range/france/slice_400_to_5000')
        self.assertEquals(cell6.getQuantity(), 2600)
        self.assertEquals(cell6.getPrice(), 0.6)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineAmountsUsingComplexSlices(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
720
        cell1 = paysheet_line.getCell('contribution_share/employee',
721 722 723
            'salary_range/france/slice_200_to_400')
        self.assertEquals(cell1.getQuantity(), 200)
        self.assertEquals(cell1.getPrice(), 0.1)
724
        cell2 = paysheet_line.getCell('contribution_share/employer',
725 726 727
            'salary_range/france/slice_200_to_400')
        self.assertEquals(cell2.getQuantity(), 200)
        self.assertEquals(cell2.getPrice(), 0.2)
728
        cell3 = paysheet_line.getCell('contribution_share/employee',
729 730 731
            'salary_range/france/slice_600_to_800')
        self.assertEquals(cell3.getQuantity(), 200)
        self.assertEquals(cell3.getPrice(), 0.3)
732
        cell4 = paysheet_line.getCell('contribution_share/employer',
733 734 735 736 737 738 739 740
            'salary_range/france/slice_600_to_800')
        self.assertEquals(cell4.getQuantity(), 200)
        self.assertEquals(cell4.getPrice(), 0.4)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

741
  def stepCheckPaysheetLineAmountsAfterUpdateWithLinesWithSameResource(self,
742
      sequence=None, **kw):
Fabien Morin's avatar
Fabien Morin committed
743 744 745 746 747 748 749 750
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    for paysheet_line in paysheet_line_list:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
        if len(paysheet_line.contentValues(portal_type='Pay Sheet Cell')) == 6:
          # there is two lines with the same resource, one with slice and one
          # without
751
          cell1 = paysheet_line.getCell('contribution_share/employee',
Fabien Morin's avatar
Fabien Morin committed
752 753 754
              'salary_range/france/slice_0_to_200')
          self.assertEquals(cell1.getQuantity(), 200)
          self.assertEquals(cell1.getPrice(), 0.1)
755
          cell2 = paysheet_line.getCell('contribution_share/employer',
Fabien Morin's avatar
Fabien Morin committed
756 757 758
              'salary_range/france/slice_0_to_200')
          self.assertEquals(cell2.getQuantity(), 200)
          self.assertEquals(cell2.getPrice(), 0.2)
759
          cell3 = paysheet_line.getCell('contribution_share/employee',
Fabien Morin's avatar
Fabien Morin committed
760 761 762
              'salary_range/france/slice_200_to_400')
          self.assertEquals(cell3.getQuantity(), 200)
          self.assertEquals(cell3.getPrice(), 0.3)
763
          cell4 = paysheet_line.getCell('contribution_share/employer',
Fabien Morin's avatar
Fabien Morin committed
764 765 766
              'salary_range/france/slice_200_to_400')
          self.assertEquals(cell4.getQuantity(), 200)
          self.assertEquals(cell4.getPrice(), 0.4)
767
          cell5 = paysheet_line.getCell('contribution_share/employee',
Fabien Morin's avatar
Fabien Morin committed
768 769 770
              'salary_range/france/slice_400_to_5000')
          self.assertEquals(cell5.getQuantity(), 2600)
          self.assertEquals(cell5.getPrice(), 0.5)
771
          cell6 = paysheet_line.getCell('contribution_share/employer',
Fabien Morin's avatar
Fabien Morin committed
772 773 774 775
              'salary_range/france/slice_400_to_5000')
          self.assertEquals(cell6.getQuantity(), 2600)
          self.assertEquals(cell6.getPrice(), 0.6)
        else:
776
          cell1 = paysheet_line.getCell('contribution_share/employee')
777 778
          self.assertEquals(cell1.getQuantity(), 3000)
          self.assertEquals(cell1.getPrice(), 0.1)
779
          cell2 = paysheet_line.getCell('contribution_share/employer')
780 781
          self.assertEquals(cell2.getQuantity(), 3000)
          self.assertEquals(cell2.getPrice(), 0.5)
Fabien Morin's avatar
Fabien Morin committed
782 783 784 785 786
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

787 788 789 790 791 792
  def stepCheckPaysheetLineAmountsWithSicknessInsuranceAndUrssaf(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
793
        cell1 = paysheet_line.getCell('contribution_share/employee')
794 795
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.1)
796
        cell2 = paysheet_line.getCell('contribution_share/employer')
797 798 799 800 801
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      elif service == 'Sickness Insurance':
802
        cell1 = paysheet_line.getCell('contribution_share/employee')
803 804
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.4)
805
        cell2 = paysheet_line.getCell('contribution_share/employer')
806 807 808 809 810 811 812 813 814 815 816
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.3)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineAmountsWithOldAgeInsuranceAndUrssaf(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
817
        cell1 = paysheet_line.getCell('contribution_share/employee')
818 819
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.1)
820
        cell2 = paysheet_line.getCell('contribution_share/employer')
821 822 823 824 825
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      elif service == 'Old Age Insurance':
826
        cell1 = paysheet_line.getCell('contribution_share/employee')
827 828
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.5)
829
        cell2 = paysheet_line.getCell('contribution_share/employer')
830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.8)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckUpdateAggregatedAmountListReturnNothing(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    model = sequence.get('model')
    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), 0)

  def stepCreateUrssafRoubaixOrganisation(self, sequence=None, **kw):
    node = self.createOrganisation()
    node.edit(title='Urssaf de Roubaix Tourcoing')
    sequence.edit(urssaf_roubaix = node)

  def stepModifyBusinessPathTradePhase(self, sequence=None, **kw):
    business_path = sequence.get('business_path')
    business_path.setTradePhaseList(['payroll/france/urssaf',
                                     'payroll/france/labour'])
853 854
    business_path.setSourceValue(sequence.get('urssaf_roubaix'))
    business_path.setSourceSectionValue(sequence.get('urssaf_roubaix'))
855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872
    business_path.setDeliveryBuilderList(('portal_deliveries/pay_sheet_builder',))
    sequence.edit(business_path=business_path)

  def stepModelSpecialiseBusinessProcess(self, sequence=None, **kw):
    model = sequence.get('model')
    business_process = sequence.get('business_process')
    model.setSpecialiseValueList(business_process)

  def stepCheckSourceSectionOnMovements(self, sequence=None, **kw):
    '''Check that the cell contain urssaf_roubaix as source section. This should
    be the case if getAggregatedAmountList from PaySheetModelLine is able to
    use Business Process to find the good source_section'''
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    urssaf_roubaix = sequence.get('urssaf_roubaix')
    for paysheet_line in paysheet_line_list:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
873
        cell1 = paysheet_line.getCell('contribution_share/employee')
874
        self.assertEquals(cell1.getSourceSectionValue(), urssaf_roubaix)
875
        cell2 = paysheet_line.getCell('contribution_share/employer')
876 877 878 879 880 881 882 883 884 885 886 887 888 889
        self.assertEquals(cell2.getSourceSectionValue(), urssaf_roubaix)
      elif service == 'Labour':
        pass
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepModelSetCategories(self, sequence=None, **kw):
    model = sequence.get('model')
    currency = sequence.get('price_currency')
    employer = sequence.get('employer')
    employee = sequence.get('employee')
    model.edit(\
        price_currency_value=currency,
        default_payment_condition_trade_date='custom',
890
        default_payment_condition_payment_date=DateTime(2009,05,25),
891 892 893 894 895 896 897 898 899
        work_time_annotation_line_quantity=151.67,
        work_time_annotation_line_quantity_unit='time/hours',
        )

  def stepPaysheetSetModelAndApplyIt(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    model = sequence.get('model')
    paysheet.setSpecialiseValue(model)
    paysheet.PaySheetTransaction_applyModel(force=1)
900

901 902 903 904 905 906 907 908 909 910
  def stepCheckCategoriesOnPaySheet(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    employer = sequence.get('employer')
    employee = sequence.get('employee')
    currency = sequence.get('price_currency')
    self.assertEquals(paysheet.getSourceSectionValue(), employee)
    self.assertEquals(paysheet.getDestinationSectionValue(), employer)
    self.assertEquals(paysheet.getPriceCurrencyValue(), currency)
    self.assertEquals(paysheet.getDefaultPaymentConditionTradeDate(), 'custom')
    self.assertEquals(paysheet.getDefaultPaymentConditionPaymentDate(),
911
        DateTime(2009,05,25))
912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051
    self.assertEquals(paysheet.getWorkTimeAnnotationLineQuantity(), 151.67)
    self.assertEquals(paysheet.getWorkTimeAnnotationLineQuantityUnit(),
      'time/hours')

  def stepCheckPaysheetContainNoAnnotationLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    self.assertEquals(len(paysheet.contentValues(portal_type=\
        'Annotation Line')), 0)

  def stepCheckPaysheetContainOneAnnotationLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    self.assertEquals(len(paysheet.contentValues(portal_type=\
        'Annotation Line')), 1)

  def stepCheckPaysheetContainNoPaymentCondition(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    self.assertEquals(len(paysheet.contentValues(portal_type=\
        'Payment Condition')), 0)

  def stepCheckPaysheetContainOnePaymentCondition(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    self.assertEquals(len(paysheet.contentValues(portal_type=\
        'Payment Condition')), 1)

  def stepCreateModelTree(self, sequence=None, **kw):
    '''
      Create three models inheriting from each other. Set slices values on a
      model.

      the inheritance tree look like this :

                                Employee Model
                                 /        \
                                /          \
                               /            \
                    Company Model         Second Company Alt
                         /
                        /
                       /
                Country Model
    '''
    model_employee = self.createModel()
    model_employee.edit(title='Employee Model', reference='model_employee',
        variation_settings_category_list='salary_range/france')
    model_company = self.createModel()
    model_company.edit(title='Company Model', reference='model_company',
        variation_settings_category_list='salary_range/france')
    model_company_alt = self.createModel()
    model_company_alt.edit(title='Second Company Model',
        reference='model_company_alt',
        variation_settings_category_list='salary_range/france')
    model_country = self.createModel()
    model_country.edit(title='Country Model', reference='model_country',
        variation_settings_category_list='salary_range/france')
    # add some cells in the models
    slice1 = model_employee.newCell('salary_range/france/slice_a',
                            portal_type='Pay Sheet Model Slice',
                            base_id='cell')
    slice1.setQuantityRangeMin(0)
    slice1.setQuantityRangeMax(1)

    slice2 = model_company.newCell('salary_range/france/slice_b',
                            portal_type='Pay Sheet Model Slice',
                            base_id='cell')
    slice2.setQuantityRangeMin(2)
    slice2.setQuantityRangeMax(3)

    slice3 = model_company_alt.newCell('salary_range/france/forfait',
                            portal_type='Pay Sheet Model Slice',
                            base_id='cell')
    slice3.setQuantityRangeMin(20)
    slice3.setQuantityRangeMax(30)

    slice4 = model_country.newCell('salary_range/france/slice_c',
                            portal_type='Pay Sheet Model Slice',
                            base_id='cell')
    slice4.setQuantityRangeMin(4)
    slice4.setQuantityRangeMax(5)

    # inherite from each other
    model_employee.setSpecialiseValueList((model_company, model_company_alt))
    model_company.setSpecialiseValue(model_country)

    sequence.edit(model_employee = model_employee,
                  model_company = model_company,
                  model_company_alt = model_company_alt,
                  model_country = model_country)

  def assertCell(self, model, salary_range, range_min, range_max):
    cell = model.getCell(salary_range)
    self.assertNotEqual(cell, None)
    self.assertEqual(cell.getQuantityRangeMin(), range_min)
    self.assertEqual(cell.getQuantityRangeMax(), range_max)

  def assertCellIsNone(self, model, salary_range):
    cell = model.getCell(salary_range)
    self.assertEqual(cell, None)

  def stepCheckgetCellResults(self, sequence=None, **kw):
    model_employee = sequence.get('model_employee')
    model_company = sequence.get('model_company')
    model_company_alt = sequence.get('model_company_alt')
    model_country = sequence.get('model_country')

    # check model_employee could access all cells
    self.assertCell(model_employee, 'salary_range/france/slice_a', 0, 1)
    self.assertCell(model_employee, 'salary_range/france/slice_b', 2, 3)
    self.assertCell(model_employee, 'salary_range/france/forfait', 20, 30)
    self.assertCell(model_employee, 'salary_range/france/slice_c', 4, 5)

    # check model_company could access just it's own cell
    # and this of the country model
    self.assertCellIsNone(model_company, 'salary_range/france/slice_a')
    self.assertCell(model_company, 'salary_range/france/slice_b', 2, 3)
    self.assertCellIsNone(model_company, 'salary_range/france/forfait')
    self.assertCell(model_company, 'salary_range/france/slice_c', 4, 5)

    # model_company_alt could access just it's own cell
    self.assertCellIsNone(model_company_alt, 'salary_range/france/slice_a')
    self.assertCellIsNone(model_company_alt, 'salary_range/france/slice_b')
    self.assertCell(model_company_alt, 'salary_range/france/forfait', 20, 30)
    self.assertCellIsNone(model_company_alt, 'salary_range/france/slice_c')

    # check model_country could access just it's own cell
    self.assertCellIsNone(model_country, 'salary_range/france/slice_a')
    self.assertCellIsNone(model_country, 'salary_range/france/slice_b')
    self.assertCellIsNone(model_country, 'salary_range/france/forfait')
    self.assertCell(model_country, 'salary_range/france/slice_c', 4, 5)

  def stepModelCreateIntermediateModelLine(self, sequence=None, **kw):
    '''
      create an intermediate_line wich contribute to tax and applied to
      base_salary
    '''
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='intermediate line',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
                    reference='intermediate_line',
1052 1053
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
1054 1055
                    base_contribution_list=['base_amount/payroll/base/income_tax'],
                    base_application_list=['base_amount/payroll/base/contribution'],
1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068
                    create_line=False,)
    sequence.edit(intermediate_model_line = model_line)

  def stepModelCreateAppliedOnTaxModelLine(self, sequence=None, **kw):
    '''
      create a model line applied on tax
    '''
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='line applied on intermediate line',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('urssaf_service'),
                    reference='line_applied_on_intermediate_line',
1069 1070
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
1071 1072
                    base_contribution_list=['base_amount/payroll/report/salary/net'],
                    base_application_list=['base_amount/payroll/base/income_tax'])
1073 1074 1075 1076 1077
    sequence.edit(model_line_applied_on_tax = model_line)

  def stepIntermediateModelLineCreateMovements(self, sequence=None,
      **kw):
    model_line = sequence.get('intermediate_model_line')
1078
    cell1 = model_line.newCell('contribution_share/employee',
1079 1080 1081
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1082 1083
    cell1.edit(price=0.2, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
1084 1085 1086
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1087
    cell2.edit(price=0.2, contribution_share='employer')
1088 1089 1090

  def stepAppliedOnTaxModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('model_line_applied_on_tax')
1091
    cell1 = model_line.newCell('contribution_share/employee',
1092 1093 1094
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1095 1096
    cell1.edit(price=0.1, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
1097 1098 1099
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1100
    cell2.edit(price=0.5, contribution_share='employer')
1101 1102 1103 1104 1105 1106 1107 1108

  def stepModelCreateOldAgeInsuranceModelLine(self, sequence=None, **kw):
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='Old Age Insurance',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('old_age_insurance_service'),
                    reference='old_age_insurance',
1109 1110
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
1111 1112
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
1113 1114 1115 1116
    sequence.edit(old_age_insurance = model_line)

  def stepOldAgeInsuranceModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('old_age_insurance')
1117
    cell1 = model_line.newCell('contribution_share/employee',
1118 1119 1120
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1121 1122
    cell1.edit(price=0.5, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
1123 1124 1125
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1126
    cell2.edit(price=0.8, contribution_share='employer')
1127 1128 1129 1130 1131 1132 1133 1134

  def stepModelCreateSicknessInsuranceModelLine(self, sequence=None, **kw):
    model = sequence.get('model')
    model_line = self.createModelLine(model)
    model_line.edit(title='Sickness Insurance',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('sickness_insurance_service'),
                    reference='sickness_insurance',
1135 1136
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
1137 1138
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
1139 1140 1141 1142
    sequence.edit(sickness_insurance = model_line)

  def stepSicknessInsuranceModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('sickness_insurance')
1143
    cell1 = model_line.newCell('contribution_share/employee',
1144 1145 1146
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1147 1148
    cell1.edit(price=0.4, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
1149 1150 1151
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1152
    cell2.edit(price=0.3, contribution_share='employer')
1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166

  def stepCheckPaysheetIntermediateLines(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')

    # paysheet should contain only two lines (labour and urssaf, but not
    # intermediate urssaf
    self.assertEquals(len(paysheet.contentValues(portal_type=\
        'Pay Sheet Line')), 2)

    # check amounts
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    for paysheet_line in paysheet_line_list:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
1167
        cell1 = paysheet_line.getCell('contribution_share/employee')
1168 1169 1170
        self.assertEquals(cell1.getQuantity(), 600) # here it's 600 of tax
                                  # because of the intermediate line (3000*0.2)
        self.assertEquals(cell1.getPrice(), 0.1)
1171
        cell2 = paysheet_line.getCell('contribution_share/employer')
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186
        self.assertEquals(cell2.getQuantity(), 600) # here it's 600 of tax
                                  # because of the intermediate line (3000*0.2)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepPaysheetCreateModelLine(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    model_line = self.createModelLine(paysheet)
    model_line.edit(title='model line in the paysheet',
                    trade_phase='payroll/france/urssaf',
                    resource_value=sequence.get('old_age_insurance_service'),
                    reference='model_line_in_the_payesheet',
1187 1188
                    variation_category_list=['contribution_share/employee',
                                             'contribution_share/employer'],
1189 1190
                    base_application_list=[ 'base_amount/payroll/base/contribution'],
                    base_contribution_list=['base_amount/payroll/base/income_tax'])
1191 1192 1193 1194
    sequence.edit(model_line_on_paysheet = model_line)

  def stepPaysheetModelLineCreateMovements(self, sequence=None, **kw):
    model_line = sequence.get('model_line_on_paysheet')
1195
    cell1 = model_line.newCell('contribution_share/employee',
1196 1197 1198
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1199 1200
    cell1.edit(price=0.5, contribution_share='employee')
    cell2 = model_line.newCell('contribution_share/employer',
1201 1202 1203
        portal_type='Pay Sheet Model Cell',
        base_id='movement',
        mapped_value_property_list=('quantity', 'price'))
1204
    cell2.edit(price=0.8, contribution_share='employer')
1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229

  def stepCheckUpdateAggregatedAmountListReturnWithModelLineOnPaysheet(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    self.checkUpdateAggregatedAmountListReturn(model, paysheet, 0, 4)

  def stepCheckPaysheetLineAreCreatedWithModelLineOnPaysheet(self,
      sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    paysheet_line_list = paysheet.contentValues(portal_type='Pay Sheet Line')
    self.assertEqual(len(paysheet_line_list), 3)
    self.assertEqual(len(paysheet.getMovementList(portal_type=\
        'Pay Sheet Cell')), 4) # 2 from the urssaf paysheet line
                               # 2 from the line create with the paysheet model
                               # line
    self.assertEqual(len(paysheet.contentValues(portal_type=\
        'Pay Sheet Model Line')), 1)

  def stepCheckPaysheetLineFromModelLineAmounts(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
1230
        cell1 = paysheet_line.getCell('contribution_share/employee')
1231 1232
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.1)
1233
        cell2 = paysheet_line.getCell('contribution_share/employer')
1234 1235 1236 1237 1238
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.5)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      elif service == 'Old Age Insurance':
1239
        cell1 = paysheet_line.getCell('contribution_share/employee')
1240 1241
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.5)
1242
        cell2 = paysheet_line.getCell('contribution_share/employer')
1243 1244 1245 1246 1247 1248 1249 1250
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.8)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepModelModifyUrssafModelLine(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line')
    # modify price on movements :
1251
    cell_1 = model_line.getCell('contribution_share/employee',
1252 1253 1254
        base_id='movement')
    self.assertNotEquals(cell_1, None)
    cell_1.edit(price=0.2)
1255
    cell_2 = model_line.getCell('contribution_share/employer',
1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270
        base_id='movement')
    self.assertNotEquals(cell_2, None)
    cell_2.edit(price=0.6)

  def stepModelDelUrssafModelLine(self, sequence=None, **kw):
    model_line = sequence.get('urssaf_model_line')
    model = sequence.get('model')
    model.manage_delObjects(model_line.getId())

  def stepCheckPaysheetLineNewAmountsAfterUpdate(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
1271
        cell1 = paysheet_line.getCell('contribution_share/employee')
1272 1273
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.2)
1274
        cell2 = paysheet_line.getCell('contribution_share/employer')
1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.6)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetLineLabourAmountOnly(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetModelLineOverLoadAmounts(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:
      service = paysheet_line.getResourceTitle()
      if service == 'Urssaf':
1298
        cell1 = paysheet_line.getCell('contribution_share/employee')
1299 1300
        self.assertEquals(cell1.getQuantity(), 3000)
        self.assertEquals(cell1.getPrice(), 0.3)
1301
        cell2 = paysheet_line.getCell('contribution_share/employer')
1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429
        self.assertEquals(cell2.getQuantity(), 3000)
        self.assertEquals(cell2.getPrice(), 0.7)
      elif service == 'Labour':
        self.assertEqual(paysheet_line.getTotalPrice(), 3000.0)
      else:
        self.fail("Unknown service for line %s" % paysheet_line.getTitle())

  def stepCheckPaysheetConsistency(self, sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    self.assertEquals([], paysheet.checkConsistency())

  def stepCheckModelConsistency(self, sequence=None, **kw):
    model = sequence.get('model')
    self.assertEquals([], model.checkConsistency())

  def stepCheckServiceConsistency(self, sequence=None, **kw):
    service = sequence.get('urssaf_service')
    self.assertEquals([], service.checkConsistency())

  def stepAddPredicateOnOldAgeInsuranceModelLineForSinglePerson(self,
      sequence=None, **kw):
    model_line = sequence.get('old_age_insurance')
    model_line.setMembershipCriterionBaseCategoryList(\
        ['source_marital_status'])
    model_line.setMembershipCriterionCategoryList(\
        ['source_marital_status/marital_status/single'])

  def stepAddPredicateOnSicknessInsuranceModelLineForMarriedPerson(self,
      sequence=None, **kw):
    model_line = sequence.get('sickness_insurance')
    model_line.setMembershipCriterionBaseCategoryList(\
        ['source_marital_status'])
    model_line.setMembershipCriterionCategoryList(\
        ['source_marital_status/marital_status/married'])

  def stepSetMaritalStatusMarriedOnEmployee(self, sequence=None, **kw):
    employee = sequence.get('employee')
    employee.setMaritalStatus('married')

  def stepSetMaritalStatusSingleOnEmployee(self, sequence=None, **kw):
    employee = sequence.get('employee')
    employee.setMaritalStatus('single')

  def stepModelTreeAddAnnotationLines(self, sequence=None, **kw):
    model_employee = sequence.get('model_employee')
    model_employee.newContent(id='over_time_duration',
                              title='Over time duration',
                              portal_type='Annotation Line',
                              reference='over_time_duration',
                              quantity=1)
    model_company = sequence.get('model_company')
    model_company.newContent(id='worked_time_duration',
                             title='Worked time duration',
                             portal_type='Annotation Line',
                             reference='worked_time_duration',
                             quantity=2)
    model_company_alt = sequence.get('model_company_alt')
    model_company_alt.newContent(id='social_insurance',
                                 title='Social insurance',
                                 portal_type='Annotation Line',
                                 reference='social_insurance',
                                 quantity=3)
    model_country = sequence.get('model_country')
    model_country.newContent(id='social_insurance',
                             title='Social insurance',
                             portal_type='Annotation Line',
                             reference='social_insurance',
                             quantity=4)

  def stepCheckInheritanceModelReferenceDict(self, sequence=None, **kw):
    model_employee = sequence.get('model_employee')
    model_employee_url = model_employee.getRelativeUrl()
    model_company_url = sequence.get('model_company').getRelativeUrl()
    model_company_alt_url = sequence.get('model_company_alt').getRelativeUrl()
    model_country_url = sequence.get('model_country').getRelativeUrl()
    
    model_reference_dict = model_employee.getInheritanceReferenceDict(\
        portal_type_list=('Annotation Line',))
    self.assertEquals(len(model_reference_dict), 3) # there is 4 model but two
                                                    # models have the same
                                                    # reference.
    self.assertEquals(model_reference_dict.has_key(model_employee_url), True)
    self.assertEquals(model_reference_dict[model_employee_url],
        ['over_time_duration'])
    self.assertEquals(model_reference_dict.has_key(model_company_url), True)
    self.assertEquals(model_reference_dict[model_company_url],
        ['worked_time_duration'])
    self.assertEquals(model_reference_dict.has_key(model_company_alt_url), True)
    self.assertEquals(model_reference_dict[model_company_alt_url],
        ['social_insurance'])
    self.assertNotEquals(model_reference_dict.has_key(model_country_url), True)
    
    # check the object list :
    paysheet = self.createPaysheet()
    paysheet.setSpecialiseValue(model_employee)
    object_list = paysheet.getInheritedObjectValueList(portal_type_list=\
        ('Annotation Line',))
    self.assertEquals(len(object_list), 3) # one line have the same reference
                                           # than another, so each reference
                                           # should be prensent only one time
                                           # in the list
    over_time_duration = paysheet.getAnnotationLineFromReference(\
        'over_time_duration')
    self.assertNotEquals(over_time_duration, None)
    over_time_duration.getQuantity(1)
    worked_time_duration = paysheet.getAnnotationLineFromReference(\
        'worked_time_duration')
    self.assertNotEquals(worked_time_duration, None)
    worked_time_duration.getQuantity(2)
    social_insurance = paysheet.getAnnotationLineFromReference(\
        'social_insurance')
    self.assertNotEquals(social_insurance, None)
    social_insurance.getQuantity(3)

  def stepCheckPaySheetTransaction_getMovementListReturn(self,
      sequence=None, **kw):
    paysheet = sequence.get('paysheet')
    # when pay sheet has no line, the script returns an empty list
    self.assertEquals(len(paysheet.PaySheetTransaction_getMovementList()), 0)

    # we add a line, then it is returned in the list
    line = self.createPaysheetLine(paysheet)
    self.assertEquals(len(paysheet.PaySheetTransaction_getMovementList()), 1)

    # if the line has cells with different tax categories, new properties are
    # added to this line.
    urssaf_service = sequence.get('urssaf_service')
    line.setResourceValue(urssaf_service)
1430 1431 1432
    line.setVariationCategoryList(['contribution_share/employee',
                                   'contribution_share/employer'])
    cell0 = line.newCell('contribution_share/employee',
1433 1434
                         portal_type='Pay Sheet Cell', base_id='movement')
    cell0.setMappedValuePropertyList(['quantity', 'price'])
1435
    cell0.setVariationCategoryList(('contribution_share/employee',))
1436 1437
    cell0.setPrice(2)
    cell0.setQuantity(3)
1438
    cell1 = line.newCell('contribution_share/employer',
1439 1440
                         portal_type='Pay Sheet Cell', base_id='movement')
    cell1.setMappedValuePropertyList(['quantity', 'price'])
1441
    cell1.setVariationCategoryList(('contribution_share/employer',))
1442 1443 1444 1445 1446 1447
    cell1.setPrice(4)
    cell1.setQuantity(5)

    movement_list = paysheet.PaySheetTransaction_getMovementList()
    self.assertEquals(1, len(movement_list))
    movement = movement_list[0]
1448 1449 1450 1451 1452 1453
    self.assertEquals(2, movement.employee_price)
    self.assertEquals(3, movement.employee_quantity)
    self.assertEquals(2*3, movement.employee_total_price)
    self.assertEquals(4, movement.employer_price)
    self.assertEquals(5, movement.employer_quantity)
    self.assertEquals(4*5, movement.employer_total_price)
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477

  def stepCheckModelWithoutRefValidity(self, sequence=None, **kw):
    '''
    If no reference are defined on a model, the behavior is that this model is
    always valid. So check a Pay Sheet Transaction Line is created after
    calling the calculation script
    '''
    eur = sequence.get('currency')
    labour = sequence.get('labour_service_output')

    model_without_ref = self.getPortalObject().paysheet_model_module.newContent( \
        specialise_value=sequence.get('business_process'),
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        effective_date=DateTime(2009, 1, 1),
        expiration_date=DateTime(2009, 12, 31))
    model_without_ref.setPriceCurrencyValue(eur)


    model_line_1 = self.createModelLine(model_without_ref)
    model_line_1.edit(
        trade_phase='payroll/france/labour',
        reference='model_without_ref',
        resource_value=labour,
1478 1479
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1480 1481 1482 1483 1484
        quantity=10000)
    
    # create the paysheet
    paysheet = self.createPaysheet()
    paysheet.edit(specialise_value=model_without_ref,
1485 1486
                  start_date=DateTime(2009, 1, 1),
                  stop_date=DateTime(2009, 1, 31),
1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
                  price_currency_value=eur)
    paysheet.PaySheetTransaction_applyModel()
    self.stepTic()

    portal_type_list = ['Pay Sheet Model Line',]

    # if no reference, we don't care about dates
    sub_object_list = paysheet.getInheritedObjectValueList(portal_type_list)
    
    self.assertEquals(len(paysheet.contentValues(\
        portal_type='Pay Sheet Line')), 0)
    # calculate the pay sheet
    paysheet.applyTransformation()
    self.stepTic()
    self.assertEquals(len(paysheet.contentValues(
        portal_type='Pay Sheet Line')), 1)
    # check values on the paysheet
    self.assertEquals(paysheet.contentValues()[0].getTotalPrice(), 10000)

  def stepCheckModelWithoutDateValidity(self, sequence=None, **kw):
    '''
    If no date are defined on a model, the behavior is that this model
1509
    is always valid.
1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524
    '''
    eur = sequence.get('currency')
    labour = sequence.get('labour_service_output')

    model_without_date = self.getPortalObject().paysheet_model_module.newContent( \
        specialise_value=sequence.get('business_process'),
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_without_date')

    model_line_2 = self.createModelLine(model_without_date)
    model_line_2.edit(
        trade_phase='payroll/france/labour',
        reference='model_without_date',
        resource_value=labour,
1525 1526
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1527 1528
        quantity=10000)

1529 1530 1531
    # create a paysheet without date
    paysheet_without_date = self.createPaysheet()
    paysheet_without_date.edit(specialise_value=model_without_date,
1532
                  price_currency_value=eur)
1533
    paysheet_without_date.PaySheetTransaction_applyModel()
1534 1535 1536 1537
    self.stepTic()

    portal_type_list = ['Pay Sheet Model Line',]

1538 1539
    # check the paysheet contail no lines before calculation
    self.assertEquals(len(paysheet_without_date.contentValues(\
1540 1541
        portal_type='Pay Sheet Line')), 0)
    # calculate the pay sheet
1542
    paysheet_without_date.applyTransformation()
1543
    self.stepTic()
1544
    self.assertEquals(len(paysheet_without_date.contentValues(\
1545
        portal_type='Pay Sheet Line')), 1)
1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560
    # check values on the paysheet_without_date
    self.assertEquals(paysheet_without_date.contentValues()[0].getTotalPrice(),
        10000)

    # create a paysheet with dates
    paysheet_with_date = self.createPaysheet()
    paysheet_with_date.edit(specialise_value=model_without_date,
                  start_date=DateTime(2009, 1, 1),
                  stop_date=DateTime(2009, 1, 31),
                  price_currency_value=eur)
    paysheet_with_date.PaySheetTransaction_applyModel()
    self.stepTic()

    portal_type_list = ['Pay Sheet Model Line',]

1561
    # check the paysheet contains no lines before calculation
1562 1563 1564 1565 1566
    self.assertEquals(len(paysheet_with_date.contentValues(\
        portal_type='Pay Sheet Line')), 0)
    # calculate the pay sheet
    paysheet_with_date.applyTransformation()
    self.stepTic()
1567
    # after calculation, paysheet contains one line, because the model applies.
1568
    self.assertEquals(len(paysheet_with_date.contentValues(\
1569 1570 1571
        portal_type='Pay Sheet Line')), 1)
    self.assertEquals(paysheet_without_date.contentValues()[0].getTotalPrice(),
        10000)
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600

  def stepCheckModelDateValidity(self, sequence=None, **kw):
    '''
    check that model effective_date and expiration_date are take into account.
    '''
    eur = sequence.get('currency')
    labour = sequence.get('labour_service_output')

    model_1 = self.getPortalObject().paysheet_model_module.newContent( \
        specialise_value=sequence.get('business_process'),
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 1, 1),
        expiration_date=DateTime(2009, 06, 30))
    
    model_2 = self.getPortalObject().paysheet_model_module.newContent( \
        specialise_value=sequence.get('business_process'),
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31))

    model_line_3 = self.createModelLine(model_1)
    model_line_3.edit(
        trade_phase='payroll/france/labour',
        reference='check_model_date_validity_1',
        resource_value=labour,
1601 1602
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1603 1604 1605 1606 1607 1608 1609 1610
        quantity=20000,
        price=1)

    model_line_4 = self.createModelLine(model_2)
    model_line_4.edit(
        trade_phase='payroll/france/labour',
        reference='check_model_date_validity_2',
        resource_value=labour,
1611 1612
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673
        quantity=30000,
        price=1)
    self.stepTic()

    # create the paysheet
    paysheet = self.portal.accounting_module.newContent(
                              portal_type='Pay Sheet Transaction',
                              specialise_value=model_1,
                              start_date=DateTime(2009, 07, 1),
                              stop_date=DateTime(2009, 07, 31),
                              price_currency_value=eur)
    paysheet.PaySheetTransaction_applyModel()
    self.stepTic()

    self.assertEquals(len(paysheet.contentValues(\
        portal_type='Pay Sheet Line')), 0)
    # calculate the pay sheet
    paysheet.applyTransformation()
    self.stepTic()
    self.assertEquals(len(paysheet.contentValues(\
        portal_type='Pay Sheet Line')), 1)
    # check values on the paysheet, if it's model_2, the total_price 
    # should be 30000.
    self.assertEquals(paysheet.contentValues()[0].getTotalPrice(), 30000)

  def stepCheckModelVersioning(self, sequence=None, **kw):
    '''
    check that latest version is used in case of more thant one model is matching
    using dates
    '''
    eur = sequence.get('currency')

    # define a non effective model
    model_1 = self.getPortalObject().paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 01, 1),
        expiration_date=DateTime(2009, 02, 28),
        specialise_value=sequence.get('business_process'))

    # define two models with same references and same dates
    # but different version number
    model_2 = self.getPortalObject().paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='002',
        specialise_value=sequence.get('business_process'))

    model_3 = self.getPortalObject().paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        variation_settings_category_list=['salary_range/france',],
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='001',
        specialise_value=sequence.get('business_process'))
    self.stepTic()
1674

1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687
    # create the paysheet
    paysheet = self.portal.accounting_module.newContent(
                              portal_type='Pay Sheet Transaction',
                              specialise_value=model_1,
                              start_date=DateTime(2009, 07, 1),
                              stop_date=DateTime(2009, 07, 31),
                              price_currency_value=eur)
    paysheet.PaySheetTransaction_applyModel()
    self.stepTic()

    # the effective model should be model_2 because of the effective date and
    # version number
    specialise_value = paysheet.getSpecialiseValue()
1688 1689 1690 1691
    effective_model = specialise_value.getEffectiveModel(\
        start_date=paysheet.getStartDate(),
        stop_date=paysheet.getStopDate())
    self.assertEquals(effective_model, model_2)
1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706

    # check the effective model tree list
    effective_value_list = specialise_value.findEffectiveSpecialiseValueList(\
        context=specialise_value,
        start_date=paysheet.getStartDate(),
        stop_date=paysheet.getStopDate())
    self.assertEquals(effective_value_list, [model_2])

  def stepCreateModelLineZeroPrice(self, sequence=None, **kw):
    '''Test the creation of lines when the price is set to zero: the line should
    not be created.'''
    model = sequence.get('model')
    labour = sequence.get('labour_service_output')
    line = model.newContent(
          id='line',
1707
          reference='zero_price_line',
1708 1709
          portal_type='Pay Sheet Model Line',
          resource_value=labour,
1710 1711
          base_contribution_list=['base_amount/payroll/base/contribution',
            'base_amount/payroll/report/salary/gross'],
1712 1713 1714 1715 1716
          quantity=5,
          price=0)

  def stepComplexModelInheritanceScheme(self, sequence=None, **kw):
    '''
Fabien Morin's avatar
Fabien Morin committed
1717
    check inheritance and effective model with a more complex inheritance tree
1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748

    # the inheritance tree look like this :

                                    model_employee
(model_1, 01/01/09, 28/02/09) ; (model_2, 01/07/09, 31/12/09) ; (model_3, 01/07/09, 31/12/09)
                                           |
                                           |
                                           |
                                     model_company
             (model_4, 01/07/09, 31/12/09), (model_5, 01/07/09, 31/12/09)
                                           |
                                           |
                                           |
                                     model_company
             (model_6, 01/07/09, 31/12/09), (model_7, 01/07/09, 31/12/09)
    '''

    eur = sequence.get('currency')
    labour = sequence.get('labour_service_output')
    paysheet_model_module = self.getPortalObject().paysheet_model_module

    # define a non effective model
    model_1 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 01, 1),
        expiration_date=DateTime(2009, 02, 28))
    model_line_1 = self.createModelLine(model_1)
    model_line_1.edit(
        resource_value=labour,
1749 1750
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
        quantity=10000)

    # define two models with same references and same dates
    # but different version number
    model_2 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='002')
    model_line_2 = self.createModelLine(model_2)
    model_line_2.edit(
        resource_value=labour,
1765 1766
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778
        quantity=20000)

    model_3 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='001')
    model_line_3 = self.createModelLine(model_3)
    model_line_3.edit(
        resource_value=labour,
1779 1780
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794
        quantity=30000)

    # define two models with same references and same dates
    # but different version number
    model_4 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_level_2_2009',
        effective_date=DateTime(2009, 01, 1),
        expiration_date=DateTime(2009, 06, 30),
        version='002')
    model_line_4 = self.createModelLine(model_4)
    model_line_4.edit(
        resource_value=labour,
1795 1796
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808
        quantity=40000)

    model_5 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_level_2_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='001')
    model_line_5 = self.createModelLine(model_5)
    model_line_5.edit(
        resource_value=labour,
1809 1810
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824
        quantity=50000)

    # third level : define two models with same references and same dates
    # but different version number
    model_6 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_level_3_2009',
        effective_date=DateTime(2009, 01, 1),
        expiration_date=DateTime(2009, 06, 30),
        version='002')
    model_line_6 = self.createModelLine(model_6)
    model_line_6.edit(
        resource_value=labour,
1825 1826
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838
        quantity=60000)

    model_7 = paysheet_model_module.newContent( \
        portal_type='Pay Sheet Model',
        specialise_value=sequence.get('business_process'),
        reference='fabien_model_level_3_2009',
        effective_date=DateTime(2009, 07, 1),
        expiration_date=DateTime(2009, 12, 31),
        version='001')
    model_line_7 = self.createModelLine(model_7)
    model_line_7.edit(
        resource_value=labour,
1839 1840
        base_contribution_list=['base_amount/payroll/base/contribution',
          'base_amount/payroll/report/salary/gross'],
1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881
        quantity=70000)

    self.stepTic()

    # create the paysheet
    paysheet = self.portal.accounting_module.newContent(
                              portal_type='Pay Sheet Transaction',
                              specialise_value=model_1,
                              start_date=DateTime(2009, 07, 1),
                              stop_date=DateTime(2009, 07, 31),
                              price_currency_value=eur)
    specialise_value = paysheet.getSpecialiseValue()

    # design some heritance trees, and check them:
    model_1.setSpecialiseValue(model_4)
    model_4.setSpecialiseValue(model_6)
    paysheet.PaySheetTransaction_applyModel()
    self.assertEquals(specialise_value.findSpecialiseValueList(context=paysheet),
        [model_1, model_4, model_6])
    self.assertEquals(specialise_value.findEffectiveSpecialiseValueList(\
        context=paysheet, start_date=paysheet.getStartDate(),
        stop_date=paysheet.getStopDate()), [model_2,])

    model_1.setSpecialiseValue(None)
    model_2.setSpecialiseValue(model_5)
    model_5.setSpecialiseValue(model_6)
    paysheet.PaySheetTransaction_applyModel()
    self.assertEquals(specialise_value.findSpecialiseValueList(context=paysheet),
        [model_1,])
    self.assertEquals(specialise_value.findEffectiveSpecialiseValueList(\
        context=paysheet, start_date=paysheet.getStartDate(),
        stop_date=paysheet.getStopDate()), [model_2, model_5, model_7])

    model_3.setSpecialiseValue(model_5)
    model_5.setSpecialiseValue(model_6)
    paysheet.PaySheetTransaction_applyModel()
    self.assertEquals(specialise_value.findSpecialiseValueList(context=paysheet),
        [model_1,])
    self.assertEquals(specialise_value.findEffectiveSpecialiseValueList(\
        context=paysheet, start_date=paysheet.getStartDate(),
        stop_date=paysheet.getStopDate()), [model_2, model_5, model_7])
1882

Fabien Morin's avatar
Fabien Morin committed
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914
  def stepCheckPropertiesAreCopiedFromModelLineToPaySheetLine(self,
      sequence=None, **kw):
    model = sequence.get('model')
    paysheet = sequence.get('paysheet')
    property_list = ('title', 'description', 'int_index')
    for model_line in model.contentValues(portal_type='Pay Sheet Model Line'):
      model_line_resource = model_line.getResource()
      line_found = False
      for paysheet_line in paysheet.contentValues(portal_type='Pay Sheet Line'):
        if paysheet_line.getResource() == model_line_resource:
          line_found = True
          for prop in property_list:
            prop_from_model_line = getattr(model_line, prop, None)
            # check a value is set on the model line
            self.assertNotEquals(prop_from_model_line, None)
            prop_from_paysheet_line = getattr(paysheet_line, prop, None)
            # check the property is the same on model_line and paysheet_line
            self.assertEquals(prop_from_model_line, prop_from_paysheet_line)
          break

      # check that for each model line, we foud a corresponding paysheet_line
      self.assertEquals(line_found, True)

  def stepSetProperiesOnModelLines(self, sequence=None, **kw):
    model = sequence.get('model')
    index = 0
    for model_line in model.contentValues(portal_type='Pay Sheet Model Line'):
      model_line.setTitle('Model line title %s' % index)
      model_line.setDescription('Model line description %s' % index)
      model_line.setIntIndex(index)
      index += 1

1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926
  def checkPrecisionOfListBox(self, report_section, precision):
    here = report_section.getObject(self.portal)
    report_section.pushReport(self.portal)
    form = getattr(here, report_section.getFormId())
    self.portal.REQUEST['here'] = here
    if form.has_field('listbox'):
      result = form.listbox.get_value('default',
                                      render_format='list',
                                      REQUEST=self.portal.REQUEST)
      self.assertEquals(precision, self.portal.REQUEST.get('precision'))
    report_section.popReport(self.portal)

1927 1928
class TestPayroll(TestPayrollMixin):

1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944
  def test_modelGetCell(self):
    '''
      Model objects have a overload method called getCell. This method first
      call the XMLMatrix.getCell and if the cell is not found, call
      getCell method in all it's inherited model until the cell is found or
      the cell have been searched on all inherited models.

      TODO : Currently, the method use a Depth-First Search algorithm, it will
      be better to use Breadth-First Search one.
      more about this on :
        - http://en.wikipedia.org/wiki/Breadth-first_search
        - http://en.wikipedia.org/wiki/Depth-first_search
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateModelTree
1945
               Tic
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963
               CheckgetCellResults
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_applyModelSetCategories(self):
    '''
      check that when the model is set on the Pay Sheet Transaction, properties
      like source, destination, currency, ... and sub-object like
      annotation_line are copied from the model to the Pay Sheet Transaction
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreateBasicModel
1964
               Tic
1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984
               CreatePriceCurrency
               ModelSetCategories
               CreateBasicPaysheet
               PaysheetSetModelAndApplyIt
               CheckCategoriesOnPaySheet
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_applyModelTwice(self):
    '''
      apply model twice does not copy subdocument twice
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreateBasicModel
1985
               Tic
1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044
               CreatePriceCurrency
               ModelSetCategories
               CreateBasicPaysheet
               CheckPaysheetContainNoAnnotationLine
               CheckPaysheetContainNoPaymentCondition
               PaysheetSetModelAndApplyIt
               CheckPaysheetContainOneAnnotationLine
               CheckPaysheetContainOnePaymentCondition
               PaysheetSetModelAndApplyIt
               CheckPaysheetContainOneAnnotationLine
               CheckPaysheetContainOnePaymentCondition
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_checkConsistency(self):
    '''
      minimal test for checkConsistency on a Pay Sheet Transaction and it's
      subdocuments (may have to be updated when we'll add more constraints).
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CheckPaysheetConsistency
               CheckModelConsistency
               CheckServiceConsistency
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_basicPaySheetCalculation(self):
    '''
      test applyTransformation method. It should create new movements
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmounts
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_intermediateLines(self):
    '''
      Intermediate lines are paysheet model lines usefull to calcul, but we
      don't want to have on paysheet. So a checkbox on paysheet model lines
      permit to create it or not (created by default)
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreateBasicModel
2045
               Tic
2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265
               ModelCreateIntermediateModelLine
               ModelCreateAppliedOnTaxModelLine
               IntermediateModelLineCreateMovements
               AppliedOnTaxModelLineCreateMovements
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
  """ + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING + """
               PaysheetApplyTransformation
               Tic
               CheckPaysheetIntermediateLines
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelLineInPaysheet(self):
    '''
      Put a Pay Sheet Model Line in Pay Sheet Transaction. This line will
      be like editable line
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CreateOldAgeInsuranaceService
               PaysheetCreateModelLine
               PaysheetModelLineCreateMovements
               CheckUpdateAggregatedAmountListReturnWithModelLineOnPaysheet
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedWithModelLineOnPaysheet
               CheckPaysheetLineFromModelLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_updateModifyMovements(self):
    '''
      Calculate the paySheet using a model, modify one value in the model and
      check that updateAggregatedAmount return nothing but modifed movements
      that need to be modified
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               ModelModifyUrssafModelLine
               CheckUpdateAggregatedAmountListReturnNothing
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineNewAmountsAfterUpdate
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineNewAmountsAfterUpdate
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_updateAddMovements(self):
    '''
      Calculate the paySheet using a model, add a model line in the model 
      and check that updateAggregatedAmount add the movements corresponding
      to this model_line
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               CreateSicknessInsuranceService
               ModelCreateSicknessInsuranceModelLine
               SicknessInsuranceModelLineCreateMovements
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingWith3Lines
               CheckPaysheetLineAmountsWithSicknessInsuranceAndUrssaf
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmountsWithSicknessInsuranceAndUrssaf
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_updateRemoveMovements(self):
    '''
      Calculate the paySheet using a model, delete a model line in the model 
      and check that updateAggregatedAmount remove the movements corresponding
      to this model_line
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               ModelDelUrssafModelLine
               CheckUpdateAggregatedAmountListReturnAfterRemoveLine
               PaysheetApplyTransformation
               Tic
               CheckThereIsOnlyOnePaysheetLine
               CheckPaysheetLineLabourAmountOnly
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineLabourAmountOnly
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelLineOverLoad(self):
    '''
      Check it's possible to overload a model line from the model tree by
      having a model line with the same reference in the paysheet.
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               PaysheetCreateUrssafModelLine
               PaysheetUrssafModelLineCreateMovements
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetModelLineOverLoadAmounts
               CheckUpdateAggregatedAmountListReturnNothing
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_sourceSectionIsSetOnMovements(self):
    '''
      check that after apply transformation, source section is set on movment
      (using Business Process)
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               PaysheetApplyTransformation
               Tic
               CheckSourceSectionOnMovements
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_sliceOnModelLine(self):
    '''
      It's possible to define some slices on model, and use it on model lines.
      Check that works and that after appy transformation, amounts are goods
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreateModelWithSlices
               Tic
               ModelCreateUrssafModelLineWithSlices
               Tic
               UrssafModelLineWithSlicesCreateMovements
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
  """ + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturnUsingSlices
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingSlices
               CheckPaysheetLineAmountsUsingSlices
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmountsUsingSlices
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_complexSliceOnModelLine(self):
    '''
      Check if there is only slice_200_to_400 (without previous
      slice_0_to_200), amount paid for this tax are correct.
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreateModelWithSlices
               Tic
               ModelCreateUrssafModelLineWithComplexSlices
               Tic
               UrssafModelLineWithComplexSlicesCreateMovements
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
  """ + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturnUsingComplexSlices
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingComplexSlices
               CheckPaysheetLineAmountsUsingComplexSlices
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmountsUsingComplexSlices
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelLineWithNonePrice(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.
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreatePriceCurrency
               CreateBasicModel
2266
               Tic
2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292
               ModelCreateUrssafModelLine
               UrssafModelLineCreateMovementsWithQuantityOnly
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
  """ + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING + """
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmountsWithQuantityOnly
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmountsWithQuantityOnly
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelLineWithZeroPrice(self):
    '''Test the creation of lines when the price is set to zero: the line should
    not be created.'''
    sequence_list = SequenceList()
    sequence_string = """
               CreateLabourOutputService
               CreateEmployer
               CreateEmployee
               CreatePriceCurrency
               CreateBasicModel
2293
               Tic
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345
               CreateModelLineZeroPrice
               CreateBasicPaysheet
  """ + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING + """
               PaysheetApplyTransformation
               Tic
               CheckNoPaysheetLineAreCreated
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_predicateOnModelLine(self):
    '''
      Check predicates can be used on model lines to select a line or not.
      1 - employee have married marital status so Sickness Insurance tax
          should be applied, and Old age insurance should not be
      2 - employee marital status is changed to single. So after re-apply 
          the transformation, Sickness Insurance tax sould not be
          applied (and it's movements should be removed) but Old age insurance
          should be applied (and two movements should be created).
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CreateOldAgeInsuranaceService
               ModelCreateOldAgeInsuranceModelLine
               OldAgeInsuranceModelLineCreateMovements
               AddPredicateOnOldAgeInsuranceModelLineForSinglePerson
               CreateSicknessInsuranceService
               ModelCreateSicknessInsuranceModelLine
               SicknessInsuranceModelLineCreateMovements
               AddPredicateOnSicknessInsuranceModelLineForMarriedPerson
               SetMaritalStatusMarriedOnEmployee
               CheckUpdateAggregatedAmountListReturnUsingPredicate
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingWith3Lines
               CheckPaysheetLineAmountsWithSicknessInsuranceAndUrssaf
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmountsWithSicknessInsuranceAndUrssaf
               SetMaritalStatusSingleOnEmployee
               CheckUpdateAggregatedAmountListReturnAfterChangePredicate
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingWith3Lines
               CheckPaysheetLineAmountsWithOldAgeInsuranceAndUrssaf
               CheckUpdateAggregatedAmountListReturnNothing
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_paySheetCalculationWithBonus(self):
    '''
      add one more line in the paysheet that will not be hour count and rate
2346
      (like the salary) but just a normal amount. Check applyTransformation
2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413
      method result. It should create new movements applied on the slary + the
      bonnus
    '''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               CreateBonusService
               PaysheetCreateBonusPaySheetLine
               PaysheetCreateBonusPaySheetLineMovements
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreatedUsingBonus
               CheckPaysheetLineWithBonusAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineWithBonusAmounts
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelSubObjectInheritance(self):
    '''
      check that a model can inherite some datas from another
      the ineritance rules are the following :
       - a DATA could be a model_line, annotation_line, ratio_line
       - a model_line, annotation_line and a ratio_line have a REFERENCE
       - a model can have some DATA's
       - a model can inherite from another, that's mean :
         o At the calculation step, each DATA of the parent model will be
           checked : the DATA with a REFERENCE that's already in the child
           model will not entered in the calcul. The other will.
         o This will be repeated on each parent model and on each parent of
           the parent model,... until there is no parent model to inherite
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateModelTree
               ModelTreeAddAnnotationLines
               CheckInheritanceModelReferenceDict
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_PaySheetTransaction_getMovementList(self):
    '''
      PaySheetTransaction_getMovementList is a script used by the listbox to
      display information about lines in the Paysheet. Just test the return of
      it.
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreateUrssafService
               CreateBasicPaysheet
               CheckPaySheetTransaction_getMovementListReturn
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_PayrollTaxesReport(self):
    currency_module = self.getCurrencyModule()
    if not hasattr(currency_module, 'EUR'):
      currency_module.newContent(
          portal_type = 'Currency',
          reference = "EUR", id = "EUR", base_unit_quantity=0.001 )
    eur = self.portal.currency_module.EUR
    service = self.portal.service_module.newContent(
                      portal_type='Service',
                      title='PS1',
2414
                      variation_base_category_list=('contribution_share',),
2415 2416
                      variation_category_list=('contribution_share/employee',
                                               'contribution_share/employer'))
2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448
    employer = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Employer',
                      price_currency_value=eur,
                      group_value=self.portal.portal_categories.group.demo_group)
    employee1 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee One',
                      career_reference='E1',
                      career_subordination_value=employer)
    employee2 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee Two',
                      career_reference='E2',
                      career_subordination_value=employer)
    provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Service Provider')
    other_provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Another Service Provider')
    ps1 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 1',
                      destination_section_value=employer,
                      source_section_value=employee1,
                      start_date=DateTime(2006, 1, 1),)
    line = ps1.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                # (destination is set by PaySheetTransaction.createPaySheetLine)
                   destination_value=employee1,
2449 2450 2451
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2452 2453 2454 2455
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2456 2457
    cell_employee.edit(price=-.50, quantity=2000, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
2458 2459 2460 2461
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2462
    cell_employer.edit(price=-.40, quantity=2000, contribution_share='employer')
2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474
    ps1.plan()

    ps2 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 2',
                      destination_section_value=employer,
                      source_section_value=employee2,
                      start_date=DateTime(2006, 1, 1),)
    line = ps2.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                   destination_value=employee2,
2475 2476 2477
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2478 2479 2480 2481
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2482 2483
    cell_employee.edit(price=-.50, quantity=3000, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
2484 2485 2486 2487
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2488
    cell_employer.edit(price=-.40, quantity=3000, contribution_share='employer')
2489 2490 2491 2492 2493

    other_line = ps2.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   destination_value=employee2,
                   source_section_value=other_provider,
2494 2495 2496
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = other_line.newCell('contribution_share/employee',
2497 2498 2499 2500
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2501 2502
    cell_employee.edit(price=-.46, quantity=2998, contribution_share='employee')
    cell_employer = other_line.newCell('contribution_share/employer',
2503 2504 2505 2506
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2507
    cell_employer.edit(price=-.42, quantity=2998, contribution_share='employer')
2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535
    self.stepTic()

    # AccountingTransactionModule_getPaySheetMovementMirrorSectionItemList is
    # used in the report dialog to display possible organisations.
    self.assertEquals(
        [('', ''),
         (other_provider.getTitle(), other_provider.getRelativeUrl()),
         (provider.getTitle(), provider.getRelativeUrl())],
        self.portal.accounting_module\
    .AccountingTransactionModule_getPaySheetMovementMirrorSectionItemList())

    # set request variables and render
    request_form = self.portal.REQUEST
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['simulation_state'] = ['draft', 'planned']
    request_form['resource'] = service.getRelativeUrl()
    request_form['mirror_section'] = provider.getRelativeUrl()

    report_section_list = self.getReportSectionList(
                             self.portal.accounting_module,
                             'AccountingTransactionModule_viewPaySheetLineReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))

Jérome Perrin's avatar
Jérome Perrin committed
2536 2537
    # base_unit_quantity for EUR is set to 0.001 in the created currencies, so the
    # precision is 3. Editable Fields will reuse this precision.
2538
    self.checkPrecisionOfListBox(report_section_list[0], 3)
2539 2540 2541 2542 2543 2544

    self.checkLineProperties(data_line_list[0],
                            id=1,
                            employee_career_reference='E1',
                            employee_title='Employee One',
                            base=2000,
2545 2546
                            employee=2000 * .50,
                            employer=2000 * .40,
2547 2548 2549 2550 2551 2552
                            total=(2000 * .50 + 2000 * .40))
    self.checkLineProperties(data_line_list[1],
                            id=2,
                            employee_career_reference='E2',
                            employee_title='Employee Two',
                            base=3000,
2553 2554
                            employee=3000 * .50,
                            employer=3000 * .40,
2555 2556 2557 2558
                            total=(3000 * .50 + 3000 * .40))
    # stat line
    self.checkLineProperties(line_list[-1],
                            base=3000 + 2000,
2559 2560
                            employee=(3000 + 2000) * .50,
                            employer=(3000 + 2000) * .40,
2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572
                            total=((3000 + 2000) * .50 + (3000 + 2000) * .40))

  def test_PayrollTaxesReportDifferentSalaryRange(self):
    currency_module = self.getCurrencyModule()
    if not hasattr(currency_module, 'EUR'):
      currency_module.newContent(
          portal_type = 'Currency',
          reference = "EUR", id = "EUR", base_unit_quantity=0.001 )
    eur = self.portal.currency_module.EUR
    service = self.portal.service_module.newContent(
                      portal_type='Service',
                      title='PS1',
2573
                      variation_base_category_list=('contribution_share',
2574
                                                    'salary_range'),
2575 2576
                      variation_category_list=('contribution_share/employee',
                                               'contribution_share/employer',
2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610
                                               'salary_range/france/slice_a',
                                               'salary_range/france/slice_b'))
    employer = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Employer',
                      price_currency_value=eur,
                      group_value=self.portal.portal_categories.group.demo_group)
    employee1 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee One',
                      career_reference='E1',
                      career_subordination_value=employer)
    employee2 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee Two',
                      career_reference='E2',
                      career_subordination_value=employer)
    provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Service Provider')
    other_provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Another Service Provider')
    ps1 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 1',
                      destination_section_value=employer,
                      source_section_value=employee1,
                      start_date=DateTime(2006, 1, 1),)
    line = ps1.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                # (destination is set by PaySheetTransaction.createPaySheetLine)
                   destination_value=employee1,
2611 2612
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer',
2613 2614
                                            'salary_range/france/slice_a',
                                            'salary_range/france/slice_b'))
2615
    cell_employee_a = line.newCell('contribution_share/employee',
2616 2617 2618 2619 2620 2621
                                   'salary_range/france/slice_a',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employee_a.edit(price=-.50, quantity=1000,
2622
                         contribution_share='employee',
2623
                         salary_range='france/slice_a')
2624
    cell_employee_b = line.newCell('contribution_share/employee',
2625 2626 2627 2628 2629 2630
                                   'salary_range/france/slice_b',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employee_b.edit(price=-.20, quantity=500,
2631
                         contribution_share='employee',
2632 2633
                         salary_range='france/slice_b')

2634
    cell_employer_a = line.newCell('contribution_share/employer',
2635 2636 2637 2638 2639 2640
                                   'salary_range/france/slice_a',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employer_a.edit(price=-.40, quantity=1000,
2641
                         contribution_share='employer',
2642
                         salary_range='france/slice_a')
2643
    cell_employer_b = line.newCell('contribution_share/employer',
2644 2645 2646 2647 2648 2649
                                   'salary_range/france/slice_b',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employer_b.edit(price=-.32, quantity=500,
2650
                         contribution_share='employer',
2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664
                         salary_range='france/slice_b')

    ps1.plan()

    ps2 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 2',
                      destination_section_value=employer,
                      source_section_value=employee2,
                      start_date=DateTime(2006, 1, 1),)
    line = ps2.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                   destination_value=employee2,
2665 2666
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer',
2667 2668
                                            'salary_range/france/slice_a',
                                            'salary_range/france/slice_b'))
2669
    cell_employee_a = line.newCell('contribution_share/employee',
2670 2671 2672 2673 2674 2675 2676
                                   'salary_range/france/slice_a',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employee_a.edit(price=-.50, quantity=1000,
                         salary_range='france/slice_a',
2677 2678
                         contribution_share='employee')
    cell_employee_b = line.newCell('contribution_share/employee',
2679 2680 2681 2682 2683 2684 2685
                                   'salary_range/france/slice_b',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employee_b.edit(price=-.20, quantity=3000,
                         salary_range='france/slice_b',
2686
                         contribution_share='employee')
2687

2688
    cell_employer_a = line.newCell('contribution_share/employer',
2689 2690 2691 2692 2693 2694 2695
                                   'salary_range/france/slice_a',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employer_a.edit(price=-.40, quantity=1000,
                         salary_range='france/slice_a',
2696 2697
                         contribution_share='employer')
    cell_employer_b = line.newCell('contribution_share/employer',
2698 2699 2700 2701 2702 2703 2704
                                   'salary_range/france/slice_b',
                                   portal_type='Pay Sheet Cell',
                                   base_id='movement',
                                   mapped_value_property_list=('price',
                                                               'quantity'),)
    cell_employer_b.edit(price=-.32, quantity=3000,
                         salary_range='france/slice_b',
2705
                         contribution_share='employer')
2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729
    self.stepTic()

    # set request variables and render
    request_form = self.portal.REQUEST
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['simulation_state'] = ['draft', 'planned']
    request_form['resource'] = service.getRelativeUrl()
    request_form['mirror_section'] = provider.getRelativeUrl()

    report_section_list = self.getReportSectionList(
                             self.portal.accounting_module,
                             'AccountingTransactionModule_viewPaySheetLineReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(6, len(data_line_list))

    self.checkLineProperties(data_line_list[0],
                            id=1,
                            employee_career_reference='E1',
                            employee_title='Employee One',
                            base=1000,
2730 2731
                            employee=1000 * .50,
                            employer=1000 * .40,
2732 2733 2734 2735 2736 2737
                            total=(1000 * .50 + 1000 * .40))
    self.checkLineProperties(data_line_list[1],
                            id=2,
                            employee_career_reference='E2',
                            employee_title='Employee Two',
                            base=1000,
2738 2739
                            employee=1000 * .50,
                            employer=1000 * .40,
2740 2741 2742 2743
                            total=(1000 * .50 + 1000 * .40))
    self.checkLineProperties(data_line_list[2],
                            employee_title='Total Slice A',
                            base=2000,
2744 2745
                            employee=2000 * .50,
                            employer=2000 * .40,
2746 2747 2748 2749 2750 2751 2752 2753
                            #total=(2000 * .50 + 2000 * .40)
                            )

    self.checkLineProperties(data_line_list[3],
                            id=3,
                            employee_career_reference='E1',
                            employee_title='Employee One',
                            base=500,
2754 2755
                            employee=500 * .20,
                            employer=500 * .32,
2756 2757 2758 2759 2760 2761
                            total=(500 * .20 + 500 * .32))
    self.checkLineProperties(data_line_list[4],
                            id=4,
                            employee_career_reference='E2',
                            employee_title='Employee Two',
                            base=3000,
2762 2763
                            employee=3000 * .20,
                            employer=3000 * .32,
2764 2765 2766 2767
                            total=(3000 * .20 + 3000 * .32))
    self.checkLineProperties(data_line_list[5],
                            employee_title='Total Slice B',
                            base=3500,
2768 2769
                            employee=3500 * .20,
                            employer=3500 * .32,
2770 2771 2772 2773 2774 2775
                            #total=(3500 * .20 + 3500 * .32),
                            )

    # stat line
    self.checkLineProperties(line_list[-1],
                            base=2000 + 3500,
2776 2777
                            employee=(2000 * .50 + 3500 * .20),
                            employer=(2000 * .40 + 3500 * .32),
2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790
                            total=((2000 * .50 + 3500 * .20) +
                                   (2000 * .40 + 3500 * .32)))

  def test_NetSalaryReport(self):
    currency_module = self.getCurrencyModule()
    if not hasattr(currency_module, 'EUR'):
      currency_module.newContent(
          portal_type = 'Currency',
          reference = "EUR", id = "EUR", base_unit_quantity=0.001 )
    eur = self.portal.currency_module.EUR
    salary_service = self.portal.service_module.newContent(
                      portal_type='Service',
                      title='Gross Salary',
2791
                      variation_base_category_list=('contribution_share',),
2792 2793
                      variation_category_list=('contribution_share/employee',
                                               'contribution_share/employer'))
2794 2795 2796
    service = self.portal.service_module.newContent(
                      portal_type='Service',
                      title='PS1',
2797
                      variation_base_category_list=('contribution_share',),
2798 2799
                      variation_category_list=('contribution_share/employee',
                                               'contribution_share/employer'))
2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834
    employer = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Employer',
                      price_currency_value=eur,
                      group_value=self.portal.portal_categories.group.demo_group)
    employee1 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee One',
                      career_reference='E1',
                      career_subordination_value=employer)
    employee1_ba = employee1.newContent(portal_type='Bank Account',
                                        title='Bank 1')
    employee2 = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee Two',
                      career_reference='E2',
                      career_subordination_value=employer)
    employee2_ba = employee2.newContent(portal_type='Bank Account',
                                        title='Bank 2')
    provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Service Provider')
    other_provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Another Service Provider')
    ps1 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 1',
                      destination_section_value=employer,
                      source_section_value=employee1,
                      payment_condition_source_payment_value=employee1_ba,
                      start_date=DateTime(2006, 1, 1),)
    line = ps1.newContent(portal_type='Pay Sheet Line',
                   resource_value=salary_service,
                   destination_value=employee1,
2835
                   base_contribution_list=['base_amount/payroll/report/salary/net',],
2836 2837 2838
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2839 2840 2841 2842
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2843
    cell_employee.edit(price=1, quantity=2000, contribution_share='employee')
2844 2845 2846 2847
    line = ps1.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                   destination_value=employee1,
2848
                   base_contribution_list=['base_amount/payroll/report/salary/net',],
2849 2850 2851
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2852 2853 2854 2855
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2856 2857
    cell_employee.edit(price=-.50, quantity=2000, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
2858 2859 2860 2861
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2862
    cell_employer.edit(price=-.40, quantity=2000, contribution_share='employer')
2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874
    ps1.plan()

    ps2 = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      title='Employee 2',
                      destination_section_value=employer,
                      source_section_value=employee2,
                      payment_condition_source_payment_value=employee2_ba,
                      start_date=DateTime(2006, 1, 1),)
    line = ps2.newContent(portal_type='Pay Sheet Line',
                   resource_value=salary_service,
                   destination_value=employee2,
2875
                   base_contribution_list=['base_amount/payroll/report/salary/net',],
2876 2877 2878
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2879 2880 2881 2882
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2883
    cell_employee.edit(price=1, quantity=3000, contribution_share='employee')
2884 2885 2886 2887
    line = ps2.newContent(portal_type='Pay Sheet Line',
                   resource_value=service,
                   source_section_value=provider,
                   destination_value=employee2,
2888
                   base_contribution_list=['base_amount/payroll/report/salary/net',],
2889 2890 2891
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
2892 2893 2894 2895
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2896 2897
    cell_employee.edit(price=-.50, quantity=3000, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
2898 2899 2900 2901
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
2902
    cell_employer.edit(price=-.40, quantity=3000, contribution_share='employer')
2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919
    self.stepTic()

    # set request variables and render
    request_form = self.portal.REQUEST
    request_form['at_date'] = DateTime(2006, 2, 2)
    request_form['section_category'] = 'group/demo_group'
    request_form['simulation_state'] = ['draft', 'planned']

    report_section_list = self.getReportSectionList(
                             self.portal.accounting_module,
                             'AccountingTransactionModule_viewNetSalaryReport')
    self.assertEquals(1, len(report_section_list))

    line_list = self.getListBoxLineList(report_section_list[0])
    data_line_list = [l for l in line_list if l.isDataLine()]
    self.assertEquals(2, len(data_line_list))

Jérome Perrin's avatar
Jérome Perrin committed
2920 2921
    # base_unit_quantity for EUR is set to 0.001 in the created currencies, so the
    # precision is 3. Editable Fields will reuse this precision.
2922
    self.checkPrecisionOfListBox(report_section_list[0], 3)
2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949

    self.checkLineProperties(data_line_list[0],
                            employee_career_reference='E1',
                            employee_title='Employee One',
                            employee_bank_account='Bank 1',
                            total_price=2000 - (2000 * .5),)
    self.checkLineProperties(data_line_list[1],
                            employee_career_reference='E2',
                            employee_title='Employee Two',
                            employee_bank_account='Bank 2',
                            total_price=3000 - (3000 * .5),)
    # stat line
    self.checkLineProperties(
            line_list[-1],
            total_price=3000 + 2000 - (2000 * .5) - (3000 * .5))

  def test_AccountingLineGeneration(self):
    currency_module = self.getCurrencyModule()
    if not hasattr(currency_module, 'EUR'):
      currency_module.newContent(
          portal_type = 'Currency',
          reference = "EUR", id = "EUR", base_unit_quantity=0.001 )
    # create services
    base_salary = self.portal.service_module.newContent(
      portal_type='Service',
      title='Base Salary',
      product_line='base_salary',
2950
      variation_base_category_list=('contribution_share',),
2951 2952
      variation_category_list=('contribution_share/employee',
                               'contribution_share/employer'))
2953 2954 2955 2956
    bonus = self.portal.service_module.newContent(
      portal_type='Service',
      title='Bonus',
      product_line='base_salary',
2957
      variation_base_category_list=('contribution_share',),
2958 2959
      variation_category_list=('contribution_share/employee',
                               'contribution_share/employer'))
2960 2961 2962 2963
    deductions = self.portal.service_module.newContent(
      portal_type='Service',
      title='Deductions',
      product_line='base_salary',
2964
      variation_base_category_list=('contribution_share',),
2965 2966
      variation_category_list=('contribution_share/employee',
                               'contribution_share/employer'))
2967 2968 2969 2970
    tax1 = self.portal.service_module.newContent(
      portal_type='Service',
      title='Tax1',
      product_line='payroll_tax_1',
2971
      variation_base_category_list=('contribution_share',),
2972 2973
      variation_category_list=('contribution_share/employee',
                               'contribution_share/employer'))
2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000

    # create accounts
    account_payroll_wages_expense = self.portal.account_module.newContent(
                          portal_type='Account',
                          title='Payroll Wages (expense)',
                          account_type='expense',)
    account_payroll_taxes_expense = self.portal.account_module.newContent(
                          portal_type='Account',
                          title='Payroll Taxes (expense)',
                          account_type='expense',)
    account_net_wages = self.portal.account_module.newContent(
                          portal_type='Account',
                          title='Net Wages',
                          account_type='liability/payable',)
    account_payroll_taxes = self.portal.account_module.newContent(
                          portal_type='Account',
                          title='Payroll Taxes',
                          account_type='liability/payable',)

    # create an invoice transaction rule for pay sheets.
    rule = self.portal.portal_rules.newContent(
      portal_type='Invoice Transaction Rule',
      title='Rule for PaySheet Accounting',
      reference='paysheet_transaction_rule',
      test_method_id='SimulationMovement_testInvoiceTransactionRule')
    rule.newContent(portal_type='Predicate',
      title='Employee Share',
3001
      string_index='contribution_share',
3002
      int_index=1,
3003
      membership_criterion_base_category_list=('contribution_share',),
3004
      membership_criterion_category_list=('contribution_share/employee',))
3005 3006
    rule.newContent(portal_type='Predicate',
      title='Employer Share',
3007
      string_index='contribution_share',
3008
      int_index=2,
3009
      membership_criterion_base_category_list=('contribution_share',),
3010
      membership_criterion_category_list=('contribution_share/employer',))
3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097

    rule.newContent(portal_type='Predicate',
      title='Base Salary',
      string_index='service',
      int_index=1,
      membership_criterion_base_category_list=('product_line',),
      membership_criterion_category_list=('product_line/base_salary',))
    rule.newContent(portal_type='Predicate',
      title='Payroll Tax 1',
      string_index='service',
      int_index=2,
      membership_criterion_base_category_list=('product_line',),
      membership_criterion_category_list=('product_line/payroll_tax_1',))
    self.stepTic()

    cell_list = rule.contentValues(portal_type='Accounting Rule Cell')
    self.assertEquals(4, len(cell_list))

    employee_base_salary = rule._getOb('movement_0_0')
    self.assertEquals('Employee Share * Base Salary',
                      employee_base_salary.getTitle())
    employee_base_salary.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_debit=1,
                      destination_value=account_payroll_wages_expense)
    employee_base_salary.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_credit=1,
                      destination_value=account_net_wages)

    employer_tax = rule._getOb('movement_1_1')
    self.assertEquals('Employer Share * Payroll Tax 1',
                      employer_tax.getTitle())
    employer_tax.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_debit=1,
                      destination_value=account_payroll_taxes)
    employer_tax.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_credit=1,
                      destination_value=account_payroll_taxes_expense)

    employee_tax = rule._getOb('movement_0_1')
    self.assertEquals('Employee Share * Payroll Tax 1',
                      employee_tax.getTitle())
    employee_tax.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_debit=1,
                      destination_value=account_payroll_taxes)
    employee_tax.newContent(
                      portal_type='Accounting Rule Cell Line',
                      destination_credit=1,
                      generate_prevision_script_id=\
      'SimulationMovement_generatePrevisionForEmployeeSharePaySheetMovement',
                      destination_value=account_net_wages)
    rule.validate()

    # create a pay sheet
    eur = self.portal.currency_module.EUR
    employer = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Employer',
                      price_currency_value=eur,
                      group_value=self.portal.portal_categories.group.demo_group)
    employee = self.portal.person_module.newContent(
                      portal_type='Person',
                      title='Employee',
                      career_reference='E1',
                      career_subordination_value=employer)
    provider = self.portal.organisation_module.newContent(
                      portal_type='Organisation',
                      title='Service Provider')

    ps = self.portal.accounting_module.newContent(
                      portal_type='Pay Sheet Transaction',
                      price_currency_value=eur,
                      resource_value=eur,
                      title='Employee 1',
                      destination_section_value=employer,
                      source_section_value=employee,
                      start_date=DateTime(2006, 1, 1),)

    # base salary = 2000
    line = ps.newContent(portal_type='Pay Sheet Line',
                   title='Base salary',
                   resource_value=base_salary,
                   destination_value=employee,
3098 3099 3100
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
3101 3102 3103 3104
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3105 3106
    cell_employee.edit(price=1, quantity=2000, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
3107 3108 3109 3110
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3111
    cell_employer.edit(price=1, quantity=2000, contribution_share='employer')
3112 3113 3114 3115 3116 3117

    # base_salary += 100 (bonus)
    line = ps.newContent(portal_type='Pay Sheet Line',
                   title='Bonus',
                   resource_value=bonus,
                   destination_value=employee,
3118 3119 3120
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
3121 3122 3123 3124
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3125 3126
    cell_employee.edit(price=1, quantity=100, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
3127 3128 3129 3130
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3131
    cell_employer.edit(price=1, quantity=100, contribution_share='employer')
3132 3133 3134 3135 3136 3137

    # base_salary -= 50 (deductions)   => base_salary == 2050
    line = ps.newContent(portal_type='Pay Sheet Line',
                   title='Deduction',
                   resource_value=deductions,
                   destination_value=employee,
3138 3139 3140
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
3141 3142 3143 3144
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3145 3146
    cell_employee.edit(price=-1, quantity=50, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
3147 3148 3149 3150
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3151
    cell_employer.edit(price=-1, quantity=50, contribution_share='employer')
3152 3153 3154 3155 3156 3157 3158 3159

    # tax1 = 10% for employee ( 205 )
    #        20% for employer ( 410 )
    line = ps.newContent(portal_type='Pay Sheet Line',
                   title='Tax 1',
                   resource_value=tax1,
                   source_section_value=provider,
                   destination_value=employee,
3160 3161 3162
                   variation_category_list=('contribution_share/employee',
                                            'contribution_share/employer'))
    cell_employee = line.newCell('contribution_share/employee',
3163 3164 3165 3166
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3167 3168
    cell_employee.edit(price=-.1, quantity=2050, contribution_share='employee')
    cell_employer = line.newCell('contribution_share/employer',
3169 3170 3171 3172
                                portal_type='Pay Sheet Cell',
                                base_id='movement',
                                mapped_value_property_list=('price',
                                                            'quantity'),)
3173
    cell_employer.edit(price=-.2, quantity=2050, contribution_share='employer')
3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330
    ps.plan()
    self.stepTic()

    related_applied_rule = ps.getCausalityRelatedValue(
                                portal_type='Applied Rule')
    self.assertNotEquals(related_applied_rule, None)

    # build accounting lines
    ps.confirm()
    ps.start()
    self.stepTic()
    accounting_line_list = ps.contentValues(
        portal_type='Pay Sheet Transaction Line')
    self.assertEquals(len(accounting_line_list), 4)

    line = [l for l in accounting_line_list
            if l.getDestinationValue() == account_payroll_wages_expense][0]
    self.assertEquals(2050, line.getDestinationDebit())
    self.assertEquals(employer, line.getDestinationSectionValue())

    line = [l for l in accounting_line_list
            if l.getDestinationValue() == account_net_wages][0]
    self.assertEquals(2050 - 205, line.getDestinationCredit())
    self.assertEquals(employer, line.getDestinationSectionValue())
    self.assertEquals(employee, line.getSourceSectionValue())

    line = [l for l in accounting_line_list
            if l.getDestinationValue() == account_payroll_taxes_expense][0]
    self.assertEquals(410, line.getDestinationDebit())
    self.assertEquals(employer, line.getDestinationSectionValue())

    line = [l for l in accounting_line_list
            if l.getDestinationValue() == account_payroll_taxes][0]
    self.assertEquals(410 + 205, line.getDestinationCredit())
    self.assertEquals(employer, line.getDestinationSectionValue())
    self.assertEquals(provider, line.getSourceSectionValue())

  def test_modelWithoutReferenceValidity(self):
    ''' Check that if no REFERENCE are defined on a model, the behavior is
    that this model is always valid. So check a Pay Sheet Transaction Line 
    is created after calling the calculation script
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreatePriceCurrency
               CreateLabourOutputService
               CreateBusinessProcess
               CreateBusinessPath
               CreateUrssafRoubaixOrganisation
               ModifyBusinessPathTradePhase
               Tic
               CheckModelWithoutRefValidity
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelWithoutDateValidity(self):
    ''' Check that if no DATE are defined on a model, the behavior is that 
    this model is always valid. (XXX check if it's what we want)
    So check that a line is created after calling calculation script, even if
    there is no start_date or stop_date
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreatePriceCurrency
               CreateLabourOutputService
               CreateBusinessProcess
               CreateBusinessPath
               CreateUrssafRoubaixOrganisation
               ModifyBusinessPathTradePhase
               Tic
               CheckModelWithoutDateValidity
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelDateValidity(self):
    ''' check that model effective_date and expiration_date are take into
    account.
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreatePriceCurrency
               CreateLabourOutputService
               CreateBusinessProcess
               CreateBusinessPath
               CreateUrssafRoubaixOrganisation
               ModifyBusinessPathTradePhase
               Tic
               CheckModelDateValidity
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelVersioning(self):
    '''check that latest version is used in case of more thant one model is
    matching using dates 
    '''
    sequence_list = SequenceList()
    sequence_string = """
               CreatePriceCurrency
               CreateBusinessProcess
               CreateBusinessPath
               CreateUrssafRoubaixOrganisation
               ModifyBusinessPathTradePhase
               Tic
               CheckModelVersioning
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_modelSliceInheritance(self):
    '''Check the slice inheritance'''
    base_id = 'cell'
    paysheet_model_module = self.getPortalObject().paysheet_model_module
    model_1 = paysheet_model_module.newContent(
        portal_type='Pay Sheet Model',
        variation_settings_category_list=
              ('salary_range/france',))

    model_2 = paysheet_model_module.newContent(
        portal_type='Pay Sheet Model',
        specialise_value=model_1,)

    cell = model_1.newCell('salary_range/france/slice_a',
        portal_type='Pay Sheet Model Slice',
        base_id='cell')
    cell.setQuantityRangeMin(1)
    cell.setQuantityRangeMax(2)

    # model 2 gets cell values from model 1 (see test_07_model_getCell)
    self.assertEquals(1,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMin())
    self.assertEquals(2,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMax())

    # model 2 can override values
    model_2.edit(variation_settings_category_list=('salary_range/france',))
    cell = model_2.newCell('salary_range/france/slice_a',
                    portal_type='Pay Sheet Model Slice',
                    base_id='cell')
    cell.setQuantityRangeMin(3)
    cell.setQuantityRangeMax(4)
    self.assertEquals(3,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMin())
    self.assertEquals(4,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMax())

    # when unsetting variation settings category on this model will acquire
    # again values from specialised model
    model_2.edit(variation_settings_category_list=())
    self.assertEquals(1,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMin())
    self.assertEquals(2,
        model_2.getCell('salary_range/france/slice_a').getQuantityRangeMax())

  def test_complexModelInheritanceScheme(self):
Fabien Morin's avatar
Fabien Morin committed
3331
    '''check inheritance and effective model with a more complex
3332 3333 3334 3335 3336 3337 3338 3339 3340 3341
    inheritance tree'''
    sequence_list = SequenceList()
    sequence_string = """
               CreatePriceCurrency
               CreateLabourOutputService
               Tic
               ComplexModelInheritanceScheme
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)
3342

Fabien Morin's avatar
Fabien Morin committed
3343
  def test_updatePaysheetAfterModelModification(self):
3344 3345 3346
    '''generate a paysheet using a model, modify the model by adding a new
    model line with the same resource as the first one and update the
    paysheet. Check the paysheet values have been updated (new line created)
Fabien Morin's avatar
Fabien Morin committed
3347 3348 3349 3350 3351 3352 3353 3354 3355
    '''
    sequence_list = SequenceList()
    sequence_string = '''
               CreateUrssafService
               CreateLabourService
               CreateEmployer
               CreateEmployee
               CreatePriceCurrency
               CreateModelWithSlices
3356
               Tic
Fabien Morin's avatar
Fabien Morin committed
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369
               ModelCreateUrssafModelLine
               UrssafModelLineCreateMovements
               CreateBasicPaysheet
               PaysheetCreateLabourPaySheetLine
               Tic
  ''' + self.BUSINESS_PATH_CREATION_SEQUENCE_STRING +'''
               CheckUpdateAggregatedAmountListReturn
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckUpdateAggregatedAmountListReturnNothing
               CheckPaysheetLineAmounts
3370
               ModelCreateUrssafModelLineWithSlices
Fabien Morin's avatar
Fabien Morin committed
3371
               Tic
3372
               UrssafModelLineWithSlicesCreateMovements
Fabien Morin's avatar
Fabien Morin committed
3373
               Tic
Fabien Morin's avatar
Fabien Morin committed
3374 3375
               PaysheetApplyTransformation
               Tic
3376 3377
               CheckPaysheetLineAreCreatedAfterUpdateWithLinesWithSameResource
               CheckPaysheetLineAmountsAfterUpdateWithLinesWithSameResource
Fabien Morin's avatar
Fabien Morin committed
3378
               CheckUpdateAggregatedAmountListReturnNothing
3379
               CheckPaysheetLineAmountsAfterUpdateWithLinesWithSameResource
Fabien Morin's avatar
Fabien Morin committed
3380 3381 3382 3383 3384 3385 3386 3387 3388 3389
    '''
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_propertiesAreSetOnPaysheetLines(self):
    '''check porperties from model line (like description, int_index,
    title, ...) are copied on the paysheet lines'''
    sequence_list = SequenceList()
    sequence_string = self.COMMON_BASIC_DOCUMENT_CREATION_SEQUENCE_STRING + """
               SetProperiesOnModelLines
Fabien Morin's avatar
Fabien Morin committed
3390
               Tic
Fabien Morin's avatar
Fabien Morin committed
3391 3392 3393 3394 3395 3396 3397 3398 3399 3400
               PaysheetApplyTransformation
               Tic
               CheckPaysheetLineAreCreated
               CheckPaysheetLineAmounts
               CheckPropertiesAreCopiedFromModelLineToPaySheetLine
    """
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)


3401 3402 3403 3404 3405
import unittest
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestPayroll))
  return suite