testERP5BankingForeignCashReception.py 18.2 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2 3 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 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
##############################################################################
#
# Copyright (c) 2006 Nexedi SARL and Contributors. All Rights Reserved.
#                    Aurelien Calonne <aurel@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.ERP5TypeTestCase import ERP5TypeTestCase
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.DCWorkflow.DCWorkflow import Unauthorized, ValidationFailed
from Products.ERP5Banking.tests.TestERP5BankingMixin import TestERP5BankingMixin

# 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'

# Define how to launch the script if we don't use runUnitTest script
if __name__ == '__main__':
  execfile(os.path.join(sys.path[0], 'framework.py'))



class TestERP5BankingForeignCashReception(TestERP5BankingMixin, ERP5TypeTestCase):
  """
    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

  not_defined_variation_list = ('variation/not_defined',)


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

  def getForeignCashReceptionModule(self):
    """
    Return the Cash Inventory Module
    """
    return getattr(self.getPortal(), 'foreign_cash_reception_module', None)


  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.foreign_cash_reception_module = self.getForeignCashReceptionModule()

    self.createManagerAndLogin()
    self.createFunctionGroupSiteCategory()
    self.createBanknotesAndCoins()
91
    self.reception = self.paris.caveau.auxiliaire.encaisse_des_devises.usd
Sebastien Robin's avatar
Sebastien Robin committed
92 93 94 95 96 97 98 99 100 101 102
    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()
    self.login('super_user')
103
    self.openCounterDate(site=self.paris)
Sebastien Robin's avatar
Sebastien Robin committed
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


  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 ForeignCashReception Module was created
    self.assertEqual(self.foreign_cash_reception_module.getPortalType(), 'Foreign Cash Reception Module')
    # check cash inventory module is empty
    self.assertEqual(len(self.foreign_cash_reception_module.objectValues()), 0)


  def stepCheckInitialInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check the initial inventory before any operations
    """
    self.simulation_tool = self.getSimulationTool()
    # check we have 0 banknotes of 50 in caisse_1
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 0.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 0.0)
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 0.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 0.0)


  def stepCreateForeignCashReception(self, sequence=None, sequence_list=None, **kwd):
    """
    Create a cash inventory document and check it
    """
135 136 137 138 139 140
    #and a price cooreponding to the sum of banknote of 50 and 20 
    #( (3) * 50 + (5) * 20 ) = 250
    self.foreign_cash_reception = self.foreign_cash_reception_module.newContent(
		    id='foreign_cash_reception', portal_type='Foreign Cash Reception',
                    source_value=None, destination_value=self.reception,
                    resource_value=self.currency_1,
141
                    description='test',
142
		    source_total_asset_price=250)
143 144
    # set source reference
    self.setDocumentSourceReference(self.foreign_cash_reception)
Sebastien Robin's avatar
Sebastien Robin committed
145 146 147 148 149 150 151 152 153
    # execute tic
    self.stepTic()
    # get the cash inventory document
    self.foreign_cash_reception = getattr(self.foreign_cash_reception_module, 'foreign_cash_reception')
    # check its portal type
    self.assertEqual(self.foreign_cash_reception.getPortalType(), 'Foreign Cash Reception')
    # check that its source is caisse_1
    self.assertEqual(self.foreign_cash_reception.getSource(), None)
    # check that its destination is caisse_2
154
    self.assertEqual(self.foreign_cash_reception.getBaobabDestination(), 'site/testsite/paris/caveau/auxiliaire/encaisse_des_devises/usd')
Sebastien Robin's avatar
Sebastien Robin committed
155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177

  def stepCreateValidLine1(self, sequence=None, sequence_list=None, **kwd):
    """
    Create the cash transfer line 1 with banknotes of 50 and check it has been well created
    """
    # create the cash transfer line
    self.addCashLineToDelivery(self.foreign_cash_reception, 'valid_line_1', 'Cash Delivery Line', self.usd_billet_50,
            ('emission_letter', 'cash_status', 'variation'), ('emission_letter/not_defined', 'cash_status/not_defined') +self.not_defined_variation_list,
            self.quantity_usd_50,
            variation_list=self.not_defined_variation_list)
    # execute tic
    self.stepTic()
    # check there is only one line created
    self.assertEqual(len(self.foreign_cash_reception.objectValues()), 1)
    # get the cash transfer line
    self.valid_line_1 = getattr(self.foreign_cash_reception, 'valid_line_1')
    # check its portal type
    self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Delivery Line')
    # check the resource is banknotes of 10000
    self.assertEqual(self.valid_line_1.getResourceValue(), self.usd_billet_50)
    # chek the value of the banknote
    self.assertEqual(self.valid_line_1.getPrice(), 50.0)
    # check the unit of banknote
178
    self.assertEqual(self.valid_line_1.getQuantityUnit(), 'unit')
Sebastien Robin's avatar
Sebastien Robin committed
179 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
    # check we have two delivery cells: (one for year 1992 and one for 2003)
    self.assertEqual(len(self.valid_line_1.objectValues()), 1)
    # now check for each variation (years 1992 and 2003)
    for variation in self.not_defined_variation_list:
      # get the delivery cell
      cell = self.valid_line_1.getCell('emission_letter/not_defined', 
                                 variation, 'cash_status/not_defined')
      # check portal types
      self.assertEqual(cell.getPortalType(), 'Cash Delivery Cell')
      # check the banknote of the cell is banknote of 10000
      self.assertEqual(cell.getResourceValue(), self.usd_billet_50)
      # check the source vault is None
      self.assertEqual(cell.getSourceValue(), None)
      # check the destination vault is counter
      self.assertEqual(cell.getDestinationValue(), self.reception)
      if cell.getId() == 'movement_0_0_0':
        # check the quantity of banknote 2
        self.assertEqual(cell.getQuantity(), 3.0)
      else:
        self.fail('Wrong cell created : %s' % cell.getId())

  def stepCreateValidLine2(self, sequence=None, sequence_list=None, **kwd):
    """
    Create the cash transfer line 1 with banknotes of 20 and check it has been well created
    """
    # create the cash transfer line
    self.addCashLineToDelivery(self.foreign_cash_reception, 'valid_line_2', 'Cash Delivery Line', self.usd_billet_20,
            ('emission_letter', 'cash_status', 'variation'), ('emission_letter/not_defined', 'cash_status/not_defined') +self.not_defined_variation_list,
            self.quantity_usd_20,
            variation_list=self.not_defined_variation_list)
    # execute tic
    self.stepTic()
    # check there is only one line created
    self.assertEqual(len(self.foreign_cash_reception.objectValues()), 2)
    # get the cash transfer line
    self.valid_line_1 = getattr(self.foreign_cash_reception, 'valid_line_2')
    # check its portal type
    self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Delivery Line')
    # check the resource is banknotes of 10000
    self.assertEqual(self.valid_line_1.getResourceValue(), self.usd_billet_20)
    # chek the value of the banknote
    self.assertEqual(self.valid_line_1.getPrice(), 20.0)
    # check the unit of banknote
222
    self.assertEqual(self.valid_line_1.getQuantityUnit(), 'unit')
Sebastien Robin's avatar
Sebastien Robin committed
223 224 225 226 227 228 229 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 256 257
    # check we have two delivery cells: (one for year 1992 and one for 2003)
    self.assertEqual(len(self.valid_line_1.objectValues()), 1)
    # now check for each variation (years 1992 and 2003)
    for variation in self.not_defined_variation_list:
      # get the delivery cell
      cell = self.valid_line_1.getCell('emission_letter/not_defined', 
                                 variation, 'cash_status/not_defined')
      # check portal types
      self.assertEqual(cell.getPortalType(), 'Cash Delivery Cell')
      # check the banknote of the cell is banknote of 10000
      self.assertEqual(cell.getResourceValue(), self.usd_billet_20)
      # check the source vault is None
      self.assertEqual(cell.getSourceValue(), None)
      # check the destination vault is counter
      self.assertEqual(cell.getDestinationValue(), self.reception)
      if cell.getId() == 'movement_0_0_0':
        # check the quantity of banknote 2
        self.assertEqual(cell.getQuantity(), 5.0)
      else:
        self.fail('Wrong cell created : %s' % cell.getId())


  def stepCheckValidLine1(self, sequence=None, sequence_list=None):
    """
    Check the cash delivery line
    """
    # check the cash delivery line
    self.valid_line_1 = getattr(self.foreign_cash_reception, 'valid_line_1')
    # check its portal type
    self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Delivery Line')
    # check the resource is banknotes of 50
    self.assertEqual(self.valid_line_1.getResourceValue(), self.usd_billet_50)
    # chek the value of the banknote
    self.assertEqual(self.valid_line_1.getPrice(), 50.0)
    # check the unit of banknote
258
    self.assertEqual(self.valid_line_1.getQuantityUnit(), 'unit')
Sebastien Robin's avatar
Sebastien Robin committed
259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
    # check we have one delivery cells
    self.assertEqual(len(self.valid_line_1.objectValues()), 1)
    # now check for variation 
    variation = 'variation/not_defined'
    # get the delivery cell
    cell = self.valid_line_1.getCell('emission_letter/not_defined', variation, 'cash_status/not_defined')
    # chek portal types
    self.assertEqual(cell.getPortalType(), 'Cash Delivery Cell')
    # check the banknote of the cell is banknote of 50
    self.assertEqual(cell.getResourceValue(), self.usd_billet_50)
    # check the source vault is caisse_1
    self.assertEqual(cell.getSourceValue(), None)
    # check the destination vault is caisse_2
    self.assertEqual(cell.getDestinationValue(), self.reception)
    self.assertEqual(cell.getQuantity(), 3.0)

  def stepCheckValidLine2(self, sequence=None, sequence_list=None):
    """
    Check the cash delivery line
    """
    # check the cash delivery line
    self.valid_line_1 = getattr(self.foreign_cash_reception, 'valid_line_2')
    # check its portal type
    self.assertEqual(self.valid_line_1.getPortalType(), 'Cash Delivery Line')
    # check the resource is banknotes of 50
    self.assertEqual(self.valid_line_1.getResourceValue(), self.usd_billet_20)
    # chek the value of the banknote
    self.assertEqual(self.valid_line_1.getPrice(), 20.0)
    # check the unit of banknote
288
    self.assertEqual(self.valid_line_1.getQuantityUnit(), 'unit')
Sebastien Robin's avatar
Sebastien Robin committed
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310
    # check we have one delivery cells
    self.assertEqual(len(self.valid_line_1.objectValues()), 1)
    # now check for variation 
    variation = 'variation/not_defined'
    # get the delivery cell
    cell = self.valid_line_1.getCell('emission_letter/not_defined', variation, 'cash_status/not_defined')
    # chek portal types
    self.assertEqual(cell.getPortalType(), 'Cash Delivery Cell')
    # check the banknote of the cell is banknote of 50
    self.assertEqual(cell.getResourceValue(), self.usd_billet_20)
    # check the source vault is caisse_1
    self.assertEqual(cell.getSourceValue(), None)
    # check the destination vault is caisse_2
    self.assertEqual(cell.getDestinationValue(), self.reception)
    self.assertEqual(cell.getQuantity(), 5.0)

  def stepConfirmForeignCashReception(self, sequence=None, sequence_list=None, **kwd):
    """
    confirm the foreign cash reception
    """
    state = self.foreign_cash_reception.getSimulationState()
    # check that state is draft
311
    self.assertEqual(state, 'empty')
Sebastien Robin's avatar
Sebastien Robin committed
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357
    self.workflow_tool.doActionFor(self.foreign_cash_reception, 'confirm_action', wf_id='foreign_cash_reception_workflow')
    self.assertEqual(self.foreign_cash_reception.getSimulationState(), 'confirmed')
    workflow_history = self.workflow_tool.getInfoFor(ob=self.foreign_cash_reception, name='history', wf_id='foreign_cash_reception_workflow')
    # check len of len workflow history is 6
    self.assertEqual(len(workflow_history), 3)


  def stepCheckConfirmedInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check that compution of inventory at vault caisse_2 is right after confirm and before deliver
    """
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 0.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 3.0)
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 0.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 5.0)


  def stepDeliverForeignCashReception(self, sequence=None, sequence_list=None, **kw):
    """
    Deliver the foreign cash reception
    """
    state = self.foreign_cash_reception.getSimulationState()
    # check that state is draft
    self.assertEqual(state, 'confirmed')
    self.workflow_tool.doActionFor(self.foreign_cash_reception, 'deliver_action', wf_id='foreign_cash_reception_workflow')
    # execute tic
    self.stepTic()
    # get state of cash sorting
    state = self.foreign_cash_reception.getSimulationState()
    # check that state is delivered
    self.assertEqual(state, 'delivered')
    # get workflow history
    workflow_history = self.workflow_tool.getInfoFor(ob=self.foreign_cash_reception, name='history', wf_id='foreign_cash_reception_workflow')
    # check len of len workflow history is 6
    self.assertEqual(len(workflow_history), 5)


  def stepCheckFinalInventory(self, sequence=None, sequence_list=None, **kwd):
    """
    Check that compution of inventory at vault caisse_2 is right after confirm and before deliver
    """
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 3.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_50.getRelativeUrl()), 3.0)
    self.assertEqual(self.simulation_tool.getCurrentInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 5.0)
    self.assertEqual(self.simulation_tool.getFutureInventory(node=self.reception.getRelativeUrl(), resource = self.usd_billet_20.getRelativeUrl()), 5.0)

Sebastien Robin's avatar
Sebastien Robin committed
358 359 360
  def stepCheckWorklist(self, **kw):
    self.checkWorklist(self.foreign_cash_reception)

Sebastien Robin's avatar
Sebastien Robin committed
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378
  ##################################
  ##  Tests
  ##################################

  def test_01_ERP5BankingForeignCashReception(self, quiet=QUIET, run=RUN_ALL_TEST):
    """
    Define the sequence of step that will be play
    """
    if not run: return
    sequence_list = SequenceList()
    # define the sequence
    sequence_string = 'Tic CheckObjects Tic ' \
                    + 'CheckInitialInventory ' \
                    + 'CreateForeignCashReception Tic ' \
                    + 'CreateValidLine1 Tic ' \
                    + 'CreateValidLine2 Tic ' \
                    + 'CheckValidLine1 ' \
                    + 'CheckValidLine2 ' \
Sebastien Robin's avatar
Sebastien Robin committed
379
                    + 'Tic CheckWorklist ' \
Sebastien Robin's avatar
Sebastien Robin committed
380 381
                    + 'ConfirmForeignCashReception Tic ' \
                    + 'CheckConfirmedInventory ' \
Sebastien Robin's avatar
Sebastien Robin committed
382
                    + 'Tic CheckWorklist ' \
Sebastien Robin's avatar
Sebastien Robin committed
383 384 385 386 387 388 389 390 391 392 393 394 395 396 397
                    + 'DeliverForeignCashReception Tic ' \
                    + 'CheckFinalInventory'
    sequence_list.addSequenceString(sequence_string)
    # play the sequence
    sequence_list.play(self)

# define how we launch the unit test
if __name__ == '__main__':
  framework()
else:
  import unittest
  def test_suite():
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(TestERP5BankingForeignCashReception))
    return suite