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
from Testing import ZopeTestCase
32
from zExceptions import Unauthorized
33
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
34
from Products.ERP5Type.tests.Sequence import SequenceList
35 36
from DateTime import DateTime
from zLOG import LOG
Guillaume Michon's avatar
Guillaume Michon committed
37
from Products.ERP5.Document.ImmobilisationMovement import UNIMMOBILISING_METHOD, NO_CHANGE_METHOD
38
from Products.ERP5.tests.utils import newSimulationExpectedFailure
39 40


41
class TestImmobilisationMixin(ERP5TypeTestCase):
42
  run_all_test = 1
Guillaume Michon's avatar
Guillaume Michon committed
43
  # Different variables used for this test
44
  item_portal_type = 'Computer'
45
  packing_list_portal_type = 'Purchase Packing List'
46
  packing_list_line_portal_type = 'Purchase Packing List Line'
47 48 49 50
  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
51 52 53
  organisation_portal_type = 'Organisation'
  account_portal_type = 'Account'
  currency_portal_type = 'Currency'
54
  resource_portal_type = 'Product'
Guillaume Michon's avatar
Guillaume Michon committed
55 56 57 58 59 60 61
  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'
62
  datetime = DateTime()
63 64
  id_transaction = 0
  id_simulation = 0
Guillaume Michon's avatar
Guillaume Michon committed
65
  reindex_done = 0
66

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

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

Guillaume Michon's avatar
Guillaume Michon committed
80
    """
81 82
    return ("erp5_core_proxy_field_legacy",
            "erp5_base",
83
            "erp5_pdm",# Needed by accounting
84 85
            "erp5_simulation",
            "erp5_trade",
Guillaume Michon's avatar
Guillaume Michon committed
86
            "erp5_accounting",
87
            "erp5_invoicing",
88
            "erp5_simplified_invoicing",
Guillaume Michon's avatar
Guillaume Michon committed
89
            "erp5_immobilisation",
90
            "erp5_computer_immobilisation", # In order to use items
91 92 93
            'erp5_configurator_standard_trade_template',
            'erp5_configurator_standard_accounting_template',
            'erp5_configurator_standard_invoicing_template',
Aurel's avatar
Aurel committed
94
            "erp5_simulation_test",
95
            "erp5_movement_table_catalog" # ImmobilisationItem.py uses movement table
Guillaume Michon's avatar
Guillaume Michon committed
96
            )
97

Guillaume Michon's avatar
Guillaume Michon committed
98 99 100 101 102 103 104 105 106 107
  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)
108 109 110 111 112 113
  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
114 115
  def getAccountModule(self):
    return self.getPortal().getDefaultModule(portal_type=self.account_portal_type)
116 117 118 119 120 121 122 123 124 125 126
  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']
127 128
    if not "manager" in [x.id for x in self.getUserFolder().objectValues()]:
      self.getUserFolder()._doAddUser('manager', '', all_roles, [])
129 130
    self.login('manager')
    self.assignPASRolesToUser('test_user_1_', all_roles)
131 132


133 134 135 136 137 138 139 140 141
  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)
142

143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
  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]
                                      )
163 164
        # In the case of PAS, if we want global roles on user, we have to do it manually.
        self.assignPASRolesToUser(user_login, user_roles)
165 166
        assignment.open()
        person.validate()
167

168 169 170 171 172 173 174 175 176 177 178
  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)
179

Guillaume Michon's avatar
Guillaume Michon committed
180 181
  def afterSetUp(self):
    portal = self.getPortal()
182
    self.createManagerAndLogin()
183

Guillaume Michon's avatar
Guillaume Michon committed
184 185 186 187 188
    # 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)
189

190 191 192
    self.createCategories()

    #Assert default security Value
193

194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210
    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()
                    ]
211

Guillaume Michon's avatar
Guillaume Michon committed
212 213 214 215
    # Then add new components
    self.createCurrency()
    self.createOrganisationList()
    self.createAccountList()
216
    self.createItemList()
Nicolas Delaby's avatar
Nicolas Delaby committed
217
    self.validateRules()
218
    self.tic()
219

220
    self.workflow_tool = self.getWorkflowTool()
221

222 223 224 225 226 227 228
  def beforeTearDown(self):
    """
    Delete all Objects in PL & M Module
    """
    self.logout()
    self.login('manager')

229 230
    self.tic()

231 232
    simulation_id_list = [r for r in self.getPortal().portal_simulation.objectIds()]
    self.getPortal().portal_simulation.manage_delObjects(simulation_id_list)
233 234 235

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

237 238 239 240
    #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)
241

242 243
    id_list = [r for r in self.getAccountingModule().objectIds()]
    self.getAccountingModule().manage_delObjects(id_list)
244

245
    self.tic()
246

Guillaume Michon's avatar
Guillaume Michon committed
247 248 249 250 251 252
  def createCategories(self):
    """
    Replace OrderMixin method
    """
    # Create group categories
    category_tool = self.getCategoryTool()
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280
    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
281 282 283 284 285

  def createCategoryTree(self, current_category, category_tree):
    """
    Create a category tree
    """
286
    for category, codification, new_tree in category_tree:
287 288 289
      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)
290

291 292 293 294 295
  def createCategorySiteTree(self, current_category, category_tree):
    """
    Create a category tree
    """
    for category, codification, vault_type, new_tree in category_tree:
296 297 298 299 300 301
      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)
302

Guillaume Michon's avatar
Guillaume Michon committed
303 304
  def createCurrency(self):
    currency_module = self.getCurrencyModule()
305
    if len(currency_module.contentValues()) == 0:
306 307
      currency_module.newContent(id="EUR", portal_type='Currency')
      currency_module.newContent(id="FCFA", portal_type='Currency')
Guillaume Michon's avatar
Guillaume Michon committed
308 309

  def createOrganisationList(self):
310
    """
Guillaume Michon's avatar
Guillaume Michon committed
311
    Create some organisations relating to the group tree
312
    """
Guillaume Michon's avatar
Guillaume Michon committed
313
    organisation_module = self.getOrganisationModule()
314
    if len(organisation_module.contentValues()) == 0:
315 316 317 318 319 320 321 322 323 324 325 326 327 328
      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
329
        organisation_module.newContent(id = organisation_id,
330
                                       title = title,
Guillaume Michon's avatar
Guillaume Michon committed
331 332 333
                                       group = group,
                                       mapping = mapping,
                                       )
334
      ##We need to commit here because edit organisation doesn't apply
335
      #self.commit()
336 337
      #self.tic()
      for organisation_id in ['A','Aa','Ab','B','Ba','Bb','standalone']:
Guillaume Michon's avatar
Guillaume Michon committed
338 339 340
        organisation = organisation_module[organisation_id]
        organisation.edit(price_currency_value = self.getCurrencyModule()["EUR"],
                          financial_year_stop_date = DateTime('2000/01/01'))
341

Guillaume Michon's avatar
Guillaume Michon committed
342
  def createAccountList(self):
343
    """
Guillaume Michon's avatar
Guillaume Michon committed
344
    Create some accounts
345
    """
Guillaume Michon's avatar
Guillaume Michon committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
    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'),
    }
372

373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393
  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)
394

Guillaume Michon's avatar
Guillaume Michon committed
395
  def createItemList(self):
396
    """
Guillaume Michon's avatar
Guillaume Michon committed
397
    Create some items
398
    """
Guillaume Michon's avatar
Guillaume Michon committed
399
    item_module = self.getItemModule()
400 401
    if len(item_module.contentValues()) == 0:
      for i in range(30):
Guillaume Michon's avatar
Guillaume Michon committed
402
        item_id = 'item%i' % i
403
        item_module.newContent(id=item_id, reference='%i' % i)
404

Guillaume Michon's avatar
Guillaume Michon committed
405 406
  def stepCreatePackingList(self, sequence=None, sequence_list=None, **kw):
    property_dict = {}
407
    for property in ('source_section','destination_section','datetime','destination'):
Guillaume Michon's avatar
Guillaume Michon committed
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422
      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'],
423 424 425 426
             stop_date =                 property_dict['datetime'],
             destination =               property_dict['destination'],
             )
    
Guillaume Michon's avatar
Guillaume Michon committed
427 428 429
    packing_list_list = sequence.get('packing_list_list', [])
    packing_list_list.append(pl)
    sequence.set('packing_list_list', packing_list_list)
430 431 432 433 434 435 436 437 438 439 440 441 442 443
    #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')
    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')
    self.tic()
    self.workflow_tool.doActionFor(pl, 'stop_action', wf_id='packing_list_workflow')
    self.tic()
    #self.workflow_tool.doActionFor(pl, 'deliver_action', wf_id='packing_list_workflow')

444 445 446 447 448 449
  def stepConfirmAmortisationTransaction(self, sequence=None, sequence_list=None, **kw):
    for transaction in self.getAccountingModule().objectValues():
      self.workflow_tool.doActionFor(transaction,
                                     'confirm_action',
                                     wf_id='accounting_workflow')

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

454 455 456 457

  def stepAggregateItems(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list_list', [])[-1]
    parameter_dict = sequence.get('parameter_dict', {})
458 459 460 461
    resource_value = sequence.get('product',None)
    if resource_value is None:
      resource_value = self.getPortal().product_module.newContent()
      sequence.edit(product=resource_value)
462 463 464 465 466
    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)
467 468
      pl_line.edit(aggregate_value_list = item_list, 
                   resource_value=resource_value, **parameter_dict)
469
    self.tic()
470 471
    #pl.calculateImmobilisationValidity()

472 473 474
  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]
475
    pl.setReference(pl.getReference())
476

Guillaume Michon's avatar
Guillaume Michon committed
477 478 479 480 481 482
  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
483
    PL 3    X         X
Guillaume Michon's avatar
Guillaume Michon committed
484 485 486 487
    PL 4         X    X
    """
    sequence.edit(destination_section =  self.getOrganisationModule()["A"],
                  datetime= self.datetime,
488
                  item_list_list = [[ self.getItemModule()['item1'] ], [ self.getItemModule()['item2'] ]])
Guillaume Michon's avatar
Guillaume Michon committed
489 490
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
491
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
492 493 494
    sequence.edit(item_list_list = [[self.getItemModule()['item4']]], datetime = self.datetime+5)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
495
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
496 497 498 499
    sequence.edit(item_list_list = [[ self.getItemModule()['item1'],self.getItemModule()['item3'] ]],
                  datetime = self.datetime+10)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
500
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
501 502 503 504
    sequence.edit(item_list_list = [[ self.getItemModule()['item2'],self.getItemModule()['item3'] ]],
                  datetime = self.datetime+15)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
505 506
    self.stepDeliverPackingList(sequence=sequence)

Guillaume Michon's avatar
Guillaume Michon committed
507 508 509
  def stepDeletePackingList(self, sequence=None, sequence_list=None, **kw):
    pl = sequence.get('packing_list')
    pl_in_list = 0
510
    if pl is None:
Guillaume Michon's avatar
Guillaume Michon committed
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546
      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):
547 548
    for accounting_transaction in self.getAccountingModule().contentValues():
      accounting_transaction.stop()
549
      self.tic()
550
      accounting_transaction.deliver()
551
      self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
552 553 554 555 556

  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")
557

Guillaume Michon's avatar
Guillaume Michon committed
558 559 560 561
  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")
562

563 564 565 566
  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")
567

Guillaume Michon's avatar
Guillaume Michon committed
568 569 570 571
  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")
572

Guillaume Michon's avatar
Guillaume Michon committed
573 574
  def stepTestPackingListImmobilisationState(self, pl, state, **kw):
    self.assertEquals(pl.getImmobilisationState(), state)
575

576 577
  def stepTestPackingListSimulationState(self, pl, state, **kw):
    self.assertEquals(pl.getSimulationState(), state)
578

579 580
  def stepTestPackingListValidationState(self, pl, state, **kw):
    self.assertEquals(pl.getValidationState(), state)
581

Guillaume Michon's avatar
Guillaume Michon committed
582 583 584 585 586 587 588 589 590 591
  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)
    """
592

Guillaume Michon's avatar
Guillaume Michon committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
    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)
609 610
    self.stepDeliverPackingList(sequence=sequence)
    #1
Guillaume Michon's avatar
Guillaume Michon committed
611 612 613 614 615 616 617 618
    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)
619 620
    self.stepDeliverPackingList(sequence=sequence)
    #2
Guillaume Michon's avatar
Guillaume Michon committed
621 622 623 624 625 626
    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)
627 628
    self.stepDeliverPackingList(sequence=sequence)
    #3
Guillaume Michon's avatar
Guillaume Michon committed
629 630 631
    sequence.edit(datetime = DateTime('2003/01/01'))
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
632 633
    self.stepDeliverPackingList(sequence=sequence)
    #4
Guillaume Michon's avatar
Guillaume Michon committed
634 635 636 637 638 639
    # 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)
640 641
    self.stepDeliverPackingList(sequence=sequence)
    #5
Guillaume Michon's avatar
Guillaume Michon committed
642 643 644
    sequence.edit(datetime = DateTime('2002/10/01'),destination_section=None)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
645 646 647 648 649 650
    self.stepDeliverPackingList(sequence=sequence)
    #6
    #sequence.edit(datetime = DateTime('2003/01/01'))
    #self.stepCreatePackingList(sequence=sequence)
    #self.stepAggregateItems(sequence=sequence)
    #self.stepDeliverPackingList(sequence=sequence)
651

Guillaume Michon's avatar
Guillaume Michon committed
652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677
  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)
678
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
679 680 681 682 683 684 685 686 687 688 689
    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)
690
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
691 692 693 694
    sequence.edit(datetime = DateTime('2001/07/01'),
                  parameter_dict = parameter_dict)
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
695
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
696 697 698 699 700 701 702 703 704 705 706
    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)
707
    self.stepDeliverPackingList(sequence=sequence)
708

Guillaume Michon's avatar
Guillaume Michon committed
709 710 711 712 713 714
    # 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)
715
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
716 717 718 719
    sequence.edit(datetime = DateTime('2004/01/01'),
                  destination_section=self.getOrganisationModule()["A"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
720
    self.stepDeliverPackingList(sequence=sequence)
721

Guillaume Michon's avatar
Guillaume Michon committed
722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
  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)
744
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
745 746 747 748 749 750 751 752 753
    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)
754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780
    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)
781

Guillaume Michon's avatar
Guillaume Michon committed
782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805
  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)
806
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
807 808 809 810 811 812 813 814 815 816 817 818 819
    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)
820
    self.stepDeliverPackingList(sequence=sequence)
821

Guillaume Michon's avatar
Guillaume Michon committed
822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845
  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)
846
    self.stepDeliverPackingList(sequence=sequence)
Guillaume Michon's avatar
Guillaume Michon committed
847 848 849 850 851 852 853 854 855
    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)
856
    self.stepDeliverPackingList(sequence=sequence)
857

Guillaume Michon's avatar
Guillaume Michon committed
858 859 860 861 862 863 864 865
  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)
866

Guillaume Michon's avatar
Guillaume Michon committed
867 868 869 870 871 872 873
  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)
874

875 876 877
  """
  TEST 17
  """
Guillaume Michon's avatar
Guillaume Michon committed
878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904
  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)
905
    self.stepDeliverPackingList(sequence=sequence)
906
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
907 908 909 910 911 912 913 914 915 916 917
    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)
918
    self.stepDeliverPackingList(sequence=sequence)
919
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
920 921 922 923 924
    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)
925
    self.stepDeliverPackingList(sequence=sequence)
926
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
927 928 929 930 931
    sequence.edit(datetime = DateTime('2002/05/16'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Ab1"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
932
    self.stepDeliverPackingList(sequence=sequence)
933
    self.tic()
Guillaume Michon's avatar
Guillaume Michon committed
934 935 936 937 938
    sequence.edit(datetime = DateTime('2002/06/16'),
                  parameter_dict = parameter_dict,
                  destination_section = self.getOrganisationModule()["Ba"])
    self.stepCreatePackingList(sequence=sequence)
    self.stepAggregateItems(sequence=sequence)
939
    self.stepDeliverPackingList(sequence=sequence)
940 941
    self.tic()

Guillaume Michon's avatar
Guillaume Michon committed
942 943 944 945 946
  def stepBuildAccounting(self, sequence=None, sequence_list=None, **kw):
    """
    Build completely accounting
    """
    self.stepPartialBuildAccounting(sequence=sequence, sequence_list=sequence_list, build_parameter_dict={}, **kw)
947

Guillaume Michon's avatar
Guillaume Michon committed
948 949 950 951 952 953 954
  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)
955

Guillaume Michon's avatar
Guillaume Michon committed
956 957 958 959
  def stepAdoptPrevision(self,sequence=None, sequence_list=None, **kw):
    """
    Launch adopt_prevision() on each Amortisation Transaction
    """
960
    isTransitionPossible = self.portal.portal_workflow.isTransitionPossible
Guillaume Michon's avatar
Guillaume Michon committed
961
    for transaction in self.getAccountingModule().contentValues():
962
      if isTransitionPossible(transaction, 'adopt_prevision'):
Guillaume Michon's avatar
Guillaume Michon committed
963
        transaction.adoptPrevision()
964
        #LOG('Launched adoptPrevision() for transaction', 0, transaction.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
965
      else:
966 967 968
        pass
        #LOG('Cannot launch adoptPrevision() for transaction', 0, transaction.getRelativeUrl())

Guillaume Michon's avatar
Guillaume Michon committed
969 970 971 972 973
  def stepAcceptDecision(self, sequence=None, sequence_list=None, **kw):
    """
    Launch accept_decision() on each Amortisation Transaction
    """
    for transaction in self.getAccountingModule().contentValues():
974
      #LOG('transaction %s causality state :' % transaction, 0, transaction.getCausalityState())
Guillaume Michon's avatar
Guillaume Michon committed
975 976 977 978
      try:
        self.getPortal().portal_workflow.doActionFor(transaction,
                                                     'accept_decision_action',
                                                     'amortisation_transaction_causality_workflow')
979
        #LOG('Launched acceptDecision() for transaction', 0, transaction.getRelativeUrl())
980
      except Unauthorized:
981 982 983
        pass
        #LOG('Cannot launch acceptDecision() for transaction', 0, transaction.getRelativeUrl())

Guillaume Michon's avatar
Guillaume Michon committed
984 985 986 987 988 989 990 991 992 993 994 995 996
  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)
997

Guillaume Michon's avatar
Guillaume Michon committed
998 999 1000 1001 1002
  def stepTestAllAppliedRulesAreEmpty(self, sequence=None, sequence_list=None, **kw):
    """
    Test if all applied rules are empty
    """
    for item in self.getItemModule().contentValues():
1003 1004
      applied_rule_list = item.getCausalityRelatedValueList()
      for applied_rule in applied_rule_list:
Guillaume Michon's avatar
Guillaume Michon committed
1005
        self.assertEquals(len(applied_rule.contentValues()), 0)
1006

Guillaume Michon's avatar
Guillaume Michon committed
1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038
  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)
1039

Guillaume Michon's avatar
Guillaume Michon committed
1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
        
  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)
1067

Guillaume Michon's avatar
Guillaume Michon committed
1068 1069
            
  def stepTestDegressiveAmortisationImmobilisationPeriods(self, sequence=None, sequence_list=None, **kw):
1070
    """
Guillaume Michon's avatar
Guillaume Michon committed
1071
    Test calculated immobilisation periods
1072
    """
Guillaume Michon's avatar
Guillaume Michon committed
1073 1074
    item = sequence.get('item')
    c_period_list = item.getImmobilisationPeriodList()
1075
    
Guillaume Michon's avatar
Guillaume Michon committed
1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095
    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)
1096
      
Guillaume Michon's avatar
Guillaume Michon committed
1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123

  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)
1124

Guillaume Michon's avatar
Guillaume Michon committed
1125
  def _testImmobilisationPeriods(self,c_period_list,e_period_list):
1126
    #LOG('c_period_list :', 0, c_period_list)
Guillaume Michon's avatar
Guillaume Michon committed
1127 1128
    e_period_cursor = 0
    for c_period in c_period_list:
1129
      #LOG('c_period :', 0, c_period)
Guillaume Michon's avatar
Guillaume Michon committed
1130 1131 1132
      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]
1133
      #LOG('e_period :', 0, e_period)
Guillaume Michon's avatar
Guillaume Michon committed
1134 1135 1136
      e_period_cursor += 1
      for key in e_period.keys():
        e_value = e_period[key]
1137
        #LOG('testing c_period %s "%s" value' % (e_period_cursor-1, key), 0, '')
Guillaume Michon's avatar
Guillaume Michon committed
1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155
        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):
1156
    """
Guillaume Michon's avatar
Guillaume Michon committed
1157
    Test calculated prices
1158
    """
Guillaume Michon's avatar
Guillaume Michon committed
1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172
    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)
1173 1174
      #LOG('testing amortisation price at date', 0, date)
      #LOG('c_price',0,c_price)
Guillaume Michon's avatar
Guillaume Michon committed
1175
      self.assertEquals(round(c_price,2), e_price)
1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200
  
  """
  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
1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218
  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)
1219
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1220
      self.assertEquals(round(c_price,2), e_price)
1221
      
Guillaume Michon's avatar
Guillaume Michon committed
1222 1223
    
  def stepTestUncontinuousDegressiveAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1224
    """
Guillaume Michon's avatar
Guillaume Michon committed
1225
    Test calculated prices
1226
    """
Guillaume Michon's avatar
Guillaume Michon committed
1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240
    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)
1241
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1242
      self.assertEquals(round(c_price,2), e_price)
1243 1244
      
    
Guillaume Michon's avatar
Guillaume Michon committed
1245
  def stepTestActualUseAmortisationPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1246
    """
Guillaume Michon's avatar
Guillaume Michon committed
1247
    Test calculated prices
1248
    """
Guillaume Michon's avatar
Guillaume Michon committed
1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263
    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)
1264
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1265 1266
      self.assertEquals(round(c_price,2), e_price)
      
1267
    
Guillaume Michon's avatar
Guillaume Michon committed
1268
  def stepTestNoAmortisationMethodPriceCalculation(self, sequence=None, sequence_list=None, **kw):
1269
    """
Guillaume Michon's avatar
Guillaume Michon committed
1270
    Test calculated prices
1271
    """
Guillaume Michon's avatar
Guillaume Michon committed
1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285
    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)
1286
      #LOG('testing amortisation price at date', 0, date)
Guillaume Michon's avatar
Guillaume Michon committed
1287 1288 1289 1290 1291
      self.assertEquals(round(c_price,2), e_price)
      
  
  def _createExpectedMovement(self, date, quantity, source=None, destination=None,
                              source_section=None, destination_section=None):
1292 1293
    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
1294 1295 1296 1297 1298 1299 1300 1301 1302 1303
              '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])]
1304
      else:
Guillaume Michon's avatar
Guillaume Michon committed
1305 1306 1307 1308 1309 1310 1311
        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
1312

Guillaume Michon's avatar
Guillaume Michon committed
1313 1314
        
  def stepTestLinearAmortisationSimulationBuild(self, sequence=None, sequence_list=None, **kw):
1315
    """
1316
    Test 09
Guillaume Michon's avatar
Guillaume Michon committed
1317
    Test built simulation for linear amortisation
1318
    """
Guillaume Michon's avatar
Guillaume Michon committed
1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338
    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))
1339 1340 1341 1342
    #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
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359
    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')
1360
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1361 1362 1363 1364
    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)
1365
  
1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409
  """
  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
1410
  def stepTestUncontinuousDegressiveAmortisationSimulationBuild(self, sequence=None, sequence_list=None, **kw):
1411
    """
Guillaume Michon's avatar
Guillaume Michon committed
1412
    Test built simulation for uncontinuous degressive amortisation
1413
    """
Guillaume Michon's avatar
Guillaume Michon committed
1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433
    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))
1434 1435 1436 1437
    #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
1438 1439 1440 1441
    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))
1442
    #Unimmobilisation
Guillaume Michon's avatar
Guillaume Michon committed
1443 1444
    e_simulation_movement_list.append(self._createExpectedMovement(
              '2003/07/01', -7530.86, 'amortisation_account', None, 'A', None))
1445 1446
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2003/07/01', -8024.67, 'amortisation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1447 1448 1449 1450
    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))
1451 1452
    #e_simulation_movement_list.append(self._createExpectedMovement(
              #'2003/07/01', -1975.33, 'output_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486
    # 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))
1487
    
Guillaume Michon's avatar
Guillaume Michon committed
1488
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1489
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1490 1491 1492 1493 1494 1495 1496
    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):
1497
    """
Guillaume Michon's avatar
Guillaume Michon committed
1498
    Test built simulation for no amortisation method
1499
    """
Guillaume Michon's avatar
Guillaume Michon committed
1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518
    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
1519
    
Guillaume Michon's avatar
Guillaume Michon committed
1520
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1521
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1522 1523 1524 1525 1526 1527 1528
    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):
1529
    """
Guillaume Michon's avatar
Guillaume Michon committed
1530
    Test built simulation for a linear amortisation method without owner change
1531
    """
Guillaume Michon's avatar
Guillaume Michon committed
1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563
    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))
1564
    
Guillaume Michon's avatar
Guillaume Michon committed
1565
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1566
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1567 1568 1569 1570
    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)
1571
    
Guillaume Michon's avatar
Guillaume Michon committed
1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606
  
  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))
1607
    
Guillaume Michon's avatar
Guillaume Michon committed
1608
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1609
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1610 1611 1612 1613
    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)
1614
    
1615
  
Guillaume Michon's avatar
Guillaume Michon committed
1616
  def stepTestSimulationBuildForContinuousMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1617
    """
Guillaume Michon's avatar
Guillaume Michon committed
1618
    Test built simulation for a linear amortisation method with actual owner change (ie group)
1619
    """
Guillaume Michon's avatar
Guillaume Michon committed
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657
    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')
1658
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1659 1660 1661 1662
    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)
1663

Guillaume Michon's avatar
Guillaume Michon committed
1664
  def stepTestSimulationBuildForUncontinuousMethodWithoutOwnerChange(self, sequence=None, sequence_list=None, **kw):
1665
    """
Guillaume Michon's avatar
Guillaume Michon committed
1666
    Test built simulation for a uncontinuous degressive amortisation method without owner change
1667
    """
Guillaume Michon's avatar
Guillaume Michon committed
1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708
    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))
1709
    
Guillaume Michon's avatar
Guillaume Michon committed
1710
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1711
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1712 1713 1714 1715
    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)
1716
    
Guillaume Michon's avatar
Guillaume Michon committed
1717 1718
  
  def stepTestSimulationBuildForUncontinuousMethodWithOwnerChange(self, sequence=None, sequence_list=None, **kw):
1719
    """
Guillaume Michon's avatar
Guillaume Michon committed
1720
    Test built simulation for a uncontinuous degressive amortisation method with owner change but no actual owner change
1721
    """
Guillaume Michon's avatar
Guillaume Michon committed
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764
    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')
1765
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1766 1767 1768 1769 1770
    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)
    
1771
    
Guillaume Michon's avatar
Guillaume Michon committed
1772
  def stepTestSimulationBuildForUncontinuousMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1773
    """
Guillaume Michon's avatar
Guillaume Michon committed
1774
    Test built simulation for a uncontinuous degressive amortisation method with actual owner change
1775
    """
Guillaume Michon's avatar
Guillaume Michon committed
1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816
    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))
1817
    
Guillaume Michon's avatar
Guillaume Michon committed
1818
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1819
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1820 1821 1822 1823 1824 1825 1826
    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):
1827
    """
Guillaume Michon's avatar
Guillaume Michon committed
1828
    Test built simulation for a no change amortisation method without owner change
1829
    """
Guillaume Michon's avatar
Guillaume Michon committed
1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855
    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')
1856
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1857 1858 1859 1860 1861
    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)
    
1862
  
Guillaume Michon's avatar
Guillaume Michon committed
1863
  def stepTestSimulationBuildForNoChangeMethodWithOwnerChange(self, sequence=None, sequence_list=None, **kw):
1864
    """
Guillaume Michon's avatar
Guillaume Michon committed
1865
    Test built simulation for a no change amortisation method with owner change but no actual owner (ie group) change
1866
    """
Guillaume Michon's avatar
Guillaume Michon committed
1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896
    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))
1897
    
Guillaume Michon's avatar
Guillaume Michon committed
1898
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1899
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1900 1901 1902 1903
    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)
1904
    
Guillaume Michon's avatar
Guillaume Michon committed
1905 1906
  
  def stepTestSimulationBuildForNoChangeMethodWithActualOwnerChange(self, sequence=None, sequence_list=None, **kw):
1907
    """
Guillaume Michon's avatar
Guillaume Michon committed
1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946
    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))
1947
    
Guillaume Michon's avatar
Guillaume Michon committed
1948
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
1949
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
1950 1951 1952 1953
    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)
1954
    
1955 1956 1957
  """
  TEST 17
  """
Guillaume Michon's avatar
Guillaume Michon committed
1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 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
  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))
2079

Guillaume Michon's avatar
Guillaume Michon committed
2080
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2081
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
2082 2083
    self.assertEquals(len(applied_rule_list),1)
    applied_rule = applied_rule_list[0]
Guillaume Michon's avatar
Guillaume Michon committed
2084 2085
    c_simulation_movement_list = applied_rule.contentValues()
    self._testSimulationBuild(c_simulation_movement_list, e_simulation_movement_list)
2086 2087


Guillaume Michon's avatar
Guillaume Michon committed
2088 2089
  def _testSimulationBuild(self, c_simulation_movement_list, e_simulation_movement_list):
    for c_movement in c_simulation_movement_list:
2090 2091 2092 2093 2094 2095 2096
      #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
2097 2098 2099 2100 2101 2102 2103
      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()
2104
        key_list.remove('id')
Guillaume Michon's avatar
Guillaume Michon committed
2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118
        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))
2119
          else:
Guillaume Michon's avatar
Guillaume Michon committed
2120
            wrong_movement = (c_value != e_value)
2121 2122 2123
          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
2124 2125 2126
        if not wrong_movement:
          e_found_movement = e_movement
        e_cursor += 1
2127
        #LOG('_testSimulationBuild',0,'wrong movement %s' % wrong_movement)
Guillaume Michon's avatar
Guillaume Michon committed
2128
      if e_found_movement is None:
2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142
        import pprint
        self.fail('No expected movement found for\
 %s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n\t%s\n%s' % (
                          c_movement.getRelativeUrl(),
                          c_movement.getDestination(),
                          c_movement.getDestinationSection(),
                          c_movement.getProfitQuantity(),
                          c_movement.getQuantity(),
                          c_movement.getResource(),
                          c_movement.getSource(),
                          c_movement.getSourceSection(),
                          c_movement.getStartDate(),
                          c_movement.getStopDate(),
                          pprint.pformat(e_simulation_movement_list)))
Guillaume Michon's avatar
Guillaume Michon committed
2143 2144
      e_simulation_movement_list.remove(e_found_movement)
    if len(e_simulation_movement_list) > 0:
2145
      #LOG('More expected movements than calculated ! Remaining expected ones are', 0, e_simulation_movement_list)
Guillaume Michon's avatar
Guillaume Michon committed
2146
      self.assertEquals(len(e_simulation_movement_list),0)
2147

Guillaume Michon's avatar
Guillaume Michon committed
2148
  def _buildExpectedTransaction(self, date, source_section, destination_section, causality_state, causality_list=[]):
2149 2150
    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
2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163
              '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
2164

Guillaume Michon's avatar
Guillaume Michon committed
2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180
  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):
2181
    """
Guillaume Michon's avatar
Guillaume Michon committed
2182 2183
    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
2184
    """
Guillaume Michon's avatar
Guillaume Michon committed
2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197
    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)
2198
    
Guillaume Michon's avatar
Guillaume Michon committed
2199 2200 2201 2202 2203 2204
    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):
2205
    """
Guillaume Michon's avatar
Guillaume Michon committed
2206 2207
    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
2208
    """
Guillaume Michon's avatar
Guillaume Michon committed
2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229
    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)
2230
    
Guillaume Michon's avatar
Guillaume Michon committed
2231 2232
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
2233
    c_transaction_list.sort(key=lambda x: x.getStopDate())
Guillaume Michon's avatar
Guillaume Michon committed
2234 2235
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
2236
    
Guillaume Michon's avatar
Guillaume Michon committed
2237
  def stepTestSimpleAccountingBuild(self, sequence=None, sequence_list=None, **kw):
2238
    """
Guillaume Michon's avatar
Guillaume Michon committed
2239 2240
    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
2241
    """
Guillaume Michon's avatar
Guillaume Michon committed
2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262
    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)
2263
    
Guillaume Michon's avatar
Guillaume Michon committed
2264 2265
    c_transaction_list = self.getPortal().portal_catalog(portal_type='Amortisation Transaction')
    c_transaction_list = [o.getObject() for o in c_transaction_list]
2266
    #c_transaction_list.sort(key=lambda x: x.getStopDate())
Guillaume Michon's avatar
Guillaume Michon committed
2267 2268
    self._testAccountingBuild(c_transaction_list, e_transaction_list)
  
2269
    
Guillaume Michon's avatar
Guillaume Michon committed
2270
  def stepTestSimulationBuildAfterFirstAccountingChange(self, sequence=None, sequence_list=None, **kw):
2271
    """
Guillaume Michon's avatar
Guillaume Michon committed
2272 2273 2274
    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
2275
    """
Guillaume Michon's avatar
Guillaume Michon committed
2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299
    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(
2300
              '2004/01/01', -0, 'depreciation_account', None, 'A', None))
Guillaume Michon's avatar
Guillaume Michon committed
2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323
    # 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')
2324
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2325 2326 2327 2328
    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)
2329 2330
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2331
  def stepTestSimulationBuildAfterSecondAccountingChange(self, sequence=None, sequence_list=None, **kw):
2332
    """
Guillaume Michon's avatar
Guillaume Michon committed
2333 2334 2335 2336
    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
2337
    """
Guillaume Michon's avatar
Guillaume Michon committed
2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385
    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')
2386
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2387 2388 2389 2390
    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)
2391 2392
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2393
  def stepTestSimulationBuildAfterPackingListModification(self, sequence=None, sequence_list=None, **kw):
2394
    """
Guillaume Michon's avatar
Guillaume Michon committed
2395 2396 2397 2398 2399 2400
    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
2401
    """
Guillaume Michon's avatar
Guillaume Michon committed
2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 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
    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')
2451
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2452 2453 2454 2455 2456 2457 2458
    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):
2459
    """
Guillaume Michon's avatar
Guillaume Michon committed
2460 2461 2462
    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
2463
    """
Guillaume Michon's avatar
Guillaume Michon committed
2464 2465 2466 2467 2468 2469 2470 2471 2472 2473
    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)]
2474
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2475 2476 2477 2478 2479 2480 2481 2482
    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
2483
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2484 2485 2486
    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)]
2487
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500
    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)]
2501
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512
    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):
2513
    """
Guillaume Michon's avatar
Guillaume Michon committed
2514 2515 2516 2517
    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
2518
    """
Guillaume Michon's avatar
Guillaume Michon committed
2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 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
    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)
2561
    
Guillaume Michon's avatar
Guillaume Michon committed
2562 2563 2564 2565
    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)
  
2566
    
Guillaume Michon's avatar
Guillaume Michon committed
2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624
  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)
2625
    
Guillaume Michon's avatar
Guillaume Michon committed
2626 2627 2628 2629 2630 2631
    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):
2632
    """
Guillaume Michon's avatar
Guillaume Michon committed
2633 2634 2635 2636 2637 2638
    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
2639
    """
Guillaume Michon's avatar
Guillaume Michon committed
2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650
    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)]
2651
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662
    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
2663
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2664 2665 2666 2667
    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)]
2668
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686
    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)]
2687
    e_transaction_list.append(transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2688 2689 2690 2691 2692 2693
    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)
2694

Guillaume Michon's avatar
Guillaume Michon committed
2695 2696 2697
    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)
2698

Guillaume Michon's avatar
Guillaume Michon committed
2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724
  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(
2725 2726
              '2004/01/01', -2500, 'depreciation_account', None, 'A', None))

Guillaume Michon's avatar
Guillaume Michon committed
2727
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2728
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2729 2730 2731 2732
    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)
2733 2734
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 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
  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))
2777
    
Guillaume Michon's avatar
Guillaume Michon committed
2778
    applied_rule_list = item.getCausalityRelatedValueList(portal_type='Applied Rule')
2779
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2780 2781 2782 2783
    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)
2784 2785
    
    
Guillaume Michon's avatar
Guillaume Michon committed
2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 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
  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')
2830
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864
    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')
2865
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 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
    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')
2917
    #LOG('Check number of applied rules for item', 0, item.getRelativeUrl())
Guillaume Michon's avatar
Guillaume Michon committed
2918 2919 2920 2921 2922 2923 2924
    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):
2925
    self.assertEquals(len(c_transaction_list), len(e_transaction_list))
2926
    e_removed_list = []
Guillaume Michon's avatar
Guillaume Michon committed
2927
    for c_transaction in c_transaction_list:
2928 2929 2930 2931 2932 2933 2934
      #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
2935 2936 2937 2938 2939 2940 2941 2942 2943
      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')
2944 2945
        if 'id' in key_list:
          key_list.remove('id')
Guillaume Michon's avatar
Guillaume Michon committed
2946 2947
        while key_cursor < len(key_list) and not wrong_transaction:
          key = key_list[key_cursor]
2948
          #LOG('key : ',0,key)
Guillaume Michon's avatar
Guillaume Michon committed
2949
          e_value = e_transaction[key]
2950
          #LOG('e_value : ',0,e_value)
Guillaume Michon's avatar
Guillaume Michon committed
2951 2952
          key = 'get' + ''.join([k.capitalize() for k in key.split('_')])
          c_value = getattr(c_transaction,key)()
2953
          #LOG('c_value : ',0,c_value)
Guillaume Michon's avatar
Guillaume Michon committed
2954 2955 2956 2957 2958 2959 2960
          is_float = 0
          try:
            if type(c_value) != type(DateTime()):
              c_value=float(c_value)
              is_float = 1
          except:
            pass
2961
          if type(c_value) == type([]):
2962
            c_value.sort(key=lambda x: x.getId())
2963
          if type(e_value) == type([]):
2964
            e_value.sort(key=lambda x: x.getId())
Guillaume Michon's avatar
Guillaume Michon committed
2965 2966 2967 2968 2969
          if is_float:
            wrong_transaction = (round(c_value,2) != round(e_value,2))
          else:
            wrong_transaction = (c_value != e_value)
          key_cursor += 1
2970
        #LOG('wrong_transaction',0,wrong_transaction)
Guillaume Michon's avatar
Guillaume Michon committed
2971 2972 2973 2974
        if not wrong_transaction:
          e_found_transaction = e_transaction
        e_cursor += 1
      if e_found_transaction is None:
2975
        #LOG('No expected transaction found for this calculated one !',0,'')
Guillaume Michon's avatar
Guillaume Michon committed
2976
        self.failUnless(e_found_transaction is not None)
2977 2978
      #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
2979 2980 2981
      e_line_list = e_transaction['line_list']
      c_line_list = c_transaction.contentValues()
      for c_line in c_line_list:
2982 2983 2984 2985 2986
        #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
2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012
        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
3013 3014
          else:
            LOG('c_value e_value', 0, (c_value, e_value))
Guillaume Michon's avatar
Guillaume Michon committed
3015 3016
          e_line_cursor += 1
        if e_found_line is None:
3017 3018 3019 3020 3021 3022 3023 3024
          import pprint
          self.fail('Calculated Transaction %s not expected:\n\t source=%s\n\tdestination=%s\n\tquantity=%s\n\tquantity_sign=%s\n%s' % (
                    c_line.getRelativeUrl(),
                    c_line.getSource(),
                    c_line.getDestination(),
                    c_line.getQuantity(),
                    c_line.getQuantitySign(),
                    pprint.pformat(e_line_list)))
Guillaume Michon's avatar
Guillaume Michon committed
3025 3026 3027
        e_line_list.remove(e_found_line)
      if len(e_line_list) > 0:
        self.assertEquals(len(e_line_list),0)
3028

Guillaume Michon's avatar
Guillaume Michon committed
3029 3030
    if len(e_transaction_list) > 0:
      self.assertEquals(len(e_transaction_list),0)
3031 3032 3033 3034

class TestImmobilisation(TestImmobilisationMixin):

  run_all_test = 1
3035

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

Guillaume Michon's avatar
Guillaume Michon committed
3042 3043 3044 3045 3046 3047 3048
  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)
3049
    sequence_list = SequenceList()
Guillaume Michon's avatar
Guillaume Michon committed
3050 3051 3052 3053 3054 3055
    sequence_string = 'SetTest01SequenceData \
                       CreatePackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       TestPackingListValidImmobilisationState \
                       AggregateItems \
3056
                       TestPackingListValidImmobilisationState \
Guillaume Michon's avatar
Guillaume Michon committed
3057 3058 3059
                       Tic \
                       TestPackingListValidImmobilisationState \
                      '
3060
    sequence_list.addSequenceString(sequence_string)
3061 3062
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3063 3064 3065 3066 3067
  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'] ]]
                  )
3068

Guillaume Michon's avatar
Guillaume Michon committed
3069 3070 3071 3072 3073 3074 3075 3076 3077
  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 \
3078
                       DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097
                       CreatePackingList \
                       AggregateItems \
                       CreatePackingList \
                       AggregateItems \
                       CreatePackingList \
                       AggregateItems \
                       Tic \
                       UseSecondPackingList \
                       EditPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       UseFirstPackingList \
                       TestPackingListValidImmobilisationState \
                       UseThirdPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       TestPackingListValidImmobilisationState \
                       UseSecondPackingList \
                       TestPackingListValidImmobilisationState \
                      '
3098
    sequence_list.addSequenceString(sequence_string)
3099 3100
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3101 3102 3103 3104 3105 3106 3107 3108
  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()
3109
    sequence_string = 'DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
3110 3111 3112 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
                       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 \
                      '
3151
    sequence_list.addSequenceString(sequence_string)
3152 3153
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3154 3155 3156 3157
  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)
3158

Guillaume Michon's avatar
Guillaume Michon committed
3159 3160 3161 3162 3163
  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)
3164

Guillaume Michon's avatar
Guillaume Michon committed
3165 3166 3167 3168 3169 3170 3171 3172 3173 3174
  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 \
3175
                       DeleteAllPackingLists Tic \
Guillaume Michon's avatar
Guillaume Michon committed
3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207
                       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 \
3208
                       TestPackingListInvalidImmobilisationState \
Guillaume Michon's avatar
Guillaume Michon committed
3209 3210 3211 3212 3213 3214 3215 3216
                       UseFourthPackingList \
                       TestPackingListCalculatingImmobilisationState \
                       Tic \
                       UseThirdPackingList \
                       TestPackingListInvalidImmobilisationState \
                       UseFourthPackingList \
                       TestPackingListInvalidImmobilisationState \
                      '
3217
    sequence_list.addSequenceString(sequence_string)
3218 3219
    sequence_list.play(self)

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

Guillaume Michon's avatar
Guillaume Michon committed
3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237
  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 \
                       '
3238
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3239 3240
    sequence_list.play(self)    

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

Guillaume Michon's avatar
Guillaume Michon committed
3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259
  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 \
                       '
3260
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3261 3262
    sequence_list.play(self)    

3263

Guillaume Michon's avatar
Guillaume Michon committed
3264 3265 3266 3267
  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})
3268

Guillaume Michon's avatar
Guillaume Michon committed
3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282
  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 \
                       '
3283
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3284 3285
    sequence_list.play(self)    
        
3286
    
Guillaume Michon's avatar
Guillaume Michon committed
3287 3288 3289 3290
  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})
3291

Guillaume Michon's avatar
Guillaume Michon committed
3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305
  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 \
                       '
3306
    sequence_list.addSequenceString(sequence_string)
3307 3308
    sequence_list.play(self)

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

Guillaume Michon's avatar
Guillaume Michon committed
3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325
  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 \
                       '
3326
    sequence_list.addSequenceString(sequence_string)
3327 3328
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3329 3330 3331 3332
  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})
3333

Guillaume Michon's avatar
Guillaume Michon committed
3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345
  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 \
                       '
3346
    sequence_list.addSequenceString(sequence_string)
3347 3348
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3349 3350 3351 3352
  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})
3353

Guillaume Michon's avatar
Guillaume Michon committed
3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366
  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 \
                       '
3367
    sequence_list.addSequenceString(sequence_string)
3368 3369 3370
    sequence_list.play(self)


Guillaume Michon's avatar
Guillaume Michon committed
3371 3372 3373 3374
  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})
3375

Guillaume Michon's avatar
Guillaume Michon committed
3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387
  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 \
                       '
3388
    sequence_list.addSequenceString(sequence_string)
3389 3390
    sequence_list.play(self)

Guillaume Michon's avatar
Guillaume Michon committed
3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407
  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 \
                       '
3408
    sequence_list.addSequenceString(sequence_string)
3409
    sequence_list.play(self)
Guillaume Michon's avatar
Guillaume Michon committed
3410 3411 3412 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


  # 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 \
                       '
3447
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3448 3449
    sequence_list.play(self)    
        
3450
    
Guillaume Michon's avatar
Guillaume Michon committed
3451 3452 3453 3454
  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})
3455

Guillaume Michon's avatar
Guillaume Michon committed
3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473
  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 \
                       '
3474
    sequence_list.addSequenceString(sequence_string)
Guillaume Michon's avatar
Guillaume Michon committed
3475 3476 3477 3478 3479 3480
    sequence_list.play(self)    


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

Guillaume Michon's avatar
Guillaume Michon committed
3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506
  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)
3507

Guillaume Michon's avatar
Guillaume Michon committed
3508 3509 3510 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
  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)
3542

Guillaume Michon's avatar
Guillaume Michon committed
3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554
  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 \
3555
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3556 3557 3558 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
                       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"])
3585

Guillaume Michon's avatar
Guillaume Michon committed
3586 3587 3588 3589 3590 3591 3592 3593
  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"])
3594

Guillaume Michon's avatar
Guillaume Michon committed
3595 3596 3597 3598 3599
  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'])
3600

3601 3602 3603 3604 3605 3606 3607 3608 3609 3610
  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')
3611 3612
    if preference.getPreferenceState() == 'disabled':
      preference.enable()
3613 3614 3615
    self.tic()
    # Now we can check several Accounting methods
    account = self.getPortal().account_module.account3
3616 3617
    self.assertEquals(10000.0,account.AccountModule_getTotalSourceDebit(brain=account))
    self.assertEquals(10000.0,account.AccountModule_getTotalSourceCredit(brain=account))
3618 3619 3620 3621 3622 3623 3624
    preference.edit(preferred_accounting_transaction_section_category=\
                        'group/group B')
    self.tic()
    self.assertEquals('group/group B',
        preference_tool.getPreferredAccountingTransactionSectionCategory())
    # Make sure to not use the cache
    self.portal.REQUEST['ERP5Accounting_getParams'] = None
3625 3626
    self.assertEquals(5000.0,account.AccountModule_getTotalSourceDebit(brain=account))
    self.assertEquals(0.0,account.AccountModule_getTotalSourceCredit(brain=account))
3627

Guillaume Michon's avatar
Guillaume Michon committed
3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641
  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 \
3642
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3643 3644 3645 3646 3647 3648 3649
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestSimpleAccountingBuild \
                       SetTest19SequenceData2 \
                       CreatePackingList \
3650
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675
                       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)    

3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703
  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
3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719

  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"])
3720

Guillaume Michon's avatar
Guillaume Michon committed
3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734
  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 \
3735
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3736 3737 3738 3739
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
3740 3741
                       ConfirmAmortisationTransaction \
                       Tic \
Guillaume Michon's avatar
Guillaume Michon committed
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
                       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"])
3767

Guillaume Michon's avatar
Guillaume Michon committed
3768 3769 3770 3771 3772
  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)
3773

Guillaume Michon's avatar
Guillaume Michon committed
3774 3775 3776 3777 3778
  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)
3779

Guillaume Michon's avatar
Guillaume Michon committed
3780 3781 3782 3783 3784
  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)
3785

Guillaume Michon's avatar
Guillaume Michon committed
3786 3787 3788 3789 3790
  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'])
3791

Guillaume Michon's avatar
Guillaume Michon committed
3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811
  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 \
3812
                       DeliverPackingList \
Guillaume Michon's avatar
Guillaume Michon committed
3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833
                       AggregateItems \
                       Tic \
                       BuildAccounting \
                       Tic \
                       TestSimpleAccountingBuild \
                       ValidateAccounting \
                       Tic \
                       Test21FirstModifyPackingList \
                       Tic \
                       TestFirstSimulationBuildAfterAccountingValidation \
                       Test21SecondModifyPackingList \
                       Tic \
                       TestSecondSimulationBuildAfterAccountingValidation \
                       Test21ThirdModifyPackingList \
                       Tic \
                       TestThirdSimulationBuildAfterAccountingValidation \
                       Test21FourthModifyPackingList \
                       Tic \
                       TestFourthSimulationBuildAfterAccountingValidation \
                       '
    sequence_list.addSequenceString(sequence_string)
3834
    sequence_list.play(self)
Guillaume Michon's avatar
Guillaume Michon committed
3835 3836


3837 3838 3839 3840
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestImmobilisation))
  return suite
Guillaume Michon's avatar
Guillaume Michon committed
3841