testImmobilisation.py 201 KB
Newer Older
1 2 3
##############################################################################
#
# Copyright (c) 2004 Nexedi SARL and Contributors. All Rights Reserved.
Guillaume Michon's avatar
Guillaume Michon committed
4
#          Guillaume Michon <guillaume.michon@e-asc.com>
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# 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.
#
##############################################################################


30
import unittest
31 32
from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
33
from Products.ERP5Type.tests.Sequence import SequenceList
34 35
from DateTime import DateTime
from zLOG import LOG
Guillaume Michon's avatar
Guillaume Michon committed
36 37
from testOrder import TestOrderMixin
from Products.ERP5.Document.ImmobilisationMovement import UNIMMOBILISING_METHOD, NO_CHANGE_METHOD
38

Guillaume Michon's avatar
Guillaume Michon committed
39 40 41 42
try:
  from transaction import get as get_transaction
except ImportError:
  pass
43

44
class TestImmobilisationMixin(TestOrderMixin, ERP5TypeTestCase):
45
  run_all_test = 1
Guillaume Michon's avatar
Guillaume Michon committed
46
  # Different variables used for this test
47
  item_portal_type = 'Apparel Fabric Item'
48
  packing_list_portal_type = 'Purchase Packing List'
49
  packing_list_line_portal_type = 'Purchase Packing List Line'
50 51 52 53
  internal_packing_list_portal_type = 'Internal Packing List'
  sale_packing_list_portal_type = 'Sale Packing List'
  inventory_portal_type = 'Inventory'
  inventory_line_portal_type = 'Inventory Line'
Guillaume Michon's avatar
Guillaume Michon committed
54 55 56
  organisation_portal_type = 'Organisation'
  account_portal_type = 'Account'
  currency_portal_type = 'Currency'
57
  resource_portal_type = 'Product'
Guillaume Michon's avatar
Guillaume Michon committed
58 59 60 61 62 63 64
  linear_method = 'eu/linear'
  degressive_method = 'fr/degressive'
  uncontinuous_degressive_method = 'fr/uncontinuous_degressive'
  actual_use_method = 'fr/actual_use'
  no_amortisation_method = 'eu/no_amortisation'
  diverged = 'diverged'
  solved = 'solved'
65 66
  id_transaction = 0
  id_simulation = 0
Guillaume Michon's avatar
Guillaume Michon committed
67
  reindex_done = 0
68

Guillaume Michon's avatar
Guillaume Michon committed
69 70
  def getTitle(self):
    return "Immobilisation"
71
  
Guillaume Michon's avatar
Guillaume Michon committed
72 73 74 75 76
  def stepCommitTransaction(self, sequence=None, sequence_list=None, **kw):
    """
    For debugging
    """
    get_transaction().commit()
77

Guillaume Michon's avatar
Guillaume Michon committed
78 79 80
  def getBusinessTemplateList(self):
    """
      Return the list of business templates.
81

Guillaume Michon's avatar
Guillaume Michon committed
82
    """
83
    return ( "erp5_base",
Guillaume Michon's avatar
Guillaume Michon committed
84
            "erp5_trade",
85
            "erp5_pdm",# Needed by accounting
Guillaume Michon's avatar
Guillaume Michon committed
86 87 88 89
            "erp5_accounting",
            "erp5_apparel", # In order to use items
            "erp5_immobilisation",
            )
90

Guillaume Michon's avatar
Guillaume Michon committed
91 92 93 94 95 96 97 98 99 100
  def getRuleTool(self):
    return getattr(self.getPortal(), 'portal_rules', None)
  def getAccountingModule(self):
    return getattr(self.getPortal(), 'accounting_module', None)
  def getOrganisationModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.organisation_portal_type)
  def getItemModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.item_portal_type)
  def getPackingListModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.packing_list_portal_type)
101 102 103 104 105 106
  def getInternalPackingListModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.internal_packing_list_portal_type)
  def getSalePackingListModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.sale_packing_list_portal_type)
  def getInventoryModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.inventory_portal_type)
Guillaume Michon's avatar
Guillaume Michon committed
107 108
  def getAccountModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.account_portal_type)
109 110 111 112 113 114 115 116 117 118 119
  def getUserFolder(self):
    return getattr(self.getPortal(), 'acl_users', None)
  def getWorkflowTool(self):
    return getattr(self.getPortal(), 'portal_workflow', None)
  
  def createManagerAndLogin(self, quiet=0, run=run_all_test):
    """
      Create a simple user in user_folder with manager rights.
      This user will be used to initialize data in the method afterSetup
    """
    all_roles = ['Manager','Assignor','Assignee','Author','Associate','Auditor']
120 121
    if not "manager" in [x.id for x in self.getUserFolder().objectValues()]:
      self.getUserFolder()._doAddUser('manager', '', all_roles, [])
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144
    self.login('manager')
    self.assignPASRolesToUser('test_user_1_', all_roles)
    
  
  def checkUserFolderType(self, quiet=0, run=run_all_test):
    """
      Check the type of user folder to let the test working with both NuxUserGroup and PAS.
    """
    self.user_folder = self.getUserFolder()
    self.PAS_installed = 0
    if self.user_folder.meta_type == 'Pluggable Auth Service':
      # we use PAS
      self.PAS_installed = 1
      
  def assignPASRolesToUser(self, user_name, role_list, quiet=0, run=run_all_test):
    """
      Assign a list of roles to one user with PAS.
    """
    user_folder = self.getUserFolder()
    for role in role_list:
      if role not in user_folder.zodb_roles.listRoleIds():
        user_folder.zodb_roles.addRole(role)
      user_folder.zodb_roles.assignRoleToPrincipal(role, user_name)
145

146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181
  def createERP5Users(self, user_dict, quiet=0, run=run_all_test):
    """
      Create all ERP5 users needed for the test.
      ERP5 user = Person object + Assignment object in erp5 person_module.
    """
    for user_login, user_data in user_dict.items():
      user_roles = user_data[0]
      # Create the Person.
      if len([p for p in self.getPersonModule().objectValues() if p.getReference() == user_login]) == 0:
        person = self.getPersonModule().newContent(id=user_login,
                                                  portal_type='Person',
                                                  reference=user_login,
                                                  career_role="internal")
        # Create the Assignment.
        assignment = person.newContent( portal_type       = 'Assignment'
                                      , destination_value = user_data[1]
                                      , function          = user_data[2]
                                      , group             = user_data[3]
                                      , site              = user_data[4]
                                      )
        if self.PAS_installed and len(user_roles) > 0:
          # In the case of PAS, if we want global roles on user, we have to do it manually.
          self.assignPASRolesToUser(user_login, user_roles)
        elif not self.PAS_installed:
          # The user_folder counterpart of the erp5 user must be
          #   created manually in the case of NuxUserGroup.
          self.user_folder.userFolderAddUser( name     = user_login
                                            , password = ''
                                            , roles    = user_roles
                                            , domains  = []
                                            )
        # User assignment to security groups is also required, but is taken care of
        #   by the assignment workflow when NuxUserGroup is used and
        #   by ERP5Security PAS plugins in the context of PAS use.
        assignment.open()
        person.validate()
182

183 184 185 186 187 188 189 190 191 192 193
  def updateRoleMappings(self, portal_type_list=[]):
    """
    Update the local roles in existing objects.
    """
    portal_catalog = self.portal.portal_catalog
    for portal_type in portal_type_list:
      for brain in portal_catalog(portal_type = portal_type):
        obj = brain.getObject()
        userdb_path, user_id = obj.getOwnerTuple()
        obj.updateLocalRolesOnSecurityGroups(user_name = user_id)
        #obj.assignRoleToSecurityGroup(user_name = user_id)
194

Guillaume Michon's avatar
Guillaume Michon committed
195 196
  def afterSetUp(self):
    portal = self.getPortal()
197
    self.createManagerAndLogin()
198

Guillaume Michon's avatar
Guillaume Michon committed
199 200 201 202 203
    # remove all message in the message_table because
    # the previous test might have failed
    message_list = portal.portal_activities.getMessageList()
    for message in message_list:
      portal.portal_activities.manageCancel(message.object_path,message.method_id)
204

205 206 207
    self.createCategories()

    #Assert default security Value
208

209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225
    list_module = [ 'Inventory Module',
                    'Purchase Packing List Module',
                    'Internal Packing List Module',
                    'Sale Packing List Module',
                    'Building Module',
                    'Incorporeal Item Module',
                    'Reevaluation Module',
                    'Restoration Module',
                    self.getAccountingModule().getPortalType(),
                    self.getOrganisationModule().getPortalType(),
                    self.getItemModule().getPortalType(),
                    self.getPackingListModule().getPortalType(),
                    self.getInventoryModule().getPortalType(),
                    self.getAccountModule().getPortalType(),
                    self.getCurrencyModule().getPortalType(),
                    self.getPersonModule().getPortalType()
                    ]
226

Guillaume Michon's avatar
Guillaume Michon committed
227 228 229 230
    # Then add new components
    self.createCurrency()
    self.createOrganisationList()
    self.createAccountList()
231 232 233
    self.createItemList()
    get_transaction().commit()
    self.tic()
234

235 236
    self.workflow_tool = self.getWorkflowTool()
    self.checkUserFolderType()
237

238 239 240 241 242 243 244
  def beforeTearDown(self):
    """
    Delete all Objects in PL & M Module
    """
    self.logout()
    self.login('manager')

245 246 247
    get_transaction().commit()
    self.tic()

248 249
    simulation_id_list = [r for r in self.getPortal().portal_simulation.objectIds()]
    self.getPortal().portal_simulation.manage_delObjects(simulation_id_list)
250 251 252

    item_id_list = [r for r in self.getItemModule().objectIds()]
    self.getItemModule().manage_delObjects(item_id_list)
253

254 255 256 257
    #LOG('item_id_list after',0,[r for r in self.getPortal().material_module.objectIds()])
    #item_catalog = [(r.uid,r.path) for r in self.getPortal().portal_catalog(portal_type = 'Material')]
    pl_id_list = [r for r in self.getPortal().purchase_packing_list_module.objectIds()]
    self.getPortal().purchase_packing_list_module.manage_delObjects(pl_id_list)
258

259 260
    id_list = [r for r in self.getAccountingModule().objectIds()]
    self.getAccountingModule().manage_delObjects(id_list)
261

262 263
    get_transaction().commit()
    self.tic()
264

Guillaume Michon's avatar
Guillaume Michon committed
265 266 267 268 269 270
  def createCategories(self):
    """
    Replace OrderMixin method
    """
    # Create group categories
    category_tool = self.getCategoryTool()
271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298
    if len(category_tool.group.objectIds()) == 0:
      self.createCategoryTree(category_tool.group,
                      [
                        ("group A","GA",
                          [
                            ("group Aa","GAa",
                              [
                                ("group Aa1","GAa1",[]),
                                ("group Aa2","GAa2",[])
                              ]
                            ),
                            ("group Ab","GAb",
                              [
                                ("group Ab1","GAb1",[]),
                                ("group Ab2","GAb2",[])
                              ]
                            )
                          ]
                        ),
                        ("group B","GB",
                          [
                            ("group Ba","GBa", []),
                            ("group Bb","GBb", [])
                          ],
                        ),
                        ("group C","GC", []),
                      ]
                  )
Guillaume Michon's avatar
Guillaume Michon committed
299 300 301 302 303

  def createCategoryTree(self, current_category, category_tree):
    """
    Create a category tree
    """
304
    for category, codification, new_tree in category_tree:
305 306 307
      if category not in current_category.objectIds():
        new_category = current_category.newContent(portal_type='Category', id=category, codification=codification)
        self.createCategoryTree(new_category, new_tree)
308

309 310 311 312 313
  def createCategorySiteTree(self, current_category, category_tree):
    """
    Create a category tree
    """
    for category, codification, vault_type, new_tree in category_tree:
314 315 316 317 318 319
      if category not in current_category.objectIds():
        new_category = current_category.newContent(portal_type='Category',
                                                   id=category,
                                                   codification=codification)
        new_category.setVaultType(vault_type)
        self.createCategorySiteTree(new_category, new_tree)
320

Guillaume Michon's avatar
Guillaume Michon committed
321 322
  def createCurrency(self):
    currency_module = self.getCurrencyModule()
323
    if len(currency_module.contentValues()) == 0:
324 325
      currency_module.newContent(id="EUR", portal_type='Currency')
      currency_module.newContent(id="FCFA", portal_type='Currency')
Guillaume Michon's avatar
Guillaume Michon committed
326 327

  def createOrganisationList(self):
328
    """
Guillaume Michon's avatar
Guillaume Michon committed
329
    Create some organisations relating to the group tree
330
    """
Guillaume Michon's avatar
Guillaume Michon committed
331
    organisation_module = self.getOrganisationModule()
332
    if len(organisation_module.contentValues()) == 0:
333 334 335 336 337 338 339 340 341 342 343 344 345 346
      organisation_list= (
                               ("A", "A", "group A", "group/group A"),
                               ("Aa", "Aa", "group A", "group/group A/group Aa"),
                               ("Ab", "Ab", "group A", "group/group A/group Ab"),
                               ("Aa1", "Aa1", "group A", "group/group A/group Aa/group Aa1"),
                               ("Aa2", "Aa2", "group A", "group/group A/group Aa/group Aa2"),
                               ("Ab1", "Ab1", "group A", "group/group A/group Ab/group Ab1"),
                               ("Ab2", "Ab2", "group A", "group/group A/group Ab/group Ab2"),
                               ("B", "B", "group B", "group/group B"),
                               ("Ba", "Ba", "group B", "group/group B/group Ba"),
                               ("Bb", "Bb", "group B", "group/group B/group Bb"),
                               ("standalone", "standalone", "", ""),
                           )
      for organisation_id, title, group, mapping in organisation_list:
Guillaume Michon's avatar
Guillaume Michon committed
347
        organisation_module.newContent(id = organisation_id,
348
                                       title = title,
Guillaume Michon's avatar
Guillaume Michon committed
349 350 351
                                       group = group,
                                       mapping = mapping,
                                       )
352 353 354 355
      ##We need to commit here because edit organisation doesn't apply
      #get_transaction().commit()
      #self.tic()
      for organisation_id in ['A','Aa','Ab','B','Ba','Bb','standalone']:
Guillaume Michon's avatar
Guillaume Michon committed
356 357 358
        organisation = organisation_module[organisation_id]
        organisation.edit(price_currency_value = self.getCurrencyModule()["EUR"],
                          financial_year_stop_date = DateTime('2000/01/01'))
359

Guillaume Michon's avatar
Guillaume Michon committed
360
  def createAccountList(self):
361
    """
Guillaume Michon's avatar
Guillaume Michon committed
362
    Create some accounts
363
    """
Guillaume Michon's avatar
Guillaume Michon committed
364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389
    account_module = self.getAccountModule()
    if len(account_module.contentValues())==0:
      for i in range(15):
        account_id = 'account%i' % i
        account = account_module.newContent(id=account_id, gap='gap')
        account.validate()
    self.account_dict = {
    'input_account':              '%s/%s' % (self.getAccountModule().getId(),'account1'),
    'output_account':             '%s/%s' % (self.getAccountModule().getId(),'account2'),
    'immobilisation_account':     '%s/%s' % (self.getAccountModule().getId(),'account3'),
    'amortisation_account':       '%s/%s' % (self.getAccountModule().getId(),'account4'),
    'depreciation_account':       '%s/%s' % (self.getAccountModule().getId(),'account5'),
    'immobilisation_vat_account': '%s/%s' % (self.getAccountModule().getId(),'account6'),
    'extra_cost_account':         '%s/%s' % (self.getAccountModule().getId(),'account7'),
    }
    self.monthly_dict = {
    'monthly_amortisation_account':'%s/%s' % (self.getAccountModule().getId(),'account8'),
    }
    self.extra_account_dict = {
    'immobilisation_account':   '%s/%s' % (self.getAccountModule().getId(),'account9'),
    'amortisation_account':     '%s/%s' % (self.getAccountModule().getId(),'account10'),
    'depreciation_account':     '%s/%s' % (self.getAccountModule().getId(),'account11'),
    }
    self.extra_monthly_dict = {
    'monthly_amortisation_account':'%s/%s' % (self.getAccountModule().getId(),'account12'),
    }
390

391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
  def createAmortisationDefaultData(self):
    amo_data_module = self.getPortal().amortisation_default_data_module
    if len(amo_data_module.contentValues()) == 0:
      property_dict1 = {'amortisation_method':self.linear_method,
                      'amortisation_start_price':0.0,
                      'disposal_price':0.0,
                      'amortisation_duration':72,
                      'immobilisation_vat':0.0,
                      'product_line':'armoires',
                      }
      amo_data1 = amo_data_module.newContent()
      amo_data1.edit(**property_dict1)
      property_dict2 = {'amortisation_method':self.linear_method,
                      'amortisation_start_price':0.0,
                      'disposal_price':0.0,
                      'amortisation_duration':72,
                      'immobilisation_vat':0.0,
                      'product_line':'art_tableaux',
                      }
      amo_data2 = amo_data_module.newContent()
      amo_data2.edit(**property_dict2)
412

Guillaume Michon's avatar
Guillaume Michon committed
413
  def createItemList(self):
414
    """
Guillaume Michon's avatar
Guillaume Michon committed
415
    Create some items
416
    """
Guillaume Michon's avatar
Guillaume Michon committed
417
    item_module = self.getItemModule()
418 419
    if len(item_module.contentValues()) == 0:
      for i in range(30):
Guillaume Michon's avatar
Guillaume Michon committed
420
        item_id = 'item%i' % i
421
        item_module.newContent(id=item_id, reference='%i' % i)
422

423 424
  def stepPdb(self, sequence=None, sequence_list=None, **kw):
    import pdb;pdb.set_trace()
425

Guillaume Michon's avatar
Guillaume Michon committed
426 427
  def stepCreatePackingList(self, sequence=None, sequence_list=None, **kw):
    property_dict = {}
428
    for property in ('source_section','destination_section','datetime','destination'):
Guillaume Michon's avatar
Guillaume Michon committed
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443
      value_list = sequence.get(property)
      if value_list is not None:
        if type(value_list) == type([]):
          value = value_list[0]
          value_list.remove(value)
        else:
          value = value_list
      else:
        value = value_list
      property_dict[property] = value
    pl_module = self.getPackingListModule()
    pl = pl_module.newContent(portal_type = self.packing_list_portal_type)
    pl.edit( source_section_value =      property_dict['source_section'],
             destination_section_value = property_dict['destination_section'],
             start_date =                property_dict['datetime'],
444 445 446 447
             stop_date =                 property_dict['datetime'],
             destination =               property_dict['destination'],
             )
    
Guillaume Michon's avatar
Guillaume Michon committed
448 449 450
    packing_list_list = sequence.get('packing_list_list', [])
    packing_list_list.append(pl)
    sequence.set('packing_list_list', packing_list_list)
451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470
    #LOG('createPL',0,[(ppl.getUid(),ppl.getRelativeUrl()) for ppl in pl_module.objectValues()])
    
  def stepDeliverPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    self.workflow_tool.doActionFor(pl, 'confirm_action', wf_id='packing_list_workflow')
    get_transaction().commit()
    self.tic()
    self.workflow_tool.doActionFor(pl, 'set_ready_action', wf_id='packing_list_workflow')
    self.workflow_tool.doActionFor(pl, 'start_action', wf_id='packing_list_workflow')
    get_transaction().commit()
    self.tic()
    self.workflow_tool.doActionFor(pl, 'stop_action', wf_id='packing_list_workflow')
    get_transaction().commit()
    self.tic()
    #self.workflow_tool.doActionFor(pl, 'deliver_action', wf_id='packing_list_workflow')

  def stepTestItemValidationState(self, sequence=None, sequence_list=None, **kw):
    item = self.getItemModule()['item1']
    self.assertEquals(item.getValidationState(), 'exploited')
471

472 473 474 475

  def stepAggregateItems(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list', [])[-1]
    parameter_dict = sequence.get('parameter_dict', {})
476 477 478 479
    resource_value = sequence.get('product',None)
    if resource_value is None:
      resource_value = self.getPortal().product_module.newContent()
      sequence.edit(product=resource_value)
480 481 482 483 484
    if parameter_dict is None: parameter_dict = {}
    item_list_list = sequence.get('item_list_list') # This is a list of list in
                                                    # order to make multiple lines
    for item_list in item_list_list:
      pl_line = pl.newContent(portal_type = self.packing_list_line_portal_type)
485 486
      pl_line.edit(aggregate_value_list = item_list, 
                   resource_value=resource_value, **parameter_dict)
487 488
    get_transaction().commit()
    self.tic()
489 490
    #pl.calculateImmobilisationValidity()

491 492 493 494
  def stepEditPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    pl.edit()
495

Guillaume Michon's avatar
Guillaume Michon committed
496 497 498 499 500 501
  def stepCreateComplexPackingListStructure(self, sequence=None, sequence_list=None, **kw):
    """
    Create a complex structure of PL and items
    Item    1    2    3   4
    PL 1    X    X
    PL 2                  X
502
    PL 3    X         X
Guillaume Michon's avatar
Guillaume Michon committed
503 504 505 506
    PL 4         X    X
    """
    sequence.edit(destination_section =  self.getOrganisationModule()["A"],
                  datetime= self.datetime,
507
                  item_list_list = [[ self.getItemModule()['item1'] ], [ self.getItemModule()['item2'] ]])
Guillaume Michon's avatar
Guillaume Michon committed
508 509
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
510
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
511 512 513
    sequence.edit(item_list_list = [[self.getItemModule()['item4']]], datetime = self.datetime+5)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
514
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
515 516 517 518
    sequence.edit(item_list_list = [[ self.getItemModule()['item1'],self.getItemModule()['item3'] ]],
                  datetime = self.datetime+10)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
519
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
520 521 522 523
    sequence.edit(item_list_list = [[ self.getItemModule()['item2'],self.getItemModule()['item3'] ]],
                  datetime = self.datetime+15)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
524 525
    self.stepDeliverPackingList(sequence=sequence)

Guillaume Michon's avatar
Guillaume Michon committed
526 527 528
  def stepDeletePackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    pl_in_list = 0
529
    if pl is None:
Guillaume Michon's avatar
Guillaume Michon committed
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
      pl = sequence.get('packing_list_list', []) [-1]
      pl_in_list = 1
    pl_id = pl.getId()
    self.getPackingListModule().manage_delObjects([pl_id])
    if pl_in_list:
      sequence.set('packing_list_list', sequence.get('packing_list_list')[:-1])
    
  def stepUseFirstPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list')[0]
    sequence.set('packing_list', pl)

  def stepUseSecondPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list')[1]
    sequence.set('packing_list', pl)

  def stepUseThirdPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list')[2]
    sequence.set('packing_list', pl)
    
  def stepUseFourthPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list')[3]
    sequence.set('packing_list', pl)
    
  def stepDeleteCurrentPackingListFromSequence(self, sequence=None, sequence_list=None, **kw):
    sequence.set('packing_list', None)
    
  def stepDeleteAllPackingLists(self, sequence=None, sequence_list=None, **kw):
    id_list = self.getPackingListModule().contentIds()
    self.getPackingListModule().manage_delObjects(id_list)
    sequence.set('packing_list_list', [])
    
  def stepDeleteAccounting(self, sequence=None, sequence_list=None, **kw):
    id_list = self.getAccountingModule().contentIds()
    self.getAccountingModule().manage_delObjects(id_list)
    
  def stepValidateAccounting(self, sequence=None, sequence_list=None, **kw):
    for transaction in self.getAccountingModule().contentValues():
      transaction.stop()
568 569
      get_transaction().commit()
      self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
570
      transaction.deliver()
571 572
      get_transaction().commit()
      self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
573 574 575 576 577

  def stepTestPackingListInvalidImmobilisationState(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl=sequence.get('packing_list_list', [])[-1]
    self.stepTestPackingListImmobilisationState(pl, "invalid")
578

Guillaume Michon's avatar
Guillaume Michon committed
579 580 581 582
  def stepTestPackingListValidImmobilisationState(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    self.stepTestPackingListImmobilisationState(pl, "valid")
583

584 585 586 587
  def stepTestPackingListDeliveredSimulationState(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    self.stepTestPackingListSimulationState(pl, "delivered")
588

Guillaume Michon's avatar
Guillaume Michon committed
589 590 591 592
  def stepTestPackingListCalculatingImmobilisationState(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    self.stepTestPackingListImmobilisationState(pl, "calculating")
593

Guillaume Michon's avatar
Guillaume Michon committed
594 595
  def stepTestPackingListImmobilisationState(self, pl, state, **kw):
    self.assertEquals(pl.getImmobilisationState(), state)
596

597 598
  def stepTestPackingListSimulationState(self, pl, state, **kw):
    self.assertEquals(pl.getSimulationState(), state)
599

600 601
  def stepTestPackingListValidationState(self, pl, state, **kw):
    self.assertEquals(pl.getValidationState(), state)
602

Guillaume Michon's avatar
Guillaume Michon committed
603 604 605 606 607 608 609 610 611 612
  def stepCreatePackingListsForContinuousAmortisationPeriodList(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    2001/01/01 : immobilisation with different values (2)
    2002/01/01 : immobilisation with no values  (3)
    2002/07/01 : owner change
    2002/10/01 : owner set to None
    2003/01/01 : immobilisation with no values (4)
    """
613

Guillaume Michon's avatar
Guillaume Michon committed
614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':72,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
630 631
    self.stepDeliverPackingList(sequence=sequence)
    #1
Guillaume Michon's avatar
Guillaume Michon committed
632 633 634 635 636 637 638 639
    parameter_dict.update( {'amortisation_start_price':12000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0 })
    sequence.edit(datetime = DateTime('2001/01/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
640 641
    self.stepDeliverPackingList(sequence=sequence)
    #2
Guillaume Michon's avatar
Guillaume Michon committed
642 643 644 645 646 647
    for parameter in ('amortisation_start_price', 'disposal_price', 'amortisation_duration', 'immobilisation_vat'):
      del parameter_dict[parameter]
    sequence.edit(datetime = DateTime('2002/01/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
648 649
    self.stepDeliverPackingList(sequence=sequence)
    #3
Guillaume Michon's avatar
Guillaume Michon committed
650 651 652
    sequence.edit(datetime = DateTime('2003/01/01'))
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
653 654
    self.stepDeliverPackingList(sequence=sequence)
    #4
Guillaume Michon's avatar
Guillaume Michon committed
655 656 657 658 659 660
    # Create owner changing movements
    sequence.edit(datetime = DateTime('2002/07/01'),
                  destination_section=self.getOrganisationModule()["B"],
                  parameter_dict=None)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
661 662
    self.stepDeliverPackingList(sequence=sequence)
    #5
Guillaume Michon's avatar
Guillaume Michon committed
663 664 665
    sequence.edit(datetime = DateTime('2002/10/01'),destination_section=None)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
666 667 668 669 670 671
    self.stepDeliverPackingList(sequence=sequence)
    #6
    #sequence.edit(datetime = DateTime('2003/01/01'))
    #self.stepCreatePackingList(sequence=sequence)
    #self.stepAggregateItems(sequence=sequence)
    #self.stepDeliverPackingList(sequence=sequence)
672

Guillaume Michon's avatar
Guillaume Michon committed
673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698
  def stepCreatePackingListsForUncontinuousAmortisationPeriodList(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing an uncontinuous period list :
    2000/01/01 : immobilisation (1)
    2001/01/01 : unimmobilisation (2)
    2001/07/01 : unimmobilisation (3)
    2002/01/01 : owner change
    2003/01/01 : immobilisation (4)
    2004/01/01 : owner change
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':72,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
699
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
700 701 702 703 704 705 706 707 708 709 710
    parameter_dict.update( {'amortisation_method':UNIMMOBILISING_METHOD,
                            'amortisation_start_price':12000,
                            'amortisation_start_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0 })
    for parameter in ('amortisation_start_price', 'disposal_price', 'amortisation_duration', 'immobilisation_vat'):
      del parameter_dict[parameter]
    sequence.edit(datetime = DateTime('2001/01/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
711
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
712 713 714 715
    sequence.edit(datetime = DateTime('2001/07/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
716
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
717 718 719 720 721 722 723 724 725 726 727
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':72,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(datetime = DateTime('2003/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["B"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
728
    self.stepDeliverPackingList(sequence=sequence)
729

Guillaume Michon's avatar
Guillaume Michon committed
730 731 732 733 734 735
    # Create owner changing movements
    sequence.edit(datetime = DateTime('2002/01/01'),
                  parameter_dict=None,
                  destination_section=self.getOrganisationModule()["B"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
736
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
737 738 739 740
    sequence.edit(datetime = DateTime('2004/01/01'),
                  destination_section=self.getOrganisationModule()["A"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
741
    self.stepDeliverPackingList(sequence=sequence)
742

Guillaume Michon's avatar
Guillaume Michon committed
743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764
  def stepCreatePackingListsForSimpleItemImmobilisation(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    2003/07/01 : immobilisation (2)
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':72,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
765
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
766 767 768 769 770 771 772 773 774
    parameter_dict.update( {'amortisation_start_price':12000,
                            'amortisation_duration':84,
                            'immobilisation_vat':0,
                            'degressive_coefficient':2.5,
                            'durability':100 })
    sequence.edit(datetime = DateTime('2003/07/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801
    self.stepDeliverPackingList(sequence=sequence)

  """
  09BIS
  """
  def stepCreatePackingListsForSimpleItemImmobilisationBIS(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/07/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["orga"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
    self.stepDeliverPackingList(sequence=sequence)
802

Guillaume Michon's avatar
Guillaume Michon committed
803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826
  def stepCreatePackingListsForSimulationTest(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    2001/01/01 : immobilisation (2)
    The second movement changes some accounts
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':8000,
                            'disposal_price':0,
                            'amortisation_duration':36,
                            'immobilisation_vat':1000,
                            'extra_cost_price':2000,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa1"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
827
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
828 829 830 831 832 833 834 835 836 837 838 839 840
    parameter_dict.update( {'amortisation_start_price':12000,
                            'amortisation_duration':36,
                            'immobilisation_vat':0,
                            'extra_cost_price':0,
                            'degressive_coefficient':2,
                            'durability':100,
                            })
    parameter_dict.update(self.extra_account_dict)
    sequence.edit(datetime = DateTime('2001/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa2"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
841
    self.stepDeliverPackingList(sequence=sequence)
842

Guillaume Michon's avatar
Guillaume Michon committed
843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866
  def stepCreatePackingListsForNoChangeMethodSimulationTest(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    2001/01/01 : immobilisation (2)
    The second movement changes only the owner (or not)
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':8000,
                            'disposal_price':0,
                            'amortisation_duration':36,
                            'immobilisation_vat':1000,
                            'extra_cost_price':2000,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa1"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
867
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
868 869 870 871 872 873 874 875 876
    for property in ('amortisation_start_price','amortisation_duration','immobilisation_vat',
                     'extra_cost_price','disposal_price'):
      del parameter_dict[property]
    parameter_dict['amortisation_method'] = NO_CHANGE_METHOD
    sequence.edit(datetime = DateTime('2001/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa2"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
877
    self.stepDeliverPackingList(sequence=sequence)
878

Guillaume Michon's avatar
Guillaume Michon committed
879 880 881 882 883 884 885 886
  def stepChangeCurrentPackingListDestinationSectionForOwnerChange(self, sequence=None, sequence_list=None, **kw):
    """
    Change the destination section of the packing list in order to make a owner change,
    but the actual owner (i.e. group) does not change
    """
    pl = sequence.get('packing_list_list')[-1]
    pl.edit(destination_section_value = self.getOrganisationModule()['Ab1'])
    pl.contentValues()[0].edit(**self.account_dict)
887

Guillaume Michon's avatar
Guillaume Michon committed
888 889 890 891 892 893 894
  def stepChangeCurrentPackingListDestinationSectionForActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
    """
    Change the destination section of the packing list in order to make the actual owner (i.e. group) change
    """
    pl = sequence.get('packing_list_list')[-1]
    pl.edit(destination_section_value = self.getOrganisationModule()['Ba'])
    pl.contentValues()[0].edit(**self.account_dict)
895

896 897 898
  """
  TEST 17
  """
Guillaume Michon's avatar
Guillaume Michon committed
899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925
  def stepCreatePackingListsForMonthlyAmortisationTest(self, sequence=None, sequence_list=None, **kw):
    """
    Create a list of packing lists describing a continuous period list :
    2000/01/01 : immobilisation (1)
    2002/03/01 : immobilisation (2), owner does not change
    2002/04/16 : immobilisation (3), owner does not change
    2002/05/16 : immobilisation (3), owner changes
    2002/06/16 : immobilisation (4), actual owner changes
    """
    item = sequence.get('item')
    amortisation_method = sequence.get('amortisation_method')
    parameter_dict = sequence.get('parameter_dict', {})
    parameter_dict.update(self.account_dict)
    parameter_dict.update(self.monthly_dict)
    parameter_dict.update( {'amortisation_method':amortisation_method,
                            'amortisation_start_price':9000,
                            'disposal_price':1000,
                            'amortisation_duration':36,
                            'immobilisation_vat':1000,
                            'extra_cost_price':2000,
                          } )
    sequence.edit(item_list_list = [[item]],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa1"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
926
    self.stepDeliverPackingList(sequence=sequence)
927 928
    get_transaction().commit()
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
929 930 931 932 933 934 935 936 937 938 939
    for property in ('amortisation_start_price','amortisation_duration','immobilisation_vat',
                     'extra_cost_price','disposal_price'):
      del parameter_dict[property]
    for property in self.account_dict.keys():
      del parameter_dict[property]
    parameter_dict.update(self.extra_monthly_dict)
    sequence.edit(datetime = DateTime('2002/03/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Aa2"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
940
    self.stepDeliverPackingList(sequence=sequence)
941 942
    get_transaction().commit()
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
943 944 945 946 947
    parameter_dict.update(self.monthly_dict)
    sequence.edit(datetime = DateTime('2002/04/16'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
948
    self.stepDeliverPackingList(sequence=sequence)
949 950
    get_transaction().commit()
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
951 952 953 954 955
    sequence.edit(datetime = DateTime('2002/05/16'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Ab1"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
956
    self.stepDeliverPackingList(sequence=sequence)
957 958
    get_transaction().commit()
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
959 960 961 962 963
    sequence.edit(datetime = DateTime('2002/06/16'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Ba"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
964
    self.stepDeliverPackingList(sequence=sequence)
965 966 967
    get_transaction().commit()
    self.tic()

Guillaume Michon's avatar
Guillaume Michon committed
968 969 970 971 972
  def stepBuildAccounting(self, sequence=None, sequence_list=None, **kw):
    """
    Build completely accounting
    """
    self.stepPartialBuildAccounting(sequence=sequence, sequence_list=sequence_list, build_parameter_dict={}, **kw)
973

Guillaume Michon's avatar
Guillaume Michon committed
974 975 976 977 978 979 980
  def stepPartialBuildAccounting(self, sequence=None, sequence_list=None, build_parameter_dict=None, **kw):
    """
    Build a part of the simulation according to sequence data
    """
    if build_parameter_dict is None:
      build_parameter_dict = sequence.get('build_parameter_dict',{})
    self.getPortal().AccountingTransactionModule_activateBuildAmortisationTransaction(**build_parameter_dict)
981

Guillaume Michon's avatar
Guillaume Michon committed
982 983 984 985 986 987 988
  def stepAdoptPrevision(self,sequence=None, sequence_list=None, **kw):
    """
    Launch adopt_prevision() on each Amortisation Transaction
    """
    for transaction in self.getAccountingModule().contentValues():
      if hasattr(transaction, 'adoptPrevision'):
        transaction.adoptPrevision()
989
        #LOG('Launched adoptPrevision() for transaction', 0, transaction.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
990
      else:
991 992 993
        pass
        #LOG('Cannot launch adoptPrevision() for transaction', 0, transaction.getRelativeUrl())

Guillaume Michon's avatar
Guillaume Michon committed
994 995 996 997 998
  def stepAcceptDecision(self, sequence=None, sequence_list=None, **kw):
    """
    Launch accept_decision() on each Amortisation Transaction
    """
    for transaction in self.getAccountingModule().contentValues():
999
      #LOG('transaction %s causality state :' % transaction, 0, transaction.getCausalityState())
Guillaume Michon's avatar
Guillaume Michon committed
1000 1001 1002 1003
      try:
        self.getPortal().portal_workflow.doActionFor(transaction,
                                                     'accept_decision_action',
                                                     'amortisation_transaction_causality_workflow')
1004
        #LOG('Launched acceptDecision() for transaction', 0, transaction.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1005
      except:
1006 1007 1008
        pass
        #LOG('Cannot launch acceptDecision() for transaction', 0, transaction.getRelativeUrl())

Guillaume Michon's avatar
Guillaume Michon committed
1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021
  def stepChangeAccountingPrice(self, sequence=None, sequence_list=None, **kw):
    """
    Modify a price on an accounting line
    """
    found = 0
    transaction_list = self.getAccountingModule().contentValues()
    for transaction in transaction_list:
      if transaction.getStopDate() == DateTime('2000/01/01'):
        for line in transaction.contentValues():
          if line.getSource() == self.account_dict['input_account'] and \
             line.getQuantity() == 10000 and not found:
            found = 1
            line.edit(quantity=15000)
1022

Guillaume Michon's avatar
Guillaume Michon committed
1023 1024 1025 1026 1027
  def stepTestAllAppliedRulesAreEmpty(self, sequence=None, sequence_list=None, **kw):
    """
    Test if all applied rules are empty
    """
    for item in self.getItemModule().contentValues():
1028 1029
      applied_rule_list = item.getCausalityRelatedValueList()
      for applied_rule in applied_rule_list:
Guillaume Michon's avatar
Guillaume Michon committed
1030
        self.assertEquals(len(applied_rule.contentValues()), 0)
1031

Guillaume Michon's avatar
Guillaume Michon committed
1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063
  def stepTestLinearAmortisationImmobilisationPeriods(self, sequence=None, sequence_list=None, **kw):
    """
    Test calculated immobilisation periods
    """
    item = sequence.get('item')
    c_period_list = item.getImmobilisationPeriodList()
    e_period_list = [ { 'start_date':DateTime('2000/01/01'), 'stop_date':DateTime('2001/01/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2001/01/01'), 'stop_date':DateTime('2002/01/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':12000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':48,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2002/01/01'), 'stop_date':DateTime('2002/07/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':0, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':None,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2002/07/01'), 'stop_date':DateTime('2002/10/01'),
                        'initial_date':DateTime('2002/07/01'),
                        'owner':self.getOrganisationModule()["B"],
                        'initial_price':5833.33, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':42,
                        'initial_duration':42 },
                    ]
    self._testImmobilisationPeriods(c_period_list, e_period_list)
1064

Guillaume Michon's avatar
Guillaume Michon committed
1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091
        
  def stepTestLinearAmortisationImmobilisationPeriodsUncontinuous(self, sequence=None, sequence_list=None, **kw):
    """
    Test calculated immobilisation periods
    """
    item = sequence.get('item')
    c_period_list = item.getImmobilisationPeriodList()
    e_period_list = [ { 'start_date':DateTime('2000/01/01'), 'stop_date':DateTime('2001/01/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2003/01/01'), 'stop_date':DateTime('2004/01/01'),
                        'initial_date':DateTime('2003/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["B"],
                        'initial_price':10000, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2004/01/01'),
                        'initial_date':DateTime('2004/01/01'),
                        'owner':self.getOrganisationModule()["A"],
                        'initial_price':8333.33, 'start_method':'eu/linear',
                        'initial_method':'eu/linear', 'start_duration':60,
                        'initial_duration':60 },
                    ]
    self._testImmobilisationPeriods(c_period_list, e_period_list)
1092

Guillaume Michon's avatar
Guillaume Michon committed
1093 1094
            
  def stepTestDegressiveAmortisationImmobilisationPeriods(self, sequence=None, sequence_list=None, **kw):
1095
    """
Guillaume Michon's avatar
Guillaume Michon committed
1096
    Test calculated immobilisation periods
1097
    """
Guillaume Michon's avatar
Guillaume Michon committed
1098 1099
    item = sequence.get('item')
    c_period_list = item.getImmobilisationPeriodList()
1100
    
Guillaume Michon's avatar
Guillaume Michon committed
1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120
    e_period_list = [ { 'start_date':DateTime('2000/01/01'), 'stop_date':DateTime('2001/01/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2001/01/01'), 'stop_date':DateTime('2002/07/01'),
                        'initial_date':DateTime('2001/01/01'),
                        'start_price':12000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':12000, 'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':48,
                        'initial_duration':48 },
                      { 'start_date':DateTime('2002/07/01'), 'stop_date':DateTime('2002/10/01'),
                        'initial_date':DateTime('2002/07/01'),
                        'start_price':4500, 'owner':self.getOrganisationModule()["B"],
                        'initial_price':4500, 'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':30,
                        'initial_duration':30 },
                    ]
    self._testImmobilisationPeriods(c_period_list, e_period_list)
1121
      
Guillaume Michon's avatar
Guillaume Michon committed
1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148

  def stepTestDegressiveAmortisationImmobilisationPeriodsUncontinuous(self, sequence=None, sequence_list=None, **kw):
    """
    Test calculated immobilisation periods
    """
    item = sequence.get('item')
    c_period_list = item.getImmobilisationPeriodList()
    e_period_list = [ { 'start_date':DateTime('2000/01/01'), 'stop_date':DateTime('2001/01/01'),
                        'initial_date':DateTime('2000/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["A"],
                        'initial_price':10000, 'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2003/01/01'), 'stop_date':DateTime('2004/01/01'),
                        'initial_date':DateTime('2003/01/01'),
                        'start_price':10000, 'owner':self.getOrganisationModule()["B"],
                        'initial_price':10000, 'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':72,
                        'initial_duration':72 },
                      { 'start_date':DateTime('2004/01/01'),
                        'initial_date':DateTime('2004/01/01'),
                        'owner':self.getOrganisationModule()["A"],
                        'start_method':'fr/uncontinuous_degressive',
                        'initial_method':'fr/uncontinuous_degressive', 'start_duration':60,
                        'initial_duration':60 },
                    ]
    self._testImmobilisationPeriods(c_period_list, e_period_list)
1149

Guillaume Michon's avatar
Guillaume Michon committed
1150
  def _testImmobilisationPeriods(self,c_period_list,e_period_list):
1151
    #LOG('c_period_list :', 0, c_period_list)
Guillaume Michon's avatar
Guillaume Michon committed
1152 1153
    e_period_cursor = 0
    for c_period in c_period_list:
1154
      #LOG('c_period :', 0, c_period)
Guillaume Michon's avatar
Guillaume Michon committed
1155 1156 1157
      if e_period_cursor >= len(e_period_list):
        self.assertEquals(len(c_period_list), len(e_period_list))
      e_period = e_period_list[e_period_cursor]
1158
      #LOG('e_period :', 0, e_period)
Guillaume Michon's avatar
Guillaume Michon committed
1159 1160 1161
      e_period_cursor += 1
      for key in e_period.keys():
        e_value = e_period[key]
1162
        #LOG('testing c_period %s "%s" value' % (e_period_cursor-1, key), 0, '')
Guillaume Michon's avatar
Guillaume Michon committed
1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
        self.failUnless(c_period.has_key(key))
        c_value = c_period[key]
        is_float = 0
        try:
          if type(c_value) != type(DateTime()):
            c_value=float(c_value)
            is_float = 1
        except:
          pass
        if is_float:
          self.assertEquals(round(c_value,2),e_value)
        else:
          self.assertEquals(c_value,e_value)
    if e_period_cursor != len(e_period_list):
      self.assertEquals(len(c_period_list), len(e_period_list))


  def stepTestLinearAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1181
    """
Guillaume Michon's avatar
Guillaume Michon committed
1182
    Test calculated prices
1183
    """
Guillaume Michon's avatar
Guillaume Michon committed
1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 8333.33),
           (DateTime('2002/01/01'), 6666.67),
           (DateTime('2003/01/01'), 5000),
           (DateTime('2003/02/01'), 4861.11),
           (DateTime('2003/02/16'), 4791.67),
           (DateTime('2004/01/01'), 3333.33),
           (DateTime('2005/01/01'), 1666.67),
           (DateTime('2006/01/01'), 0),
           (DateTime('2020/01/01'), 0),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
1198 1199
      #LOG('testing amortisation price at date', 0, date)
      #LOG('c_price',0,c_price)
Guillaume Michon's avatar
Guillaume Michon committed
1200
      self.assertEquals(round(c_price,2), e_price)
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225
  
  """
  09BIS
  """
  def stepTestLinearAmortisationPriceCalculationBIS(self, sequence=None, sequence_list=None, **kw):
    """
    Test calculated prices
    """
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 8750.00),
           (DateTime('2002/01/01'), 6250.00),
           (DateTime('2003/01/01'), 3750.00),
           (DateTime('2003/12/31'), 1250.00),
           (DateTime('2004/01/01'), 1243.17),
           (DateTime('2005/01/01'), 0),
           (DateTime('2006/01/01'), 0),
           (DateTime('2020/01/01'), 0),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
      #LOG('testing amortisation price at date', 0, date)
      #LOG('c_price',0,c_price)
      self.assertEquals(round(c_price,2), e_price)

Guillaume Michon's avatar
Guillaume Michon committed
1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243
  def stepTestDegressiveAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
    """
    Test calculated prices
    """
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 6666.67),
           (DateTime('2002/01/01'), 4444.44),
           (DateTime('2003/01/01'), 2962.96),
           (DateTime('2003/02/01'), 2880.66),
           (DateTime('2003/02/16'), 2839.51),
           (DateTime('2004/01/01'), 1975.31),
           (DateTime('2005/01/01'), 987.65),
           (DateTime('2006/01/01'), 0),
           (DateTime('2020/01/01'), 0),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
1244
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1245
      self.assertEquals(round(c_price,2), e_price)
1246
      
Guillaume Michon's avatar
Guillaume Michon committed
1247 1248
    
  def stepTestUncontinuousDegressiveAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1249
    """
Guillaume Michon's avatar
Guillaume Michon committed
1250
    Test calculated prices
1251
    """
Guillaume Michon's avatar
Guillaume Michon committed
1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 6666.67),
           (DateTime('2002/01/01'), 4444.44),
           (DateTime('2003/01/01'), 2962.96),
           (DateTime('2003/02/01'), 2880.66),
           (DateTime('2003/02/16'), 2839.51),
           (DateTime('2004/01/01'), 9857.14),
           (DateTime('2005/01/01'), 6336.73),
           (DateTime('2006/01/01'), 4073.62),
           (DateTime('2020/01/01'), 0.),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
1266
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1267
      self.assertEquals(round(c_price,2), e_price)
1268 1269
      
    
Guillaume Michon's avatar
Guillaume Michon committed
1270
  def stepTestActualUseAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1271
    """
Guillaume Michon's avatar
Guillaume Michon committed
1272
    Test calculated prices
1273
    """
Guillaume Michon's avatar
Guillaume Michon committed
1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 7428.57),
           (DateTime('2002/01/01'), 4857.14),
           (DateTime('2003/01/01'), 2285.71),
           (DateTime('2003/02/01'), 2071.43),
           (DateTime('2003/02/16'), 1964.29),
           (DateTime('2003/07/01'), 1000.00),
           (DateTime('2004/01/01'), 800),
           (DateTime('2005/01/01'), 400),
           (DateTime('2006/01/01'), 0),
           (DateTime('2020/01/01'), 0),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
1289
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1290 1291
      self.assertEquals(round(c_price,2), e_price)
      
1292
    
Guillaume Michon's avatar
Guillaume Michon committed
1293
  def stepTestNoAmortisationMethodPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1294
    """
Guillaume Michon's avatar
Guillaume Michon committed
1295
    Test calculated prices
1296
    """
Guillaume Michon's avatar
Guillaume Michon committed
1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310
    item = sequence.get('item')
    price_list = [
           (DateTime('2001/01/01'), 10000),
           (DateTime('2002/01/01'), 10000),
           (DateTime('2003/01/01'), 10000),
           (DateTime('2003/02/01'), 10000),
           (DateTime('2003/02/16'), 10000),
           (DateTime('2004/01/01'), 12000),
           (DateTime('2005/01/01'), 12000),
           (DateTime('2006/01/01'), 12000),
           (DateTime('2020/01/01'), 12000),
           ]
    for date, e_price in price_list:
      c_price = item.getAmortisationPrice(at_date=date)
1311
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1312 1313 1314 1315 1316
      self.assertEquals(round(c_price,2), e_price)
      
  
  def _createExpectedMovement(self, date, quantity, source=None, destination=None,
                              source_section=None, destination_section=None):
1317 1318
    self.id_simulation+=1
    r_dict = {'id':self.id_simulation,'start_date':DateTime(date), 'stop_date':DateTime(date), 
Guillaume Michon's avatar
Guillaume Michon committed
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328
              'quantity':quantity, 'resource':'currency_module/EUR'}
    my_account_dict = dict(self.account_dict)
    my_account_dict.update(self.monthly_dict)
    my_extra_account_dict = dict(self.extra_account_dict)
    my_extra_account_dict.update(self.extra_monthly_dict)
    for name, prop in (('source',source), ('destination',destination)):
      if prop is None:
        r_dict[name] = None
      elif prop.split('_')[-1] == 'extra':
        r_dict[name] = my_extra_account_dict['_'.join(prop.split('_')[:-1])]
1329
      else:
Guillaume Michon's avatar
Guillaume Michon committed
1330 1331 1332 1333 1334 1335 1336
        r_dict[name] = my_account_dict[prop]
    for name, prop in (('source_section_value', source_section), ('destination_section_value', destination_section)):
      if prop is None:
        r_dict[name] = None
      else:
        r_dict[name] = self.getOrganisationModule()[prop]
    return r_dict
1337

Guillaume Michon's avatar
Guillaume Michon committed
1338 1339
        
  def stepTestLinearAmortisationSimulationBuild(self, sequence=None, sequence_list=None, **kw):
1340
    """
1341
    Test 09
Guillaume Michon's avatar
Guillaume Michon committed
1342
    Test built simulation for linear amortisation
1343
    """
Guillaume Michon's avatar
Guillaume Michon committed
1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -1666.67, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -1666.67, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -1666.67, 'depreciation_account', None, 'A', None))
1364 1365 1366 1367
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2004/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2004/01/01', -1666.67, 'depreciation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 833.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -833.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 833.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -833.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2005/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2005/01/01', -1666.67, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2006/01/01', 1666.67, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2006/01/01', -1666.67, 'depreciation_account', None, 'A', None))
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1385
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1386 1387 1388 1389
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
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 1430 1431 1432 1433 1434
  """
  09BIS
  """
  def stepTestLinearAmortisationSimulationBuildBIS(self, sequence=None, sequence_list=None, **kw):
    """
    Test built simulation for linear amortisation
    """
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/07/01', 10000, 'input_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/07/01', -10000, 'immobilisation_account', None, 'orga', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/12/31', 1250.00, 'amortisation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/12/31', -1250.00, 'depreciation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/12/31', 2500.00, 'amortisation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/12/31', -2500.00, 'depreciation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/12/31', 2500.00, 'amortisation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/12/31', -2500.00, 'depreciation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/12/31', 2500.00, 'amortisation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/12/31', -2500.00, 'depreciation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/12/31', 1250.00, 'amortisation_account', None, 'orga', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/12/31', -1250.00, 'depreciation_account', None, 'orga', None))


    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
Guillaume Michon's avatar
Guillaume Michon committed
1435
  def stepTestUncontinuousDegressiveAmortisationSimulationBuild(self, sequence=None, sequence_list=None, **kw):
1436
    """
Guillaume Michon's avatar
Guillaume Michon committed
1437
    Test built simulation for uncontinuous degressive amortisation
1438
    """
Guillaume Michon's avatar
Guillaume Michon committed
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2222.22, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2222.22, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 1481.48, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -1481.48, 'depreciation_account', None, 'A', None))
1459 1460 1461 1462
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2004/01/01', 987.65, 'amortisation_account', None, 'A', None))
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2004/01/01', -987.65, 'depreciation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1463 1464 1465 1466
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 493.83, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -493.83, 'depreciation_account', None, 'A', None))
1467
    #Unimmobilisation
Guillaume Michon's avatar
Guillaume Michon committed
1468 1469
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -7530.86, 'amortisation_account', None, 'A', None))
1470 1471
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2003/07/01', -8024.67, 'amortisation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1472 1473 1474 1475
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', 10000, 'immobilisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -2469.14, 'output_account', None, 'A', None))
1476 1477
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2003/07/01', -1975.33, 'output_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511
    # New immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', 12000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -12000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2142.86, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2142.86, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2005/01/01', 3520.41, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2005/01/01', -3520.41, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2006/01/01', 2263.12, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2006/01/01', -2263.12, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2007/01/01', 1454.86, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2007/01/01', -1454.86, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2008/01/01', 935.27, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2008/01/01', -935.27, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2009/01/01', 841.74, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2009/01/01', -841.74, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2010/01/01', 841.74, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2010/01/01', -841.74, 'depreciation_account', None, 'A', None))
1512
    
Guillaume Michon's avatar
Guillaume Michon committed
1513
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1514
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1515 1516 1517 1518 1519 1520 1521
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
  
  def stepTestNoAmortisationMethodSimulationBuild(self, sequence=None, sequence_list=None, **kw):
1522
    """
Guillaume Michon's avatar
Guillaume Michon committed
1523
    Test built simulation for no amortisation method
1524
    """
Guillaume Michon's avatar
Guillaume Michon committed
1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # No annuity
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', 10000, 'immobilisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -10000, 'output_account', None, 'A', None))
    # New immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', 12000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -12000, 'immobilisation_account', None, 'A', None))
    # No annuity
1544
    
Guillaume Michon's avatar
Guillaume Michon committed
1545
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1546
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1547 1548 1549 1550 1551 1552 1553
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
  
  def stepTestSimulationBuildForContinuousMethodWithoutOwnerChange(self, sequence=None, sequence_list=None, **kw):
1554
    """
Guillaume Michon's avatar
Guillaume Michon committed
1555
    Test built simulation for a linear amortisation method without owner change
1556
    """
Guillaume Michon's avatar
Guillaume Michon committed
1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    # Account transfer
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account_extra', 'amortisation_account', 'Aa', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -10000, 'immobilisation_account_extra', 'immobilisation_account', 'Aa', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account_extra', 'depreciation_account', 'Aa', 'Aa'))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account_extra', None, 'Aa', None))
1589
    
Guillaume Michon's avatar
Guillaume Michon committed
1590
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1591
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1592 1593 1594 1595
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1596
    
Guillaume Michon's avatar
Guillaume Michon committed
1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631
  
  def stepTestSimulationBuildForContinuousMethodWithOwnerChange(self, sequence=None, sequence_list=None, **kw):
    """
    Test built simulation for a linear amortisation method with owner change but no actual owner (ie group) change
    """
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    # Account transfer
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', 'amortisation_account', 'Ab', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -10000, 'immobilisation_account', 'immobilisation_account', 'Ab', 'Aa'))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account', None, 'Ab', None))
1632
    
Guillaume Michon's avatar
Guillaume Michon committed
1633
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1634
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1635 1636 1637 1638
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1639
    
1640
  
Guillaume Michon's avatar
Guillaume Michon committed
1641
  def stepTestSimulationBuildForContinuousMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1642
    """
Guillaume Michon's avatar
Guillaume Michon committed
1643
    Test built simulation for a linear amortisation method with actual owner change (ie group)
1644
    """
Guillaume Michon's avatar
Guillaume Michon committed
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 1674 1675 1676 1677 1678 1679 1680 1681 1682
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'output_account', None, 'Aa', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 6666.67, 'input_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'immobilisation_account', None, 'Ba', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account', None, 'Ba', None))
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1683
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1684 1685 1686 1687
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1688

Guillaume Michon's avatar
Guillaume Michon committed
1689
  def stepTestSimulationBuildForUncontinuousMethodWithoutOwnerChange(self, sequence=None, sequence_list=None, **kw):
1690
    """
Guillaume Michon's avatar
Guillaume Michon committed
1691
    Test built simulation for a uncontinuous degressive amortisation method without owner change
1692
    """
Guillaume Michon's avatar
Guillaume Michon committed
1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'depreciation_account', None, 'Aa', None))
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'output_account', None, 'Aa', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 12000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -12000, 'immobilisation_account_extra', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 8000, 'amortisation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -8000, 'depreciation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2666.67, 'amortisation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2666.67, 'depreciation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 1333.33, 'amortisation_account_extra', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -1333.33, 'depreciation_account_extra', None, 'Aa', None))
1734
    
Guillaume Michon's avatar
Guillaume Michon committed
1735
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1736
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1737 1738 1739 1740
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1741
    
Guillaume Michon's avatar
Guillaume Michon committed
1742 1743
  
  def stepTestSimulationBuildForUncontinuousMethodWithOwnerChange(self, sequence=None, sequence_list=None, **kw):
1744
    """
Guillaume Michon's avatar
Guillaume Michon committed
1745
    Test built simulation for a uncontinuous degressive amortisation method with owner change but no actual owner change
1746
    """
Guillaume Michon's avatar
Guillaume Michon committed
1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'depreciation_account', None, 'Aa', None))
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'output_account', None, 'Aa', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 12000, 'input_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -12000, 'immobilisation_account', None, 'Ab', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 8000, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -8000, 'depreciation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2666.67, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2666.67, 'depreciation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 1333.33, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -1333.33, 'depreciation_account', None, 'Ab', None))
    
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1790
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1791 1792 1793 1794 1795
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
1796
    
Guillaume Michon's avatar
Guillaume Michon committed
1797
  def stepTestSimulationBuildForUncontinuousMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1798
    """
Guillaume Michon's avatar
Guillaume Michon committed
1799
    Test built simulation for a uncontinuous degressive amortisation method with actual owner change
1800
    """
Guillaume Michon's avatar
Guillaume Michon committed
1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'depreciation_account', None, 'Aa', None))
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'output_account', None, 'Aa', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 12000, 'input_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -12000, 'immobilisation_account', None, 'Ba', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 8000, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -8000, 'depreciation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2666.67, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2666.67, 'depreciation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 1333.33, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -1333.33, 'depreciation_account', None, 'Ba', None))
1842
    
Guillaume Michon's avatar
Guillaume Michon committed
1843
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1844
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1845 1846 1847 1848 1849 1850 1851
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
        
  
  def stepTestSimulationBuildForNoChangeMethodWithoutOwnerChange(self, sequence=None, sequence_list=None, **kw):
1852
    """
Guillaume Michon's avatar
Guillaume Michon committed
1853
    Test built simulation for a no change amortisation method without owner change
1854
    """
Guillaume Michon's avatar
Guillaume Michon committed
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
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1881
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1882 1883 1884 1885 1886
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
1887
  
Guillaume Michon's avatar
Guillaume Michon committed
1888
  def stepTestSimulationBuildForNoChangeMethodWithOwnerChange(self, sequence=None, sequence_list=None, **kw):
1889
    """
Guillaume Michon's avatar
Guillaume Michon committed
1890
    Test built simulation for a no change amortisation method with owner change but no actual owner (ie group) change
1891
    """
Guillaume Michon's avatar
Guillaume Michon committed
1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    # Account transfer
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', 'amortisation_account', 'Ab', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -10000, 'immobilisation_account', 'immobilisation_account', 'Ab', 'Aa'))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account', None, 'Ab', None))
1922
    
Guillaume Michon's avatar
Guillaume Michon committed
1923
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1924
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1925 1926 1927 1928
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1929
    
Guillaume Michon's avatar
Guillaume Michon committed
1930 1931
  
  def stepTestSimulationBuildForNoChangeMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1932
    """
Guillaume Michon's avatar
Guillaume Michon committed
1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971
    Test built simulation for a no change amortisation method with actual owner change (ie group)
    """
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 9000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 10000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'output_account', None, 'Aa', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 6666.67, 'input_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -6666.67, 'immobilisation_account', None, 'Ba', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 3333.33, 'amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -3333.33, 'depreciation_account', None, 'Ba', None))
1972
    
Guillaume Michon's avatar
Guillaume Michon committed
1973
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1974
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1975 1976 1977 1978
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
1979
    
1980 1981 1982
  """
  TEST 17
  """
Guillaume Michon's avatar
Guillaume Michon committed
1983 1984 1985 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 2045 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
  def stepTestSimulationBuildForMonthlyAmortisation(self, sequence=None, sequence_list=None, **kw):
    """
    Test built simulation for a linear amortisation method with a monthly amortisation
    """
    def createMonthlyAnnuityList(start_date, stop_date, month_value, account, section):
      return_list = []
      current_date = start_date
      while DateTime(current_date) <= DateTime(stop_date):
        return_list.append(self._createExpectedMovement(
              current_date, month_value, account, None, section, None))
        year, month, day = [int(x) for x in current_date.split('/')]
        month += 1
        if month == 13:
          month = 1
          year += 1
        current_date = '%s/%s/%s' % (year, month, day)
      return return_list
        
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation 2000/01/01
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 2000, 'extra_cost_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -11000, 'immobilisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -1000, 'immobilisation_vat_account', None, 'Aa', None))
    # Annuities
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2000/02/01', '2001/01/01', 277.78, 'amortisation_account', 'Aa'))  # 3333.33/12
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2000/02/01', '2001/01/01', -277.78, 'monthly_amortisation_account', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 3333.33, 'monthly_amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2001/02/01', '2002/01/01', 277.78, 'amortisation_account', 'Aa'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2001/02/01', '2002/01/01', -277.78, 'monthly_amortisation_account', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 3333.33, 'monthly_amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -3333.33, 'depreciation_account', None, 'Aa', None))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/02/01', '2002/03/01', 277.78, 'amortisation_account', 'Aa'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/02/01', '2002/03/01', -277.78, 'monthly_amortisation_account', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 555.56, 'monthly_amortisation_account', None, 'Aa', None)) # 3333.33/6
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -555.56, 'depreciation_account', None, 'Aa', None))
    # Optional transfer 2002/03/01
    # Annuities
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/04/01', '2002/04/16', 277.78, 'amortisation_account', 'Aa'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/04/01', '2002/04/16', -277.78, 'monthly_amortisation_account_extra', 'Aa'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/05/01', '2002/05/01', 138.89, 'amortisation_account', 'Aa')) # 277.78 / 2
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/05/01', '2002/05/01', -138.89, 'monthly_amortisation_account_extra', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 416.67, 'monthly_amortisation_account_extra', None, 'Aa', None)) # 277.78 * 1.5
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -416.67, 'depreciation_account', None, 'Aa', None))
    # Optional transfer 2002/04/16
    # Annuities
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/05/01', '2002/06/01', 138.89, 'amortisation_account', 'Aa')) # 277.78 / 2
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/05/01', '2002/06/01', -138.89, 'monthly_amortisation_account', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 277.78, 'monthly_amortisation_account', None, 'Aa', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -277.78, 'depreciation_account', None, 'Aa', None))
    # Account transfer 2002/05/16
    e_simulation_movement_list.append(self._createExpectedMovement( # 6666.67 + 277.78 * 4.5
              '2002/05/16', 7916.67, 'amortisation_account', 'amortisation_account', 'Ab', 'Aa'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/05/16', -11000, 'immobilisation_account', 'immobilisation_account', 'Ab', 'Aa'))
    # Annuities
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/06/01', '2002/07/01', 138.89, 'amortisation_account', 'Ab'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/06/01', '2002/07/01', -138.89, 'monthly_amortisation_account', 'Ab'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 277.78, 'monthly_amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -277.78, 'depreciation_account', None, 'Ab', None))
    # Unimmobilisation 2002/06/16
    e_simulation_movement_list.append(self._createExpectedMovement( # 6666.67 + 277.78 * 5.5
              '2002/06/16', -8194.44, 'amortisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/06/16', 11000, 'immobilisation_account', None, 'Ab', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/06/16', -2805.56, 'output_account', None, 'Ab', None))
    # New immobilisation for new owner 2002/06/16
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/06/16', 2805.56, 'input_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/06/16', -2805.56, 'immobilisation_account', None, 'Ba', None))
    # Annuities
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/07/01', '2002/07/01', 150.46, 'amortisation_account', 'Ba')) # (1805.56 / 6) / 2
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/07/01', '2002/07/01', -150.46, 'monthly_amortisation_account', 'Ba'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/08/01', '2002/12/01', 300.93, 'amortisation_account', 'Ba')) # 1805.56 / 6
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2002/08/01', '2002/12/01', -300.93, 'monthly_amortisation_account', 'Ba'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2003/01/01', '2003/01/01', 150.46, 'amortisation_account', 'Ba'))
    e_simulation_movement_list.extend(createMonthlyAnnuityList(
              '2003/01/01', '2003/01/01', -150.46, 'monthly_amortisation_account', 'Ba'))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 1805.56, 'monthly_amortisation_account', None, 'Ba', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -1805.56, 'depreciation_account', None, 'Ba', None))
2104

Guillaume Michon's avatar
Guillaume Michon committed
2105
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2106
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
2107 2108
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
Guillaume Michon's avatar
Guillaume Michon committed
2109 2110
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2111 2112


Guillaume Michon's avatar
Guillaume Michon committed
2113 2114
  def _testSimulationBuild(self, c_simulation_movement_list, e_simulation_movement_list):
    for c_movement in c_simulation_movement_list:
2115 2116 2117 2118 2119 2120 2121
      #LOG('c_movement %s :' % c_movement, 0, 
       #'date=%s\n, source=%s\n, source_section=%s\n, destination=%s\n, destination_section=%s\n, quantity=%s\n, resource=%s\n, profit_quantity=%s\n' % (
          #(c_movement.getStopDate(), c_movement.getSource(), c_movement.getSourceSection(),
           #c_movement.getDestination(), c_movement.getDestinationSection(), c_movement.getQuantity(),
           #c_movement.getResource(), c_movement.getProfitQuantity())
         #)
      #)
Guillaume Michon's avatar
Guillaume Michon committed
2122 2123 2124 2125 2126 2127 2128
      e_found_movement = None
      e_cursor = 0
      while e_cursor < len(e_simulation_movement_list) and e_found_movement is None:
        e_movement = e_simulation_movement_list[e_cursor]
        wrong_movement = 0
        key_cursor = 0
        key_list = e_movement.keys()
2129
        key_list.remove('id')
Guillaume Michon's avatar
Guillaume Michon committed
2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143
        while key_cursor < len(key_list) and not wrong_movement:
          key = key_list[key_cursor]
          e_value = e_movement[key]
          key = 'get' + ''.join([k.capitalize() for k in key.split('_')])
          c_value = getattr(c_movement,key)()
          is_float = 0
          try:
            if type(c_value) != type(DateTime()):
              c_value=float(c_value)
              is_float = 1
          except:
            pass
          if is_float:
            wrong_movement = (round(c_value,2) != round(e_value,2))
2144
          else:
Guillaume Michon's avatar
Guillaume Michon committed
2145
            wrong_movement = (c_value != e_value)
2146 2147 2148
          if wrong_movement:
            LOG('_testSimulationBuild',0,'key:%s, c_value:%s e_value:%s ' % (key, c_value,e_value))
          key_cursor += 1
Guillaume Michon's avatar
Guillaume Michon committed
2149 2150 2151
        if not wrong_movement:
          e_found_movement = e_movement
        e_cursor += 1
2152
        #LOG('_testSimulationBuild',0,'wrong movement %s' % wrong_movement)
Guillaume Michon's avatar
Guillaume Michon committed
2153
      if e_found_movement is None:
2154
        self.fail('No expected movement found for %s' % (c_movement.getRelativeUrl()))
Guillaume Michon's avatar
Guillaume Michon committed
2155 2156
      e_simulation_movement_list.remove(e_found_movement)
    if len(e_simulation_movement_list) > 0:
2157
      #LOG('More expected movements than calculated ! Remaining expected ones are', 0, e_simulation_movement_list)
Guillaume Michon's avatar
Guillaume Michon committed
2158
      self.assertEquals(len(e_simulation_movement_list),0)
2159

Guillaume Michon's avatar
Guillaume Michon committed
2160
  def _buildExpectedTransaction(self, date, source_section, destination_section, causality_state, causality_list=[]):
2161 2162
    self.id_transaction+=1
    r_dict = {'id':self.id_transaction,'start_date':DateTime(date), 'stop_date':DateTime(date), 
Guillaume Michon's avatar
Guillaume Michon committed
2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175
              'resource':'currency_module/EUR', 'line_list':[],
              'causality_state':causality_state}
    for name, prop in (('source_section_value', source_section), ('destination_section_value', destination_section)):
      if prop is None:
        r_dict[name] = None
      else:
        r_dict[name] = self.getOrganisationModule()[prop]
    causality_value_list = []
    for causality in causality_list:
      causality_value_list.append(self.getItemModule()[causality])
    if len(causality_value_list) != 0:
      r_dict['causality_value_list'] = causality_value_list
    return r_dict
2176

Guillaume Michon's avatar
Guillaume Michon committed
2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192
  def _buildExpectedTransactionLine(self, source, destination, quantity):
    r_dict = {'quantity':quantity}
    my_account_dict = dict(self.account_dict)
    my_account_dict.update(self.monthly_dict)
    my_extra_account_dict = dict(self.extra_account_dict)
    my_extra_account_dict.update(self.extra_monthly_dict)
    for name, prop in (('source',source), ('destination',destination)):
      if prop is None:
        r_dict[name] = None
      elif prop.split('_')[-1] == 'extra':
        r_dict[name] = my_extra_account_dict['_'.join(prop.split('_')[:-1])]
      else:
        r_dict[name] = my_account_dict[prop]
    return r_dict

  def stepTestPartialAccountingBuild(self, sequence=None, sequence_list=None, **kw):
2193
    """
Guillaume Michon's avatar
Guillaume Michon committed
2194 2195
    Test partial accounting build, based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01, and partial build is done with at_date=2002/01/01 and items = 1 & 2
2196
    """
Guillaume Michon's avatar
Guillaume Michon committed
2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209
    e_transaction_list = []
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1','item2'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,20000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-20000)]
    e_transaction_list.append(transaction)
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1','item2'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,5000),
                                self._buildExpectedTransactionLine('depreciation_account',None,-5000)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.solved,['item1','item2'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,5000),
                                self._buildExpectedTransactionLine('depreciation_account',None,-5000)]
    e_transaction_list.append(transaction)
2210
    
Guillaume Michon's avatar
Guillaume Michon committed
2211 2212 2213 2214 2215 2216
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
    
    
  def stepTestMultiItemAccountingBuild(self, sequence=None, sequence_list=None, **kw):
2217
    """
Guillaume Michon's avatar
Guillaume Michon committed
2218 2219
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 3 items, with complete build
2220
    """
Guillaume Michon's avatar
Guillaume Michon committed
2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241
    e_transaction_list = []
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1','item2','item3'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,30000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-30000)]
    e_transaction_list.append(transaction)
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1','item2','item3'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,7500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-7500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.solved,['item1','item2','item3'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,7500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-7500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.solved,['item1','item2','item3'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,7500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-7500)]
    e_transaction_list.append(transaction)                               
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.solved,['item1','item2','item3'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,7500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-7500)]
    e_transaction_list.append(transaction)
2242
    
Guillaume Michon's avatar
Guillaume Michon committed
2243 2244 2245 2246 2247
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    c_transaction_list.sort(lambda a,b: cmp(a.getStopDate(),b.getStopDate()))
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
2248
    
Guillaume Michon's avatar
Guillaume Michon committed
2249
  def stepTestSimpleAccountingBuild(self, sequence=None, sequence_list=None, **kw):
2250
    """
Guillaume Michon's avatar
Guillaume Michon committed
2251 2252
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build
2253
    """
Guillaume Michon's avatar
Guillaume Michon committed
2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274
    e_transaction_list = []
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,10000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-10000)]
    e_transaction_list.append(transaction)
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                               
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
2275
    
Guillaume Michon's avatar
Guillaume Michon committed
2276 2277
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
2278
    #c_transaction_list.sort(lambda a,b: cmp(a.getStopDate(),b.getStopDate()))
Guillaume Michon's avatar
Guillaume Michon committed
2279 2280
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
2281
    
Guillaume Michon's avatar
Guillaume Michon committed
2282
  def stepTestSimulationBuildAfterFirstAccountingChange(self, sequence=None, sequence_list=None, **kw):
2283
    """
Guillaume Michon's avatar
Guillaume Michon committed
2284 2285 2286
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner
2287
    """
Guillaume Michon's avatar
Guillaume Michon committed
2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Annuities set to 0 due to their link with transactions
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 0, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -0, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 0, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
2312
              '2004/01/01', -0, 'depreciation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335
    # Unimmobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -5000, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 10000, 'immobilisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -5000, 'output_account', None, 'A', None))
    # New immobilisation for new owner
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 5000, 'input_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -5000, 'immobilisation_account', None, 'B', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'B', None))
              
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2336
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2337 2338 2339 2340
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2341 2342
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2343
  def stepTestSimulationBuildAfterSecondAccountingChange(self, sequence=None, sequence_list=None, **kw):
2344
    """
Guillaume Michon's avatar
Guillaume Michon committed
2345 2346 2347 2348
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and accounting is built again.
    Then the second movement is deleted
2349
    """
Guillaume Michon's avatar
Guillaume Michon committed
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
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Annuities reset to their real value
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))              
    # Unimmobilisation, set to 0 due to their link to transactions
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -0, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'immobilisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -0, 'output_account', None, 'A', None))
    # New immobilisation for new owner, set to 0 due to their link to transactions
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'input_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -0, 'immobilisation_account', None, 'B', None))
    # Annuities, set to 0 due to their link to transactions
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 0, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -0, 'depreciation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 0, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -0, 'depreciation_account', None, 'B', None))
              
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2398
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2399 2400 2401 2402
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2403 2404
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2405
  def stepTestSimulationBuildAfterPackingListModification(self, sequence=None, sequence_list=None, **kw):
2406
    """
Guillaume Michon's avatar
Guillaume Michon committed
2407 2408 2409 2410 2411 2412
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and accounting is built again.
    Then the second movement is deleted, and the accounting is rebuilt
    Then adopt_prevision() is launched on accounting transactions
    Then the first movement is modified, setting amortisation_account to another value
2413
    """
Guillaume Michon's avatar
Guillaume Michon committed
2414 2415 2416 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 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account_extra', None, 'A', None))              
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Unimmobilisation, set to 0 before
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'immobilisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'output_account', None, 'A', None))
    # Still annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Immobilisation on B, set to 0 previously
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 0, 'input_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -0, 'immobilisation_account', None, 'B', None))
    # Annuities to B set to 0 previously
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 0, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -0, 'depreciation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 0, 'amortisation_account', None, 'B', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -0, 'depreciation_account', None, 'B', None))
    
              
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2463
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2464 2465 2466 2467 2468 2469 2470
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
    
  def stepTestAccountingBuildAfterFirstChange(self, sequence=None, sequence_list=None, **kw):
2471
    """
Guillaume Michon's avatar
Guillaume Michon committed
2472 2473 2474
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and the accounting is rebuilt
2475
    """
Guillaume Michon's avatar
Guillaume Michon committed
2476 2477 2478 2479 2480 2481 2482 2483 2484 2485
    e_transaction_list = []
    # Immobilisation
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,10000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-10000)]
    e_transaction_list.append(transaction)
    # Annuities
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
2486
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2487 2488 2489 2490 2491 2492 2493 2494
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500),
                                # Unimmobilisation
                                self._buildExpectedTransactionLine('amortisation_account',None,-5000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,10000),
                                self._buildExpectedTransactionLine('output_account',None,-5000)]
    # Annuities ; these ones are divergent
2495
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2496 2497 2498
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
2499
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
    # Immobilisation for new owner
    transaction = self._buildExpectedTransaction('2002/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,5000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-5000)]
    e_transaction_list.append(transaction)
    # Annuities
    transaction = self._buildExpectedTransaction('2003/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
2513
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524
    transaction = self._buildExpectedTransaction('2004/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
    
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
    
  def stepTestAccountingBuildAfterSecondChange(self, sequence=None, sequence_list=None, **kw):
2525
    """
Guillaume Michon's avatar
Guillaume Michon committed
2526 2527 2528 2529
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and the accounting is rebuilt
    Then the second movement is deleted and the account is built again
2530
    """
Guillaume Michon's avatar
Guillaume Michon committed
2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572
    e_transaction_list = []
    # Immobilisation
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,10000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-10000)]
    e_transaction_list.append(transaction)
    # Annuities
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500),
                                # Unimmobilisation, divergent
                                self._buildExpectedTransactionLine('amortisation_account',None,-5000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,10000),
                                self._buildExpectedTransactionLine('output_account',None,-5000)]
    # Annuities ; these ones were not solved but are now convergent again
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                               
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
    # Immobilisation for new owner, divergent
    transaction = self._buildExpectedTransaction('2002/01/01','B',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,5000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-5000)]
    e_transaction_list.append(transaction)
    # Annuities, divergent
    transaction = self._buildExpectedTransaction('2003/01/01','B',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2004/01/01','B',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
2573
    
Guillaume Michon's avatar
Guillaume Michon committed
2574 2575 2576 2577
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
2578
    
Guillaume Michon's avatar
Guillaume Michon committed
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 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636
  def stepTestAccountingBuildAfterAdoptPrevision(self, sequence=None, sequence_list=None, **kw):
    """
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and the accounting is rebuilt
    Then the second movement is deleted and the accounting is built again
    Then adopt_prevision() is launched
    """
    e_transaction_list = []
    # Immobilisation
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,10000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-10000)]
    e_transaction_list.append(transaction)
    # Annuities
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500),
                                # Unimmobilisation, set to 0 by solver
                                self._buildExpectedTransactionLine('amortisation_account',None,-0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,0),
                                self._buildExpectedTransactionLine('output_account',None,-0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,0),
                                self._buildExpectedTransactionLine('output_account',None,-0)]
    # Annuities
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)                               
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
    # Immobilisation for new owner, set to 0 by solver
    transaction = self._buildExpectedTransaction('2002/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-0),
                                self._buildExpectedTransactionLine('input_account',None,0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-0)]
    e_transaction_list.append(transaction)
    # Annuities, set to 0 by solver
    transaction = self._buildExpectedTransaction('2003/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0),
                                self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0)]
    e_transaction_list.append(transaction)                                
    transaction = self._buildExpectedTransaction('2004/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0),
                                self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0)]
    e_transaction_list.append(transaction)
2637
    
Guillaume Michon's avatar
Guillaume Michon committed
2638 2639 2640 2641 2642 2643
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
    
  def stepTestAccountingBuildAfterPackingListModification(self, sequence=None, sequence_list=None, **kw):
2644
    """
Guillaume Michon's avatar
Guillaume Michon committed
2645 2646 2647 2648 2649 2650
    Test accounting build based on a single movement of 10000 for a 4 year linear amortisation
    on the 2000/01/01 for 1 item, with complete build.
    Then a movement is added, at 2002/01/01, changing the owner, and accounting is built again.
    Then the second movement is deleted, and the accounting is rebuilt
    Then adopt_prevision() is launched on accounting transactions
    Then the first movement is modified, setting amortisation_account to another value
2651
    """
Guillaume Michon's avatar
Guillaume Michon committed
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662
    e_transaction_list = []
    # Immobilisation
    transaction = self._buildExpectedTransaction('2000/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,10000),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-10000)]
    e_transaction_list.append(transaction)
    # Annuities
    transaction = self._buildExpectedTransaction('2001/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500),
                                self._buildExpectedTransactionLine('amortisation_account_extra',None,2500)]
2663
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674
    transaction = self._buildExpectedTransaction('2002/01/01','A',None,self.diverged,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,2500),
                                self._buildExpectedTransactionLine('amortisation_account_extra',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500),
                                # Unimmobilisation
                                self._buildExpectedTransactionLine('amortisation_account',None,-0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,0),
                                self._buildExpectedTransactionLine('output_account',None,-0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,0),
                                self._buildExpectedTransactionLine('output_account',None,-0)]
    # Annuities
2675
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2676 2677 2678 2679
    transaction = self._buildExpectedTransaction('2003/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('amortisation_account_extra',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
2680
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698
    transaction = self._buildExpectedTransaction('2004/01/01','A',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('amortisation_account_extra',None,2500),
                                self._buildExpectedTransactionLine('depreciation_account',None,-2500)]
    e_transaction_list.append(transaction)
    # Immobilisation for new owner, set to 0 by solver
    transaction = self._buildExpectedTransaction('2002/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('input_account',None,0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-0),
                                self._buildExpectedTransactionLine('input_account',None,0),
                                self._buildExpectedTransactionLine('immobilisation_account',None,-0)]
    e_transaction_list.append(transaction)
    # Annuities, set to 0 by solver
    transaction = self._buildExpectedTransaction('2003/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0),
                                self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0)]
2699
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2700 2701 2702 2703 2704 2705
    transaction = self._buildExpectedTransaction('2004/01/01','B',None,self.solved,['item1'])
    transaction['line_list'] = [self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0),
                                self._buildExpectedTransactionLine('amortisation_account',None,0),
                                self._buildExpectedTransactionLine('depreciation_account',None,-0)]
    e_transaction_list.append(transaction)
2706

Guillaume Michon's avatar
Guillaume Michon committed
2707 2708 2709
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
2710

Guillaume Michon's avatar
Guillaume Michon committed
2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736
  def stepTestSimulationBuildAfterAcceptDecision(self, sequence=None, sequence_list=None, **kw):
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list[-1]['profit_quantity'] = -5000
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
2737 2738
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))

Guillaume Michon's avatar
Guillaume Michon committed
2739
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2740
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2741 2742 2743 2744
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2745 2746
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788
  def stepTestFirstSimulationBuildAfterAccountingValidation(self, sequence=None, sequence_list=None, **kw):
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Correction movements
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 833.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -833.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 833.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -833.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 833.33, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -833.33, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'depreciation_account', None, 'A', None))
2789
    
Guillaume Michon's avatar
Guillaume Michon committed
2790
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2791
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2792 2793 2794 2795
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2796 2797
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2798 2799 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 2835 2836 2837 2838 2839 2840 2841
  def stepTestSecondSimulationBuildAfterAccountingValidation(self, sequence=None, sequence_list=None, **kw):
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Correction movements
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'depreciation_account', None, 'A', None))
    
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2842
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
    
  def stepTestThirdSimulationBuildAfterAccountingValidation(self, sequence=None, sequence_list=None, **kw):
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))
    # No more correction movement
    
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2877
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
    
  def stepTestFourthSimulationBuildAfterAccountingValidation(self, sequence=None, sequence_list=None, **kw):
    item = sequence.get('item')
    e_simulation_movement_list = []
    # Immobilisation
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', 10000, 'input_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2000/01/01', -10000, 'immobilisation_account', None, 'A', None))
    # Annuities
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'depreciation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))
    # Correction movements
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', -2500, 'amortisation_account', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2001/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2002/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2004/01/01', 2500, 'amortisation_account_extra', None, 'A', None))
    
    
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2929
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2930 2931 2932 2933 2934 2935 2936
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
    
    
  def _testAccountingBuild(self, c_transaction_list, e_transaction_list):
2937 2938
    #self.assertEquals(len(c_transaction_list),len(e_transaction_list))
    e_removed_list = []
Guillaume Michon's avatar
Guillaume Michon committed
2939
    for c_transaction in c_transaction_list:
2940 2941 2942 2943 2944 2945 2946
      #LOG('c_transaction %s :' % c_transaction, 0, 
          #'date=%s\n, source_section=%s\n, destination_section=%s\n, resource=%s\n, state=%s\n, causality_list=%s\n' % (
          #(c_transaction.getStopDate(), c_transaction.getSourceSection(),
           #c_transaction.getDestinationSection(), c_transaction.getResource(), c_transaction.getCausalityState(),
           #c_transaction.getCausalityList())
         #)
      #)
Guillaume Michon's avatar
Guillaume Michon committed
2947 2948 2949 2950 2951 2952 2953 2954 2955
      e_found_transaction = None
      e_cursor = 0
      while e_cursor < len(e_transaction_list) and e_found_transaction is None:
        e_transaction = e_transaction_list[e_cursor]
        wrong_transaction = 0
        key_cursor = 0
        key_list = e_transaction.keys()
        if 'line_list' in key_list:
          key_list.remove('line_list')
2956 2957
        if 'id' in key_list:
          key_list.remove('id')
Guillaume Michon's avatar
Guillaume Michon committed
2958 2959
        while key_cursor < len(key_list) and not wrong_transaction:
          key = key_list[key_cursor]
2960
          #LOG('key : ',0,key)
Guillaume Michon's avatar
Guillaume Michon committed
2961
          e_value = e_transaction[key]
2962
          #LOG('e_value : ',0,e_value)
Guillaume Michon's avatar
Guillaume Michon committed
2963 2964
          key = 'get' + ''.join([k.capitalize() for k in key.split('_')])
          c_value = getattr(c_transaction,key)()
2965
          #LOG('c_value : ',0,c_value)
Guillaume Michon's avatar
Guillaume Michon committed
2966 2967 2968 2969 2970 2971 2972
          is_float = 0
          try:
            if type(c_value) != type(DateTime()):
              c_value=float(c_value)
              is_float = 1
          except:
            pass
2973 2974 2975 2976
          if type(c_value) == type([]):
            c_value.sort(lambda a,b: cmp(a.getId(), b.getId()))
          if type(e_value) == type([]):
            e_value.sort(lambda a,b: cmp(a.getId(), b.getId()))
Guillaume Michon's avatar
Guillaume Michon committed
2977 2978 2979 2980 2981
          if is_float:
            wrong_transaction = (round(c_value,2) != round(e_value,2))
          else:
            wrong_transaction = (c_value != e_value)
          key_cursor += 1
2982
        #LOG('wrong_transaction',0,wrong_transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2983 2984 2985 2986
        if not wrong_transaction:
          e_found_transaction = e_transaction
        e_cursor += 1
      if e_found_transaction is None:
2987
        #LOG('No expected transaction found for this calculated one !',0,'')
Guillaume Michon's avatar
Guillaume Michon committed
2988
        self.failUnless(e_found_transaction is not None)
2989 2990
      #e_transaction_list.remove(e_transaction)
      e_removed_list.append(e_transaction_list.pop(e_transaction_list.index(e_transaction)))
Guillaume Michon's avatar
Guillaume Michon committed
2991 2992 2993
      e_line_list = e_transaction['line_list']
      c_line_list = c_transaction.contentValues()
      for c_line in c_line_list:
2994 2995 2996 2997 2998
        #LOG('c_line %s :' % c_line, 0, 
          #'source=%s\n,destination=%s\n,quantity=%s\n' % (
          #(c_line.getSource(),c_line.getDestination(),c_line.getQuantity())
          #)
         #)
Guillaume Michon's avatar
Guillaume Michon committed
2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030
        e_found_line = None
        e_line_cursor = 0
        while e_line_cursor < len(e_line_list) and e_found_line is None:
          e_line = e_line_list[e_line_cursor]
          wrong_line = 0
          key_cursor = 0
          key_list = e_line.keys()
          while key_cursor < len(key_list) and not wrong_line:
            key = key_list[key_cursor]
            e_value = e_line[key]
            key = 'get' + ''.join([k.capitalize() for k in key.split('_')])
            c_value = getattr(c_line,key)()
            is_float = 0
            try:
              if type(c_value) != type(DateTime()):
                c_value=float(c_value)
                is_float = 1
            except:
              pass
            if is_float:
              wrong_line = (round(c_value,2) != round(e_value,2))
            else:
              wrong_line = (c_value != e_value)
            key_cursor += 1
          if not wrong_line:
            e_found_line = e_line
          e_line_cursor += 1
        if e_found_line is None:
          self.failUnless(e_found_line is not None)
        e_line_list.remove(e_found_line)
      if len(e_line_list) > 0:
        self.assertEquals(len(e_line_list),0)
3031

Guillaume Michon's avatar
Guillaume Michon committed
3032 3033
    if len(e_transaction_list) > 0:
      self.assertEquals(len(e_transaction_list),0)
3034 3035 3036 3037

class TestImmobilisation(TestImmobilisationMixin):

  run_all_test = 1
3038

Guillaume Michon's avatar
Guillaume Michon committed
3039 3040 3041
  def stepSetTest01SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(destination_section = self.getOrganisationModule()["A"],
                  datetime = self.datetime,
3042
                  item_list_list = [[self.getItemModule()['item1']]]
Guillaume Michon's avatar
Guillaume Michon committed
3043
                  )
3044

Guillaume Michon's avatar
Guillaume Michon committed
3045 3046 3047 3048 3049 3050 3051
  def test_01_singlePackingListImmobilisationStateChange(self, quiet=0, run=run_all_test):
    # Test if an added packing list has a correct immobilisation state
    if not run: return
    if not quiet:
      message = '\nTest Single Packing List Immobilisation State Change'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
3052
    sequence_list = SequenceList()
Guillaume Michon's avatar
Guillaume Michon committed
3053 3054 3055 3056 3057 3058
    sequence_string = 'SetTest01SequenceData \
                       CreatePackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       TestPackingListValidImmobilisationState \
                       AggregateItems \
3059
                       TestPackingListValidImmobilisationState \
Guillaume Michon's avatar
Guillaume Michon committed
3060 3061 3062
                       Tic \
                       TestPackingListValidImmobilisationState \
                      '
3063
    sequence_list.addSequenceString(sequence_string)
3064 3065
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3066 3067 3068 3069 3070
  def stepSetTest02SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(destination_section = self.getOrganisationModule()["A"],
                  datetime= [self.datetime, self.datetime+5, self.datetime+10],
                  item_list_list = [[ self.getItemModule()['item2'] ]]
                  )
3071

Guillaume Michon's avatar
Guillaume Michon committed
3072 3073 3074 3075 3076 3077 3078 3079 3080
  def test_02_singleItemImmobilisationStateChange(self, quiet=0, run=run_all_test):
    # Test if an edit on a preceding delivery switches the following in calculating state
    if not run: return
    if not quiet:
      message = '\nTest Single Item Immobilisation State Change'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest02SequenceData \
3081
                       DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100
                       CreatePackingList \
                       AggregateItems \
                       CreatePackingList \
                       AggregateItems \
                       CreatePackingList \
                       AggregateItems \
                       Tic \
                       UseSecondPackingList \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                      '
3101
    sequence_list.addSequenceString(sequence_string)
3102 3103
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3104 3105 3106 3107 3108 3109 3110 3111
  def test_03_complexItemStructureImmobilisationStateChange(self, quiet=0, run=run_all_test):
    # Test on a complex structure if an edit on a PL changes correctly immobilisation states
    if not run: return
    if not quiet:
      message = '\nTest Complex Item Structure Immobilisation State Change'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
3112
    sequence_string = 'DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153
                       CreateComplexPackingListStructure \
                       Tic \
                       UseSecondPackingList \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListValidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListValidImmobilisationState \
                       Tic \
                       UseFirstPackingList \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       UseThirdPackingList \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListValidImmobilisationState \
                      '
3154
    sequence_list.addSequenceString(sequence_string)
3155 3156
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3157 3158 3159 3160
  def stepSetTest04SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item5'],
                  destination_section = self.getOrganisationModule()["A"],
                  amortisation_method = self.linear_method)
3161

Guillaume Michon's avatar
Guillaume Michon committed
3162 3163 3164 3165 3166
  def stepTest04ModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_start_price=None)
3167

Guillaume Michon's avatar
Guillaume Michon committed
3168 3169 3170 3171 3172 3173 3174 3175 3176 3177
  def test_04_TestContinuousMethodMovementValidity(self, quiet=0, run=run_all_test):
    # Create a continuous method with some movements, then test their validity
    # by invalidating some of them
    if not run: return
    if not quiet:
      message = '\nTest Continuous Method Movement Validity'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest04SequenceData \
3178
                       DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
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
                       CreatePackingListsForContinuousAmortisationPeriodList \
                       Tic \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListValidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListValidImmobilisationState \
                       UseFirstPackingList \
                       Test04ModifyPackingList \
                       UseSecondPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       UseFirstPackingList \
                       TestPackingListInvalidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListValidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       DeletePackingList \
                       UseFirstPackingList \
                       TestPackingListInvalidImmobilisationState \
                       UseThirdPackingList \
3211
                       TestPackingListInvalidImmobilisationState \
Guillaume Michon's avatar
Guillaume Michon committed
3212 3213 3214 3215 3216 3217 3218 3219
                       UseFourthPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       UseThirdPackingList \
                       TestPackingListInvalidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListInvalidImmobilisationState \
                      '
3220
    sequence_list.addSequenceString(sequence_string)
3221 3222
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3223 3224 3225
  def stepSetTest05SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item6'],
                  amortisation_method = self.linear_method)
3226

Guillaume Michon's avatar
Guillaume Michon committed
3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240
  def test_05_TestImmobilisationPeriodsWithContinuousMethodDuringContinuousTime(self, quiet=0, run=run_all_test):
    # Test the calculated amortisation periods with a continuous amortisation method
    # and with no stop of immobilisation
    if not run: return
    if not quiet:
      message = '\nTest Immobilisation Periods With Continuous Method During Continuous Time'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest05SequenceData \
                       CreatePackingListsForContinuousAmortisationPeriodList \
                       Tic \
                       TestLinearAmortisationImmobilisationPeriods \
                       '
3241
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3242 3243
    sequence_list.play(self)    

3244
    
Guillaume Michon's avatar
Guillaume Michon committed
3245 3246 3247
  def stepSetTest06SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item7'],
                  amortisation_method = self.linear_method)
3248

Guillaume Michon's avatar
Guillaume Michon committed
3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262
  def test_06_TestImmobilisationPeriodsWithContinuousMethodDuringUncontinuousTime(self, quiet=0, run=run_all_test):
    # Test the calculated amortisation periods with a continuous amortisation method
    # and with stops of immobilisation in the time
    if not run: return
    if not quiet:
      message = '\nTest Immobilisation Periods With Continuous Method During Uncontinuous Time'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest06SequenceData \
                       CreatePackingListsForUncontinuousAmortisationPeriodList \
                       Tic \
                       TestLinearAmortisationImmobilisationPeriodsUncontinuous \
                       '
3263
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3264 3265
    sequence_list.play(self)    

3266

Guillaume Michon's avatar
Guillaume Michon committed
3267 3268 3269 3270
  def stepSetTest07SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item8'],
                  amortisation_method = self.uncontinuous_degressive_method,
                  parameter_dict = {'degressive_coefficient': 2})
3271

Guillaume Michon's avatar
Guillaume Michon committed
3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285
  def test_07_TestImmobilisationPeriodsWithUncontinuousMethodDuringContinuousTime(self, quiet=0, run=run_all_test):
    # Test the calculated amortisation periods with a uncontinuous amortisation method
    # and with no stop of immobilisation in the time
    if not run: return
    if not quiet:
      message = '\nTest Immobilisation Periods With Uncontinuous Method During Continuous Time'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest07SequenceData \
                       CreatePackingListsForContinuousAmortisationPeriodList \
                       Tic \
                       TestDegressiveAmortisationImmobilisationPeriods \
                       '
3286
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3287 3288
    sequence_list.play(self)    
        
3289
    
Guillaume Michon's avatar
Guillaume Michon committed
3290 3291 3292 3293
  def stepSetTest08SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item9'],
                  amortisation_method = self.uncontinuous_degressive_method,
                  parameter_dict = {'degressive_coefficient': 2})
3294

Guillaume Michon's avatar
Guillaume Michon committed
3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308
  def test_08_TestImmobilisationPeriodsWithUncontinuousMethodDuringUncontinuousTime(self, quiet=0, run=run_all_test):
    # Test the calculated amortisation periods with an uncontinuous amortisation method
    # and with stops of immobilisation in the time
    if not run: return
    if not quiet:
      message = '\nTest Immobilisation Periods With Uncontinuous Method During Uncontinuous Time'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest08SequenceData \
                       CreatePackingListsForUncontinuousAmortisationPeriodList \
                       Tic \
                       TestDegressiveAmortisationImmobilisationPeriodsUncontinuous \
                       '
3309
    sequence_list.addSequenceString(sequence_string)
3310 3311
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3312 3313 3314
  def stepSetTest09SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item10'],
                  amortisation_method = self.linear_method)
3315

Guillaume Michon's avatar
Guillaume Michon committed
3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328
  def test_09_TestAmortisationPriceAndSimulationForLinearAmortisation(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Amortisation Price And Simulation For Linear Amortisation'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest09SequenceData \
                       CreatePackingListsForSimpleItemImmobilisation \
                       Tic \
                       TestLinearAmortisationPriceCalculation \
                       TestLinearAmortisationSimulationBuild \
                       '
3329
    sequence_list.addSequenceString(sequence_string)
3330 3331
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3332 3333 3334 3335
  def stepSetTest10SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item11'],
                  amortisation_method = self.degressive_method,
                  parameter_dict={'degressive_coefficient':2})
3336

Guillaume Michon's avatar
Guillaume Michon committed
3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348
  def test_10_TestAmortisationPriceForDegressiveAmortisation(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Amortisation Price For Degressive Amortisation'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest10SequenceData \
                       CreatePackingListsForSimpleItemImmobilisation \
                       Tic \
                       TestDegressiveAmortisationPriceCalculation \
                       '
3349
    sequence_list.addSequenceString(sequence_string)
3350 3351
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3352 3353 3354 3355
  def stepSetTest11SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item12'],
                  amortisation_method = self.uncontinuous_degressive_method,
                  parameter_dict={'degressive_coefficient':2})
3356

Guillaume Michon's avatar
Guillaume Michon committed
3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369
  def test_11_TestAmortisationPriceAndSimulationForUncontinuousDegressiveAmortisation(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Amortisation Price And Simulation For Uncontinuous Degressive Amortisation'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest11SequenceData \
                       CreatePackingListsForSimpleItemImmobilisation \
                       Tic \
                       TestUncontinuousDegressiveAmortisationPriceCalculation \
                       TestUncontinuousDegressiveAmortisationSimulationBuild \
                       '
3370
    sequence_list.addSequenceString(sequence_string)
3371 3372 3373
    sequence_list.play(self)


Guillaume Michon's avatar
Guillaume Michon committed
3374 3375 3376 3377
  def stepSetTest12SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item13'],
                  amortisation_method = self.actual_use_method,
                  parameter_dict={'durability':1000})
3378

Guillaume Michon's avatar
Guillaume Michon committed
3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390
  def test_12_TestAmortisationPriceForActualUseDegressiveAmortisation(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Amortisation Price For Actual Use Amortisation'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest12SequenceData \
                       CreatePackingListsForSimpleItemImmobilisation \
                       Tic \
                       TestActualUseAmortisationPriceCalculation \
                       '
3391
    sequence_list.addSequenceString(sequence_string)
3392 3393
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410
  def stepSetTest13SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item14'],
                  amortisation_method = self.no_amortisation_method,
                 )
  def test_13_TestAmortisationPriceForNoAmortisationMethod(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Amortisation Price For No Amortisation Method'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest13SequenceData \
                       CreatePackingListsForSimpleItemImmobilisation \
                       Tic \
                       TestNoAmortisationMethodPriceCalculation \
                       TestNoAmortisationMethodSimulationBuild \
                       '
3411
    sequence_list.addSequenceString(sequence_string)
3412
    sequence_list.play(self)
Guillaume Michon's avatar
Guillaume Michon committed
3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449


  # Test owner changes. The expected behavior is the following :
  # ----------------------------------------------------------------------------------------------
  # |                   | Owner does not change |  Owner changes but the  | Actual owner changes |
  # |                   |                       |  actual owner does not  |                      |
  # ----------------------------------------------------------------------------------------------
  # |NO_CHANGE movement |     Nothing to do     |        Transfer         |Stop immo - start immo|
  # |Continuous movement|   Optional transfer   |        Transfer         |Stop immo - start immo|
  # |       Other       | Stop immo - start immo| Stop immo - start immo  |Stop immo - start immo|
  # ----------------------------------------------------------------------------------------------
  # "Optional Transfer" means "transfer from old accounts to new ones if they change"
  # "Transfer" means "transfer all non-solded accounts from a section to another"
  # "Continuous movement" means "same method as previous period and method is continuous"
  # Note that section can change without changing owner.
  # "Actual owner changes" means "the 'group' property of both owners differ"
  def stepSetTest14SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item15'],
                  amortisation_method = self.linear_method)
  def test_14_TestOwnerChangeSimulationForContinuousAmortisationMethod(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Owner Change Simulation For Continuous Amortisation Method'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest14SequenceData \
                       CreatePackingListsForSimulationTest \
                       Tic \
                       TestSimulationBuildForContinuousMethodWithoutOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForOwnerChange \
                       Tic \
                       TestSimulationBuildForContinuousMethodWithOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForActualOwnerChange \
                       Tic \
                       TestSimulationBuildForContinuousMethodWithActualOwnerChange \
                       '
3450
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3451 3452
    sequence_list.play(self)    
        
3453
    
Guillaume Michon's avatar
Guillaume Michon committed
3454 3455 3456 3457
  def stepSetTest15SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item16'],
                  amortisation_method = self.uncontinuous_degressive_method,
                  parameter_dict = {'degressive_coefficient':2})
3458

Guillaume Michon's avatar
Guillaume Michon committed
3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476
  def test_15_TestOwnerChangeSimulationForUnContinuousAmortisationMethod(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Owner Change Simulation For Uncontinuous Amortisation Method'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest15SequenceData \
                       CreatePackingListsForSimulationTest \
                       Tic \
                       TestSimulationBuildForUncontinuousMethodWithoutOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForOwnerChange \
                       Tic \
                       TestSimulationBuildForUncontinuousMethodWithOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForActualOwnerChange \
                       Tic \
                       TestSimulationBuildForUncontinuousMethodWithActualOwnerChange \
                       '
3477
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3478 3479 3480 3481 3482 3483
    sequence_list.play(self)    


  def stepSetTest16SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item17'],
                  amortisation_method = self.linear_method)
3484

Guillaume Michon's avatar
Guillaume Michon committed
3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509
  def test_16_TestOwnerChangeSimulationForContinuousAmortisationMethod(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Owner Change Simulation For Continuous Amortisation Method'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest16SequenceData \
                       CreatePackingListsForNoChangeMethodSimulationTest \
                       Tic \
                       TestSimulationBuildForNoChangeMethodWithoutOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForOwnerChange \
                       Tic \
                       TestSimulationBuildForNoChangeMethodWithOwnerChange \
                       ChangeCurrentPackingListDestinationSectionForActualOwnerChange \
                       Tic \
                       TestSimulationBuildForNoChangeMethodWithActualOwnerChange \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    


  def stepSetTest17SequenceData(self, sequence=None, sequence_list=None, **kw):
    sequence.edit(item = self.getItemModule()['item18'],
                  amortisation_method = self.linear_method)
3510

Guillaume Michon's avatar
Guillaume Michon committed
3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544
  def test_17_TestMonthlyAmortisation(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Monthly Amortisation'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest17SequenceData \
                       CreatePackingListsForMonthlyAmortisationTest \
                       Tic \
                       TestSimulationBuildForMonthlyAmortisation \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    


  def stepSetTest18SequenceData(self, sequence=None, sequence_list=None, **kw):
    item_list = ['item1','item2','item3']
    item_list = [self.getItemModule()[item] for item in item_list]
    parameter_dict = dict(self.account_dict)
    parameter_dict.update( {'amortisation_method':self.linear_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0,
                          } )
    build_parameter_dict = { 'at_date':DateTime('2002/01/01'),
                             'item_uid_list': [x.getUid() for x in [self.getItemModule()[y] for y in ['item1','item2']]],
                           }
    sequence.edit(item_list_list = [item_list],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"],
                  build_parameter_dict = build_parameter_dict)
3545

Guillaume Michon's avatar
Guillaume Michon committed
3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557
  def test_18_TestAccountingBuilding(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Simple Accounting Build'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest18SequenceData \
                       DeleteAllPackingLists \
                       Tic \
                       TestAllAppliedRulesAreEmpty \
                       CreatePackingList \
3558
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587
                       AggregateItems \
                       Tic \
                       PartialBuildAccounting \
                       Tic \
                       TestPartialAccountingBuild \
                       DeleteAccounting \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestMultiItemAccountingBuild \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    

  def stepSetTest19SequenceData(self, sequence=None, sequence_list=None, **kw):
    item_list = ['item1']
    item_list = [self.getItemModule()[item] for item in item_list]
    parameter_dict = dict(self.account_dict)
    parameter_dict.update( {'amortisation_method':self.linear_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [item_list],
                  item=self.getItemModule()['item1'],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
3588

Guillaume Michon's avatar
Guillaume Michon committed
3589 3590 3591 3592 3593 3594 3595 3596
  def stepSetTest19SequenceData2(self, sequence=None, sequence_list=None, **kw):
    """
    Add a section change packing_list at date 2002/01/01
    """
    parameter_dict = {}
    sequence.edit(datetime = DateTime('2002/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["B"])
3597

Guillaume Michon's avatar
Guillaume Michon committed
3598 3599 3600 3601 3602
  def stepTest19ModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_account=self.extra_account_dict['amortisation_account'])
3603

3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619
  def stepTestAccountingSectionStatistics(self, sequence=None, sequence_list=None, **kw):
    # First we must make sure that the preference is well defined
    preference_tool = self.getPreferenceTool()
    preference = preference_tool.default_site_preference
    preference.edit(preferred_accounting_transaction_simulation_state=\
                      ('delivered', 'confirmed', 'draft', 'planned', 'cancelled', 'stopped'),
                    preferred_accounting_transaction_section_category=\
                        'group/group A',
                    preferred_accounting_transaction_currency=\
                        'currency_module/EUR')
    wf_tool = self.getWorkflowTool()
    wf_tool.doActionFor(preference,'enable_action',wf_id='preference_workflow')
    get_transaction().commit()
    self.tic()
    # Now we can check several Accounting methods
    account = self.getPortal().account_module.account3
3620 3621
    self.assertEquals(10000.0,account.AccountModule_getTotalSourceDebit(brain=account))
    self.assertEquals(10000.0,account.AccountModule_getTotalSourceCredit(brain=account))
3622 3623 3624 3625 3626 3627 3628 3629
    preference.edit(preferred_accounting_transaction_section_category=\
                        'group/group B')
    get_transaction().commit()
    self.tic()
    self.assertEquals('group/group B',
        preference_tool.getPreferredAccountingTransactionSectionCategory())
    # Make sure to not use the cache
    self.portal.REQUEST['ERP5Accounting_getParams'] = None
3630 3631
    self.assertEquals(5000.0,account.AccountModule_getTotalSourceDebit(brain=account))
    self.assertEquals(0.0,account.AccountModule_getTotalSourceCredit(brain=account))
3632

Guillaume Michon's avatar
Guillaume Michon committed
3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646
  def test_19_TestAccountingBuildingAndDivergence(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Accounting Build And Divergence Behavior'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest19SequenceData \
                       DeleteAccounting \
                       Tic \
                       DeleteAllPackingLists \
                       Tic \
                       TestAllAppliedRulesAreEmpty \
                       CreatePackingList \
3647
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3648 3649 3650 3651 3652 3653 3654
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestSimpleAccountingBuild \
                       SetTest19SequenceData2 \
                       CreatePackingList \
3655
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680
                       AggregateItems \
                       Tic \
                       TestSimulationBuildAfterFirstAccountingChange \
                       BuildAccounting \
                       Tic \
                       TestAccountingBuildAfterFirstChange \
                       DeletePackingList \
                       Tic \
                       TestSimulationBuildAfterSecondAccountingChange \
                       BuildAccounting \
                       Tic \
                       TestAccountingBuildAfterSecondChange \
                       AdoptPrevision \
                       Tic \
                       TestAccountingBuildAfterAdoptPrevision \
                       Test19ModifyPackingList \
                       Tic \
                       TestSimulationBuildAfterPackingListModification \
                       BuildAccounting \
                       Tic \
                       TestAccountingBuildAfterPackingListModification \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    

3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708
  def test_19BIS_TestAccountingBuildAndOwngerChange(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Accounting Build And Divergence Behavior'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest19SequenceData \
                       DeleteAccounting \
                       Tic \
                       DeleteAllPackingLists \
                       Tic \
                       TestAllAppliedRulesAreEmpty \
                       CreatePackingList \
                       DeliverPackingList \
                       AggregateItems \
                       Tic \
                       SetTest19SequenceData2 \
                       CreatePackingList \
                       DeliverPackingList \
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestAccountingSectionStatistics \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    
Guillaume Michon's avatar
Guillaume Michon committed
3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724

  def stepSetTest20SequenceData(self, sequence=None, sequence_list=None, **kw):
    item_list = ['item1']
    item_list = [self.getItemModule()[item] for item in item_list]
    parameter_dict = dict(self.account_dict)
    parameter_dict.update( {'amortisation_method':self.linear_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [item_list],
                  item=self.getItemModule()['item1'],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
3725

Guillaume Michon's avatar
Guillaume Michon committed
3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739
  def test_20_TestAccountingAcceptDecisionSolver(self, quiet=0, run=run_all_test):
    if not run: return
    if not quiet:
      message = '\nTest Accounting Accept Decision Solver'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest20SequenceData \
                       DeleteAccounting \
                       Tic \
                       DeleteAllPackingLists \
                       Tic \
                       TestAllAppliedRulesAreEmpty \
                       CreatePackingList \
3740
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestSimpleAccountingBuild \
                       ChangeAccountingPrice \
                       Tic \
                       AcceptDecision \
                       Tic \
                       TestSimulationBuildAfterAcceptDecision \
                       '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)    

  def stepSetTest21SequenceData(self, sequence=None, sequence_list=None, **kw):
    item_list = ['item1']
    item_list = [self.getItemModule()[item] for item in item_list]
    parameter_dict = dict(self.account_dict)
    parameter_dict.update( {'amortisation_method':self.linear_method,
                            'amortisation_start_price':10000,
                            'disposal_price':0,
                            'amortisation_duration':48,
                            'immobilisation_vat':0,
                          } )
    sequence.edit(item_list_list = [item_list],
                  item=self.getItemModule()['item1'],
                  datetime = DateTime('2000/01/01'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["A"])
3770

Guillaume Michon's avatar
Guillaume Michon committed
3771 3772 3773 3774 3775
  def stepTest21FirstModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_duration=36)
3776

Guillaume Michon's avatar
Guillaume Michon committed
3777 3778 3779 3780 3781
  def stepTest21SecondModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_duration=24)
3782

Guillaume Michon's avatar
Guillaume Michon committed
3783 3784 3785 3786 3787
  def stepTest21ThirdModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_duration=48)
3788

Guillaume Michon's avatar
Guillaume Michon committed
3789 3790 3791 3792 3793
  def stepTest21FourthModifyPackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    if pl is None: pl = sequence.get('packing_list_list', [])[-1]
    for line in pl.contentValues():
      line.edit(amortisation_account=self.extra_account_dict['amortisation_account'])
3794

Guillaume Michon's avatar
Guillaume Michon committed
3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814
  def test_21_TestSimulationBuildingWithValidatedTransactions(self, quiet=0, run=run_all_test):
    """
    The expand process takes care of already validated transactions : it creates
    some correction simulation movements in order to compensate simulation movements
    whose corresponding delivery is already validated.
    This test tests this behavior
    """
    if not run: return
    if not quiet:
      message = '\nTest Simulation Building With Validated Transactions'
      ZopeTestCase._print(message)
      LOG('Testing... ',0,message)
    sequence_list = SequenceList()
    sequence_string = 'SetTest21SequenceData \
                       DeleteAccounting \
                       Tic \
                       DeleteAllPackingLists \
                       Tic \
                       TestAllAppliedRulesAreEmpty \
                       CreatePackingList \
3815
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestSimpleAccountingBuild \
                       ValidateAccounting \
                       Tic \
                       Test21FirstModifyPackingList \
                       Tic \
                       TestFirstSimulationBuildAfterAccountingValidation \
                       Test21SecondModifyPackingList \
                       Tic \
                       TestSecondSimulationBuildAfterAccountingValidation \
                       Test21ThirdModifyPackingList \
                       Tic \
                       TestThirdSimulationBuildAfterAccountingValidation \
                       Test21FourthModifyPackingList \
                       Tic \
                       TestFourthSimulationBuildAfterAccountingValidation \
                       '
    sequence_list.addSequenceString(sequence_string)
3837
    sequence_list.play(self)
Guillaume Michon's avatar
Guillaume Michon committed
3838 3839


3840 3841 3842 3843
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestImmobilisation))
  return suite
Guillaume Michon's avatar
Guillaume Michon committed
3844