testERP5BankingCheckbookUsualCashTransfer.py 18.9 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2
##############################################################################
#
3
# Copyright (c) 2006-2010 Nexedi SA and Contributors. All Rights Reserved.
Sebastien Robin's avatar
Sebastien Robin committed
4 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 30 31 32
#                    Sebastien Robin <seb@nexedi.com>
#
# 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.
#
##############################################################################


# import requested python module
import os
from Products.ERP5Type.tests.Sequence import SequenceList
33
from Products.DCWorkflow.DCWorkflow import ValidationFailed
Sebastien Robin's avatar
Sebastien Robin committed
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
from Products.ERP5Banking.tests.testERP5BankingCheckbookVaultTransfer \
     import TestERP5BankingCheckbookVaultTransferMixin
from zLOG import LOG

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE']     = os.path.join(os.getcwd(), 'zLOG.log')
# Define the level of log we want, here is all
os.environ['EVENT_LOG_SEVERITY'] = '-300'

class TestERP5BankingCheckbookUsualCashTransferMixin(
          TestERP5BankingCheckbookVaultTransferMixin):

  def createCheckbookVaultTransfer(self, sequence=None, sequence_list=None, **kwd):
    """
    Create a checkbook Reception
    We do not need to check it because it is already done in another unit test.
    """
    self.checkbook_vault_transfer = self.getCheckbookVaultTransferModule().newContent(
                     id='checkbook_vault_transfer', portal_type='Checkbook Vault Transfer',
53
                     source_value=self.vault_transfer_source_site,
Sebastien Robin's avatar
Sebastien Robin committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
                     destination_value=self.vault_transfer_destination_site,
                     start_date=(self.date-3))
    # Add a line for check and checkbook
    self.line_1 = self.checkbook_vault_transfer.newContent(quantity=1,
                                 resource_value=self.checkbook_model_1,
                                 check_amount_value=self.checkbook_model_1.variant_1,
                                 destination_trade_value=self.bank_account_1,
                                 aggregate_value=self.checkbook_1,
                                 )
    self.line_2 = self.checkbook_vault_transfer.newContent(quantity=1,
                                 resource_value=self.check_model_1,
                                 check_amount_value=None,
                                 destination_trade_value=self.bank_account_2,
                                 aggregate_value=self.check_1,
                                 )
69
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'order_action',
Sebastien Robin's avatar
Sebastien Robin committed
70
                                   wf_id='checkbook_vault_transfer_workflow')
71
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'confirm_action',
72
                                   wf_id='checkbook_vault_transfer_workflow')
73
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'deliver_action',
Sebastien Robin's avatar
Sebastien Robin committed
74 75
                                   wf_id='checkbook_vault_transfer_workflow')

76
  def createCheckbookVaultTransferWithTravelerCheck(self, sequence=None,
77 78 79 80 81 82 83
                                 sequence_list=None, **kwd):
    """
    Create a checkbook Reception
    We do not need to check it because it is already done in another unit test.
    """
    self.checkbook_vault_transfer = self.getCheckbookVaultTransferModule().newContent(
                     id='checkbook_vault_transfer', portal_type='Checkbook Vault Transfer',
84
                     source_value=self.vault_transfer_source_site,
85
                     destination_value=self.vault_transfer_destination_site,
86
                     description='test',
87 88 89 90
                     start_date=(self.date-3))
    # Add a line for traveler check
    self.line_2 = self.checkbook_vault_transfer.newContent(quantity=1,
                             resource_value=self.traveler_check_model,
91
                             check_type_value=self.traveler_check_model.variant_1,
92
                             aggregate_value=self.traveler_check,
93
                             price_currency_value=self.currency_2
94
                             )
95
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'order_action',
96
                                   wf_id='checkbook_vault_transfer_workflow')
97
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'confirm_action',
98
                                   wf_id='checkbook_vault_transfer_workflow')
99
    self.workflow_tool.doActionFor(self.checkbook_vault_transfer, 'deliver_action',
100
                                   wf_id='checkbook_vault_transfer_workflow')
Sebastien Robin's avatar
Sebastien Robin committed
101

102
class TestERP5BankingCheckbookUsualCashTransfer(TestERP5BankingCheckbookUsualCashTransferMixin):
Sebastien Robin's avatar
Sebastien Robin committed
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
  """
    This class is a unit test to check the module of Cash Transfer

    Here are the following step that will be done in the test :

    XXX to be completed

  """


  # pseudo constants
  RUN_ALL_TEST = 1 # we want to run all test
  QUIET = 0 # we don't want the test to be quiet


  def getTitle(self):
    """
      Return the title of the test
    """
    return "ERP5BankingCheckbookUsualCashTransfer"

  def afterSetUp(self):
    """
      Method called before the launch of the test to initialize some data
    """
    # Set some variables :
    self.initDefaultVariable()
    # the cash inventory module
    self.checkbook_usual_cash_transfer_module = self.getCheckbookUsualCashTransferModule()
    self.checkbook_reception_module = self.getCheckbookReceptionModule()
    self.check_module = self.getCheckModule()
    self.checkbook_module = self.getCheckbookModule()
    self.checkbook_model_module = self.getCheckbookModelModule()

    self.createManagerAndLogin()
    self.createFunctionGroupSiteCategory()
139
    self.createCheckAndCheckbookModel()
Sebastien Robin's avatar
Sebastien Robin committed
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    self.vault_transfer_source_site = self.paris.caveau
    self.vault_transfer_destination_site = self.paris.surface
    self.source_site = self.paris.surface.caisse_courante
    self.reception_destination_site = self.paris
    self.destination_site = self.paris.surface.banque_interne.guichet_1
    self.source_vault = self.paris.surface.caisse_courante.encaisse_des_billets_et_monnaies
    self.destination_vault = self.paris.surface.banque_interne.guichet_1.encaisse_des_billets_et_monnaies
    self.checkUserFolderType()
    self.organisation = self.organisation_module.newContent(id='baobab_org', portal_type='Organisation',
                          function='banking', group='baobab',  site='testsite/paris')
    # define the user
    user_dict = {
        'super_user' : [['Manager'], self.organisation, 'banking/comptable', 'baobab', 'testsite/paris']
      }
    # call method to create this user
    self.createERP5Users(user_dict)
    self.logout()
157
    self.loginByUserName('super_user')
Sebastien Robin's avatar
Sebastien Robin committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

    # create a person and a bank account
    self.person_1 = self.createPerson(id='person_1',
                                      first_name='Sebastien',
                                      last_name='Robin')
    self.bank_account_1 = self.createBankAccount(person=self.person_1,
                                                 account_id='bank_account_1',
                                                 currency=self.currency_1,
                                                 amount=100000)
    # create a person and a bank account
    self.person_2 = self.createPerson(id='person_2',
                                      first_name='Aurelien',
                                      last_name='Calonne')
    self.bank_account_2 = self.createBankAccount(person=self.person_2,
                                                 account_id='bank_account_1',
                                                 currency=self.currency_1,
                                                 amount=100000)
    # this is required in order to have some items
    # in the source
    self.createCheckbookReception()
    self.checkItemsCreated()
179
    self.tic()
Sebastien Robin's avatar
Sebastien Robin committed
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221
    self.createCheckbookVaultTransfer()


  def stepCheckObjects(self, sequence=None, sequence_list=None, **kwd):
    """
    Check that all the objects we created in afterSetUp or
    that were added by the business template and that we rely
    on are really here.
    """
    self.checkResourceCreated()
    # check that CheckbookUsualCashTransfer Module was created
    self.assertEqual(self.checkbook_usual_cash_transfer_module.getPortalType(), 'Checkbook Usual Cash Transfer Module')
    # check cash inventory module is empty
    self.assertEqual(len(self.checkbook_usual_cash_transfer_module.objectValues()), 0)


  def stepCheckInitialCheckbookInventory(self, sequence=None, sequence_list=None, **kw):
    """
    Check initial cash checkbook on source
    """
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 2)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 2)
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                             node=self.destination_vault.getRelativeUrl(),
                             at_date=self.date)), 0)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                             node=self.destination_vault.getRelativeUrl(),
                             at_date=self.date)), 0)

  def stepCreateCheckbookUsualCashTransfer(self, sequence=None, sequence_list=None, **kwd):
    """
    Create a checkbook usual cash transfer
    """
    # We will do the transfer ot two items.
    self.checkbook_usual_cash_transfer = self.checkbook_usual_cash_transfer_module.newContent(
                     id='checkbook_usual_cash_transfer', portal_type='Checkbook Usual Cash Transfer',
                     source_value=self.source_site, destination_value=self.destination_site,
                     resource_value=self.currency_1,
222
                     start_date=(self.date-3.1))
Sebastien Robin's avatar
Sebastien Robin committed
223 224 225
    # check its portal type
    self.assertEqual(self.checkbook_usual_cash_transfer.getPortalType(), 'Checkbook Usual Cash Transfer')
    # check source
226
    self.assertEqual(self.checkbook_usual_cash_transfer.getBaobabSource(),
Sebastien Robin's avatar
Sebastien Robin committed
227 228
               'site/testsite/paris/surface/caisse_courante/encaisse_des_billets_et_monnaies')
    # check destination
229
    self.assertEqual(self.checkbook_usual_cash_transfer.getBaobabDestination(),
Sebastien Robin's avatar
Sebastien Robin committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
               'site/testsite/paris/surface/banque_interne/guichet_1/encaisse_des_billets_et_monnaies')


  def stepCreateCheckAndCheckbookLineList(self, sequence=None, sequence_list=None, **kwd):
    """
    Create the checkbook
    """
    # This is not required to create checkbook items, they will be
    # automatically created with the confirm action worfklow transition

    # Add a line for check and checkbook
    self.line_1 = self.checkbook_usual_cash_transfer.newContent(quantity=1,
                                 resource_value=self.checkbook_model_1,
                                 check_amount_value=self.checkbook_model_1.variant_1,
                                 reference_range_min=1,
                                 reference_range_max=50,
                                 aggregate_value=self.checkbook_1
                                 )
    self.line_2 = self.checkbook_usual_cash_transfer.newContent(quantity=1,
                                 resource_value=self.check_model_1,
                                 check_amount_value=None,
                                 reference_range_min=51,
                                 reference_range_max=51,
                                 aggregate_value=self.check_1
                                 )

256 257 258 259 260
  def stepCheckConfirmCheckbookUsualCashTransferRaiseError(self, sequence=None, sequence_list=None, **kwd):
    """
    confirm the checkbook usual cash transfer
    """
    state = self.checkbook_usual_cash_transfer.getSimulationState()
261 262
    self.assertRaises(ValidationFailed, self.workflow_tool.doActionFor,
                      self.checkbook_usual_cash_transfer, 'confirm_action',
263 264 265
                      wf_id='checkbook_usual_cash_transfer_workflow')
    workflow_history = self.workflow_tool.getInfoFor(ob=self.checkbook_usual_cash_transfer, name='history', wf_id='checkbook_usual_cash_transfer_workflow')

Sebastien Robin's avatar
Sebastien Robin committed
266 267 268 269 270 271 272 273 274
  def stepConfirmCheckbookUsualCashTransfer(self, sequence=None, sequence_list=None, **kwd):
    """
    confirm the checkbook usual cash transfer
    """
    state = self.checkbook_usual_cash_transfer.getSimulationState()
    self.assertEqual(state, 'draft')
    self.workflow_tool.doActionFor(self.checkbook_usual_cash_transfer, 'confirm_action', wf_id='checkbook_usual_cash_transfer_workflow')
    self.assertEqual(self.checkbook_usual_cash_transfer.getSimulationState(), 'confirmed')
    workflow_history = self.workflow_tool.getInfoFor(ob=self.checkbook_usual_cash_transfer, name='history', wf_id='checkbook_usual_cash_transfer_workflow')
275 276

  def stepChangeCheckbookUsualCashTransferStartDate(self,
277 278 279 280 281
               sequence=None, sequence_list=None, **kw):
    """
    Set a correct date
    """
    self.checkbook_usual_cash_transfer.edit(start_date=self.date)
Sebastien Robin's avatar
Sebastien Robin committed
282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307

  def stepCheckConfirmedCheckbookInventory(self, sequence=None, sequence_list=None, **kw):
    """
    Check cash checkbook in item table
    """
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 2)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 0)
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                     node=self.destination_vault.getRelativeUrl(),
                     at_date=self.date)), 0)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                     node=self.destination_vault.getRelativeUrl(),
                     at_date=self.date)), 2)


  def stepDeliverCheckbookUsualCashTransfer(self, sequence=None, sequence_list=None, **kw):
    """
    Deliver the checkbook usual cash transfer
    """
    state = self.checkbook_usual_cash_transfer.getSimulationState()
    # check that state is draft
    self.assertEqual(state, 'confirmed')
308 309
    self.workflow_tool.doActionFor(self.checkbook_usual_cash_transfer,
                                   'confirm_to_deliver_action',
Sebastien Robin's avatar
Sebastien Robin committed
310 311 312 313 314 315 316 317 318 319
                                   wf_id='checkbook_usual_cash_transfer_workflow')
    # get state of cash sorting
    state = self.checkbook_usual_cash_transfer.getSimulationState()
    # check that state is delivered
    self.assertEqual(state, 'delivered')

  def stepCheckFinalCheckbookInventory(self, sequence=None, sequence_list=None, **kw):
    """
    Check cash checkbook in item table
    """
Grégory Wisniewski's avatar
Grégory Wisniewski committed
320
    LOG('sql request for getCurrentTrackingList', 0, self.simulation_tool.getCurrentTrackingList(
Sebastien Robin's avatar
Sebastien Robin committed
321
                     node=self.source_vault.getRelativeUrl(),
Grégory Wisniewski's avatar
Grégory Wisniewski committed
322
                     at_date=self.date, src__=1))
Sebastien Robin's avatar
Sebastien Robin committed
323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 0)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                     node=self.source_vault.getRelativeUrl(),
                     at_date=self.date)), 0)
    self.assertEqual(len(self.simulation_tool.getCurrentTrackingList(
                     node=self.destination_vault.getRelativeUrl(),
                     at_date=self.date)), 2)
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                     node=self.destination_vault.getRelativeUrl(),
                     at_date=self.date)), 2)
    checkbook_list = self.simulation_tool.getCurrentTrackingList(
                             node=self.destination_vault.getRelativeUrl(),
                             at_date=self.date)
    self.assertEqual(len(checkbook_list), 2)
    # check we have cash checkbook 1
    checkbook_object_list = [x.getObject() for x in checkbook_list]
Grégory Wisniewski's avatar
Grégory Wisniewski committed
341
    self.failIfDifferentSet(checkbook_object_list, [self.checkbook_1, self.check_1])
Sebastien Robin's avatar
Sebastien Robin committed
342 343 344 345
    self.assertEqual(len(self.simulation_tool.getFutureTrackingList(
                node=self.destination_vault.getRelativeUrl(),
                at_date=self.date)), 2)

346
  def stepChangePreviousDeliveryDate(self,
347 348 349 350 351 352 353 354 355 356 357 358 359
               sequence=None, sequence_list=None, **kwd):
    """
    Reset a vault
    """
    self.previous_delivery = self.checkbook_vault_transfer
    self.previous_date = self.previous_delivery.getStartDate()
    self.previous_delivery.edit(start_date=self.date+5)

  def stepDeliverCheckbookUsualCashTransferFails(self, sequence=None, sequence_list=None, **kwd):
    """
    Try if we get Insufficient balance
    """
    message = self.assertWorkflowTransitionFails(self.checkbook_usual_cash_transfer,
Grégory Wisniewski's avatar
Grégory Wisniewski committed
360
              'checkbook_usual_cash_transfer_workflow', 'confirm_to_deliver_action')
361 362
    self.assertTrue(message.find('Sorry, the item with reference')>=0)
    self.assertTrue(message.find('is not available any more')>=0)
363

Sebastien Robin's avatar
Sebastien Robin committed
364 365 366 367 368 369 370 371
  ##################################
  ##  Tests
  ##################################

  def test_01_ERP5BankingCheckbookUsualCashTransfer(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
    Define the sequence of step that will be play
    """
372 373
    if not run:
      return
Sebastien Robin's avatar
Sebastien Robin committed
374 375 376 377 378
    sequence_list = SequenceList()
    # define the sequence
    sequence_string = 'Tic CheckObjects Tic CheckInitialCheckbookInventory ' \
                    + 'CreateCheckbookUsualCashTransfer Tic ' \
                    + 'CreateCheckAndCheckbookLineList Tic ' \
379 380
                    + 'CheckConfirmCheckbookUsualCashTransferRaiseError Tic ' \
                    + 'ChangeCheckbookUsualCashTransferStartDate Tic ' \
Sebastien Robin's avatar
Sebastien Robin committed
381 382
                    + 'ConfirmCheckbookUsualCashTransfer Tic ' \
                    + 'CheckConfirmedCheckbookInventory Tic ' \
383 384 385
                    + 'ChangePreviousDeliveryDate Tic ' \
                    + 'DeliverCheckbookUsualCashTransferFails Tic ' \
                    + 'PutBackPreviousDeliveryDate Tic ' \
Sebastien Robin's avatar
Sebastien Robin committed
386 387 388 389 390 391
                    + 'DeliverCheckbookUsualCashTransfer Tic ' \
                    + 'CheckFinalCheckbookInventory'
    sequence_list.addSequenceString(sequence_string)
    # play the sequence
    sequence_list.play(self)