testOrder.py 66.7 KB
Newer Older
Romain Courteaud's avatar
Romain Courteaud 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
##############################################################################
#
# Copyright (c) 2004, 2005 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
#          Romain Courteaud <romain@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.
#
##############################################################################

#
# Skeleton ZopeTestCase
#

from random import randint

import os, sys
if __name__ == '__main__':
    execfile(os.path.join(sys.path[0], 'framework.py'))

# Needed in order to have a log file inside the current folder
os.environ['EVENT_LOG_FILE'] = os.path.join(os.getcwd(), 'zLOG.log')
os.environ['EVENT_LOG_SEVERITY'] = '-300'

from Testing import ZopeTestCase
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from AccessControl.SecurityManagement import newSecurityManager, \
                                             noSecurityManager
from DateTime import DateTime
from Acquisition import aq_base, aq_inner
from zLOG import LOG
from Products.ERP5Type.DateUtils import addToDate
from Products.ERP5Type.tests.Sequence import Sequence, SequenceList
import time
import os
from Products.ERP5Type import product_path
from Products.CMFCore.utils import getToolByName

58
class TestOrderMixin:
Romain Courteaud's avatar
Romain Courteaud committed
59

60
  run_all_test = 1
Romain Courteaud's avatar
Romain Courteaud committed
61 62 63 64 65 66 67 68
  default_quantity = 99
  default_price = 555
  resource_portal_type = 'Apparel Model'
  order_portal_type = 'Sale Order'
  order_line_portal_type = 'Sale Order Line'
  cell_portal_type = 'Delivery Cell'
  applied_rule_portal_type = 'Applied Rule'
  datetime = DateTime()
69 70
  packing_list_portal_type = 'Sale Packing List'
  packing_list_line_portal_type = 'Sale Packing List Line'
71
  packing_list_cell_portal_type = 'Sale Packing List Cell'
72
  delivery_builder_id = 'sale_packing_list_builder'
73
  order_workflow_id='order_workflow'
74 75 76 77 78
  size_list = ['Baby','Child/32','Child/34','Man','Woman'] 

  def stepCommit(self,**kw):
    get_transaction().commit()

Romain Courteaud's avatar
Romain Courteaud committed
79 80 81 82

  def getBusinessTemplateList(self):
    """
    """
Sebastien Robin's avatar
Sebastien Robin committed
83
    return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_apparel',)
Romain Courteaud's avatar
Romain Courteaud committed
84 85 86

  def login(self, quiet=0, run=run_all_test):
    uf = self.getPortal().acl_users
87
    uf._doAddUser('rc', '', ['Manager', 'Member'], [])
Romain Courteaud's avatar
Romain Courteaud committed
88 89 90 91 92 93 94 95
    user = uf.getUserById('rc').__of__(uf)
    newSecurityManager(None, user)

  def afterSetUp(self, quiet=1, run=run_all_test):
    self.login()
    portal = self.getPortal()
    self.category_tool = self.getCategoryTool()
    portal_catalog = self.getCatalogTool()
96
    #portal_catalog.manage_catalogClear()
Romain Courteaud's avatar
Romain Courteaud committed
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
    self.createCategories()

  def createCategories(self):
    """ 
      Light install create only base categories, so we create 
      some categories for testing them
    """
    size_category_list = ['Baby', 'Child', 'Man', 'Woman']
    if len(self.category_tool.size.contentValues()) == 0 :
      for category_id in size_category_list:
        o = self.category_tool.size.newContent(portal_type='Category',
                                               id=category_id)
      for category_id in ['32', '34']:
        o = self.category_tool.size.Child.newContent(portal_type='Category',
                                                     id=category_id)

    colour_category_list = ['blue', 'green']
    if len(self.category_tool.colour.contentValues()) == 0 :
      for category_id in colour_category_list:
        o = self.category_tool.colour.newContent(portal_type='Category',
                                                 id=category_id)

119 120 121 122 123 124 125 126
    industrial_phase_category_list = ['phase1', 'phase2',
                                      'supply_phase1', 'supply_phase2']
    if len(self.category_tool.industrial_phase.contentValues()) == 0:
      for category_id in industrial_phase_category_list:
        o = self.category_tool.industrial_phase.newContent(
                                                 portal_type='Category',
                                                 id=category_id)

127 128 129 130 131 132 133
    product_line_category_list = ['apparel', ]
    if len(self.category_tool.product_line.contentValues()) == 0:
      for category_id in product_line_category_list:
        o = self.category_tool.product_line.newContent(
                                                 portal_type='Category',
                                                 id=category_id)
  
Romain Courteaud's avatar
Romain Courteaud committed
134 135 136 137 138 139 140 141 142 143 144 145
  def stepTic(self,**kw):
    self.tic()

  def stepCreateNotVariatedResource(self,sequence=None, sequence_list=None, \
                                    **kw):
    """
      Create a resource with no variation
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(portal_type=self.resource_portal_type)
    resource.edit(
146
      title = "NotVariatedResource",
147 148
      industrial_phase_list=["phase1", "phase2"],
      product_line = 'apparel'
Romain Courteaud's avatar
Romain Courteaud committed
149 150 151
    )

    sequence.edit( resource = resource )
152 153 154
    resource_list = sequence.get('resource_list',default=[])
    resource_list.append(resource)
    sequence.edit( resource_list = resource_list )
Romain Courteaud's avatar
Romain Courteaud committed
155 156 157 158 159 160 161 162 163 164

  def stepCreateVariatedResource(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
      Create a resource with no variation
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(portal_type=self.resource_portal_type)
    resource.edit(
165
      title = "VariatedResource",
166 167
      industrial_phase_list=["phase1", "phase2"],
      product_line = 'apparel'
Romain Courteaud's avatar
Romain Courteaud committed
168
    )
169
    resource.setSizeList(self.size_list) 
Romain Courteaud's avatar
Romain Courteaud committed
170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187
    # Add colour variation
    colour_variation_count = 3
    for i in range(colour_variation_count):
      variation_portal_type = 'Apparel Model Colour Variation'
      variation = resource.newContent(portal_type = variation_portal_type)
      variation.edit(
        title = 'ColourVariation%s' % str(i)
      )
    # Add morphology variation
    morphology_variation_count = 2
    for i in range(morphology_variation_count) :
      variation_portal_type = 'Apparel Model Morphology Variation'
      variation = resource.newContent(portal_type=variation_portal_type)
      variation.edit(
        title = 'MorphologyVariation%s' % str(i)
      )

    sequence.edit( resource = resource )
188 189 190
    resource_list = sequence.get('resource_list',default=[])
    resource_list.append(resource)
    sequence.edit( resource_list = resource_list )
Romain Courteaud's avatar
Romain Courteaud committed
191

192 193
  def stepCreateOrganisation(self, sequence=None, sequence_list=None, 
                             title='organisation', **kw):
Romain Courteaud's avatar
Romain Courteaud committed
194 195 196 197 198 199 200 201 202 203 204
    """
      Create a empty organisation
    """
    organisation = sequence.get('organisation')
    organisation_portal_type = 'Organisation'
    portal = self.getPortal()
    organisation_module = portal.getDefaultModule( \
                                   portal_type=organisation_portal_type)
    organisation = organisation_module.newContent( \
                                   portal_type=organisation_portal_type)
    organisation.edit(
205
      title=title,
Romain Courteaud's avatar
Romain Courteaud committed
206
    )
207 208
    #sequence.edit(organisation=organisation)
    sequence.edit(**{title:organisation})
Romain Courteaud's avatar
Romain Courteaud committed
209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

  def stepCreateOrder(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty order
    """
    organisation = sequence.get('organisation')
#     person = sequence.get('person')
    portal = self.getPortal()
    order_module = portal.getDefaultModule(portal_type=self.order_portal_type)
    order = order_module.newContent(portal_type=self.order_portal_type)
    order.edit(
      title = "Order",
      start_date = self.datetime + 10,
      stop_date = self.datetime + 20,
    )
    if organisation is not None:
Romain Courteaud's avatar
Romain Courteaud committed
225 226 227 228
      order.edit(source_value=organisation,
                 source_section_value=organisation,
                 destination_value=organisation,
                 destination_section_value=organisation)
Romain Courteaud's avatar
Romain Courteaud committed
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 258 259 260 261 262 263
    sequence.edit( order = order )

  def stepCheckOrder(self, sequence=None, sequence_list=None, **kw):
    """
      Check if order was well created
    """
    organisation = sequence.get('organisation')
    order = sequence.get('order')
    self.assertEquals(self.datetime+10, order.getStartDate())
    self.assertEquals(self.datetime+20, order.getStopDate())
    self.assertEquals(organisation, order.getSourceValue())
    self.assertEquals(organisation, order.getDestinationValue())
    self.assertEquals(organisation, order.getSourceSectionValue())
    self.assertEquals(organisation, order.getDestinationSectionValue())

  def stepCreateOrderLine(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty order line
    """
    order = sequence.get('order')
    order_line = order.newContent(portal_type=self.order_line_portal_type)
    order_line.edit(
      title = "Order Line"
    )
    sequence.edit(order_line=order_line)

  def stepCheckOrderLineEmptyMatrix(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check if the matrix of the current order line is empty.
    """
    order_line = sequence.get('order_line')
    base_id = 'movement'
#     vcl = list(order_line.getVariationCategoryList())
#     cell_key_list = order_line.getCellKeyList(base_id=base_id)
264
    cell_list = order_line.objectValues(portal_type=self.cell_portal_type)
Romain Courteaud's avatar
Romain Courteaud committed
265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
#     self.failIfDifferentSet( vcl , [] ) 
#     self.failIfDifferentSet( cell_key_list , [] )
    self.failIfDifferentSet( cell_list , [] )
      
  def stepSetOrderLineResource(self, sequence=None, sequence_list=None, **kw):
    """
      Set order line resource with the current resource
    """
    order_line = sequence.get('order_line')
    resource = sequence.get('resource')
    order_line.setResourceValue(resource)

  def stepDeleteOrderLineResource(self, sequence=None, \
                                  sequence_list=None, **kw):
    """
      Set order line resource to None
    """
    order_line = sequence.get('order_line')
    order_line.setResource(None)

  def stepEmptyOrderLineMatrix(self,sequence=None, sequence_list=None, **kw):
    """
      Delete the current order line matrix
    """
    order_line = sequence.get('order_line')
290
    cell_list = order_line.objectValues(portal_type=self.cell_portal_type)
Romain Courteaud's avatar
Romain Courteaud committed
291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
    order_line.deleteContent( map(lambda x: x.getId(), cell_list) )

  def stepSetOrderLineEmptyVCL(self,sequence=None, sequence_list=None, **kw):
    """
      Delete the current order line's variation category list
    """
    order_line = sequence.get('order_line')
    resource = sequence.get('resource')
    order_line.setVariationCategoryList([])

  def splitList(self, list):
    """
      Split a list and return tuple with the 2 half
    """
    middle = len(list)/2 + len(list)%2
    return ( list[:middle] , list[middle:] )

  def stepSetOrderLineHalfVCL(self,sequence=None, sequence_list=None, **kw):
    """
      Delete the current order line variation category list
    """
    order_line = sequence.get('order_line')
    resource = sequence.get('resource')
    order_line_vcl = []
    resource_vbcl = resource.getVariationBaseCategoryList()
    for vbc in resource_vbcl:
317
      LOG('stepSetOrderLineHalfVCL', 0, 'vbc: %s' % str(vbc))
Romain Courteaud's avatar
Romain Courteaud committed
318 319 320
      resource_vcl = list(resource.getVariationCategoryList(
                                  base_category_list=[vbc],
                                  omit_individual_variation=0))
321 322
      LOG('stepSetOrderLineHalfVCL', 0,
                        'resource_vcl: %s' % str(resource_vcl))
Romain Courteaud's avatar
Romain Courteaud committed
323
      resource_vcl.sort()
324 325
      LOG('stepSetOrderLineHalfVCL', 0, 'split resource_vcl: %s' %
                           str(self.splitList(resource_vcl)[0]))
Romain Courteaud's avatar
Romain Courteaud committed
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345
      order_line_vcl.extend(self.splitList(resource_vcl)[0])
    order_line.setVariationCategoryList(order_line_vcl)

  def stepSetOrderLineFullVCL(self,sequence=None, sequence_list=None, **kw):
    """
      Complete the order line's variation category list
    """
    order_line = sequence.get('order_line')
    resource = sequence.get('resource')
    resource_vcl = list(resource.getVariationCategoryList(
                                   omit_individual_variation=0))
    resource_vcl.sort()
    order_line.setVariationCategoryList(resource_vcl)

  def stepCheckOrderLineRange(self,sequence=None, sequence_list=None, **kw):
    """
      Check order line matrix range
    """
    order_line = sequence.get('order_line')
    base_id = 'movement'
346
    vcl = order_line.getVariationCategoryList(omit_option_base_category=1)
Romain Courteaud's avatar
Romain Courteaud committed
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 372 373
    cell_range = order_line.OrderLine_asCellRange(matrixbox=0)

    l = len(vcl)
    s = sum(map(lambda x: len(x), cell_range))
    self.assertEquals(l,s)
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if cell_range == []:
      self.assertEquals(len(cell_key_list), 0)
    else:
      len_range = map(lambda x: len(x), cell_range)
      self.assertEquals(len(cell_key_list), reduce(lambda x,y: x*y, len_range))

  def stepCompleteOrderLineMatrix(self,sequence=None, sequence_list=None, \
                                  **kw):
    """
      Complete the current order line matrix.
    """
    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = list(order_line.getCellKeyList(base_id=base_id))
    cell_key_list.sort()
    price = 100
    quantity = 200
    for cell_key in cell_key_list:
      cell = order_line.newCell(base_id=base_id, \
                                portal_type=self.cell_portal_type, *cell_key)
      cell.edit(mapped_value_property_list=['price','quantity'],
Romain Courteaud's avatar
Romain Courteaud committed
374 375 376
                price=price, quantity=quantity,
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
Romain Courteaud's avatar
Romain Courteaud committed
377 378 379 380 381 382 383 384 385 386 387 388
      price += 1
      quantity += 1

  def stepCheckOrderLineCompleteMatrix(self, sequence=None, \
                                       sequence_list=None, **kw):
    """
      Check if the matrix of the current order line is complete.
    """
    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = list(order_line.getCellKeyList(base_id=base_id))
    cell_key_list.sort()
389
    cell_list = order_line.objectValues(portal_type=self.cell_portal_type)
Romain Courteaud's avatar
Romain Courteaud committed
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437
    self.assertEquals(len(cell_list), len(cell_key_list))
    price = 100
    quantity = 200
    for cell_key in cell_key_list:
      self.failUnless(order_line.hasCell(base_id=base_id, *cell_key))
      cell = order_line.getCell(base_id=base_id, *cell_key)
      self.assertEquals(self.cell_portal_type, cell.getPortalType())
      # XXX How can I check the cell content ?
#       self.assertEquals(price , cell.getProperty('price'))
#       self.assertEquals(quantity, cell.getProperty('quantity'))
#       self.failIfDifferentSet(cell.getMembershipCriterionCategoryList(),
#                               cell_key)
      price += 1
      quantity += 1

  def stepCheckOrderLineVRCL(self, sequence=None, sequence_list=None, **kw):
    """
      Check if getVariationRangeCategoryList returns the good result.
    """
    order_line = sequence.get('order_line')
    resource = order_line.getResourceValue()
    vrcl = order_line.getVariationRangeCategoryList()
    if resource == None:
      self.failIfDifferentSet([], list(vrcl))
    else:
      resource_vcl = resource.getVariationCategoryList(omit_individual_variation=0)
      self.failIfDifferentSet(resource_vcl, vrcl)

  def stepCheckOrderLineVRCIL(self, sequence=None, sequence_list=None, **kw):
    """
      Check if getVariationRangeCategoryItemList returns the good result.
      Does not test display...
      Item are left display.
    """
    order_line = sequence.get('order_line')
    vrcl = order_line.getVariationRangeCategoryList()
    vrcil = order_line.getVariationRangeCategoryItemList()
    self.failIfDifferentSet(vrcl, map(lambda x: x[1], vrcil))

  def stepCheckOrderLineVCIL(self, sequence=None, sequence_list=None, **kw):
    """
      Check if getVariationCategoryItemList returns the good result.
      Does not test display...
      Item are left display.
    """
    order_line = sequence.get('order_line')
    vcl = order_line.getVariationCategoryList()
    vcil = order_line.getVariationCategoryItemList()
438 439
    LOG('stepCheckOrderLineVCIL', 0, 'vcl: %s\n' % str(vcl))
    LOG('stepCheckOrderLineVCIL', 0, 'vcil: %s\n' % str(vcil))
Romain Courteaud's avatar
Romain Courteaud committed
440 441 442 443 444 445 446 447
    self.failIfDifferentSet(vcl, map(lambda x: x[1], vcil))

  def stepSetOrderLineDefaultValues(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Set the default price and quantity on the order line.
    """
    order_line = sequence.get('order_line')
Romain Courteaud's avatar
Romain Courteaud committed
448 449
    order_line.edit(quantity=self.default_quantity,
                    price=self.default_price)
Romain Courteaud's avatar
Romain Courteaud committed
450 451 452 453 454 455 456 457 458 459 460 461 462 463 464
      
  def stepCheckOrderLineDefaultValues(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check the default price and quantity on the order line.
    """
    order_line = sequence.get('order_line')
    self.assertEquals(self.default_quantity, order_line.getQuantity())
    self.assertEquals(self.default_price, order_line.getPrice())
      
  def stepCheckOrderLineTotalQuantity(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check the method getTotalQuantity on a order line.
    """
465 466 467 468 469
    
    # FIXME : order_line needs to be indexed for 'fast' calculation to
    # work as expected
    self.stepTic()
    
Romain Courteaud's avatar
Romain Courteaud committed
470 471 472 473 474 475 476 477 478
    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if list(cell_key_list) == []:
      self.assertEquals(order_line.getQuantity(), \
                        order_line.getTotalQuantity())
    else:
      total_quantity = 0
      for cell_key in cell_key_list:
479 480
        if order_line.hasCell(base_id = base_id, *cell_key):
          cell = order_line.getCell(base_id = base_id, *cell_key)
Romain Courteaud's avatar
Romain Courteaud committed
481 482
          total_quantity += cell.getProperty('quantity')
      self.assertEquals(total_quantity, order_line.getTotalQuantity())
483 484 485
    self.assertEquals( order_line.getTotalQuantity(fast = 0),
                       order_line.getTotalQuantity(fast = 1) )
                       
486 487
  def stepCheckOrderLineTotalPrice(self, sequence=None, \
                                    sequence_list=None, **kw):
Romain Courteaud's avatar
Romain Courteaud committed
488
    """
489
      Check the method getTotalPrice on a order line.
Romain Courteaud's avatar
Romain Courteaud committed
490
    """
491 492 493 494 495
    
    # FIXME : order_line needs to be indexed for 'fast' calculation to
    # work as expected
    self.stepTic()
    
496 497 498 499 500 501 502 503 504 505
    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if list(cell_key_list) == []:
      self.assertEquals(order_line.getProperty('price') *
                        order_line.getProperty('quantity'), 
                        order_line.getTotalPrice())
    else:
      total_price = 0
      for cell_key in cell_key_list:
506 507
        if order_line.hasCell(base_id = base_id, *cell_key):
          cell = order_line.getCell(base_id = base_id, *cell_key)
508 509 510
          total_price +=  ( cell.getProperty('quantity') *
                            cell.getProperty('price'))
      self.assertEquals(total_price, order_line.getTotalPrice())
511 512
    self.assertEquals( order_line.getTotalPrice(fast = 0),
                       order_line.getTotalPrice(fast = 1) )
513 514 515 516 517 518
      
  def stepCheckOrderTotalQuantity(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check the method getTotalQuantity on a order .
    """
519 520 521 522 523
    
    # FIXME : order needs to be indexed for 'fast' calculation to
    # work as expected
    self.stepTic()
    
524 525 526 527 528 529 530 531
    order = sequence.get('order')
    order_line_list = order.objectValues( \
                                 portal_type=self.order_line_portal_type)
    order_line_list = map(lambda x: x.getObject(), order_line_list)
    total_quantity = 0
    for order_line in order_line_list:
      total_quantity += order_line.getTotalQuantity()
    self.assertEquals(total_quantity, order.getTotalQuantity())
532 533
    self.assertEquals( order.getTotalQuantity(fast = 0),
                       order.getTotalQuantity(fast = 1) )
534 535 536 537 538 539
      
  def stepCheckOrderTotalPrice(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check the method getTotalPrice on a order .
    """
540 541 542 543 544
    
    # FIXME : order needs to be indexed for 'fast' calculation to
    # work as expected
    self.stepTic()
    
545 546 547 548 549 550 551 552
    order = sequence.get('order')
    order_line_list = order.objectValues( \
                                 portal_type=self.order_line_portal_type)
    order_line_list = map(lambda x: x.getObject(), order_line_list)
    total_price = 0
    for order_line in order_line_list:
      total_price += order_line.getTotalPrice()
    self.assertEquals(total_price, order.getTotalPrice())
553 554
    self.assertEquals( order.getTotalPrice(fast = 0),
                       order.getTotalPrice(fast = 1) )
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591
      
  def stepCheckOrderInitialState(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check if the first state of a order is draft.
    """
    order = sequence.get('order')
    self.assertEquals('draft', order.getSimulationState())
      
  def stepCheckOrderLineState(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check if the state of a order line is the same as parent order.
    """
    order = sequence.get('order')
    order_line = sequence.get('order_line')
    self.assertEquals(order.getSimulationState(), order_line.getSimulationState())
      
  def stepCheckOrderCellState(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check if the state of a order line is the same as parent order.
    """
    order = sequence.get('order')
    order_line = sequence.get('order_line')
    cell_list = order_line.objectValues(portal_type=self.cell_portal_type)
    for cell in cell_list:
      self.assertEquals(order.getSimulationState(), cell.getSimulationState())

  def stepCheckOrderPlanned(self, sequence=None, sequence_list=None, **kw):
    order = sequence.get('order')
    self.assertEquals('planned', order.getSimulationState())
      
  def checkAcquisition(self, object, acquired_object):
    """
      Check if properties are well acquired
    """
592
    # packing_list_movement, simulation_movement
593 594 595 596 597 598
    self.assertEquals(acquired_object.getStartDate(), object.getStartDate())
    self.assertEquals(acquired_object.getStopDate(), object.getStopDate())
    self.assertEquals(acquired_object.getSourceValue(), \
                      object.getSourceValue())
    self.assertEquals(acquired_object.getDestinationValue(), \
                      object.getDestinationValue())
599 600


601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628
    self.assertEquals(acquired_object.getSourceSectionValue(), \
                      object.getSourceSectionValue())
    self.assertEquals(acquired_object.getDestinationSectionValue(), \
                      object.getDestinationSectionValue())

  def stepCheckOrderLineAcquisition(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Test if order line acquired some order properties
    """
    order = sequence.get('order')
    order_line = sequence.get('order_line')
    self.checkAcquisition(order_line, order)

  def stepCheckOrderCellAcquisition(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Test if order cell acquired some order line properties
    """
    order_line = sequence.get('order_line')
    cell = order_line.getCellValueList()[0]
    self.checkAcquisition(cell, order_line)
    # Test resource
    self.assertEquals(order_line.getResource(), \
                      cell.getResource())
    # Test resource variation
    cvcl = cell.getVariationCategoryList()
    olvcl = order_line.getVariationCategoryList()
629 630 631
    # This test is not valide anymore, because of option variation
#     self.assertEquals(len(order_line.getVariationRangeBaseCategoryList()), \
#                       len(cvcl))
632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
    for variation_category in cvcl:
      self.failUnless(variation_category in olvcl)

  def stepCheckOrderSimulation(self, sequence=None, sequence_list=None, **kw):
    """
      Test if simulation is matching order
    """
    order = sequence.get('order')
    related_applied_rule_list = order.getCausalityRelatedValueList( \
                                   portal_type=self.applied_rule_portal_type)
    no_applied_rule_state = ('draft', 'auto_planned')
    order_state = order.getSimulationState()

    if order_state in no_applied_rule_state:
      self.assertEquals(0, len(related_applied_rule_list))
    else:
648 649
      LOG('stepCheckOrderSimulation', 0, 'related_applied_rule_list: %s' %
                   str([x.getObject() for x in related_applied_rule_list]))
650 651
      self.assertEquals(1, len(related_applied_rule_list))
      applied_rule = related_applied_rule_list[0].getObject()
Sebastien Robin's avatar
Sebastien Robin committed
652
      sequence.edit(applied_rule=applied_rule)
653 654 655 656 657 658 659 660 661 662
      self.failUnless(applied_rule is not None)
      self.failUnless(order_state, \
                      applied_rule.getLastExpandSimulationState())
      
      # Test if applied rule has a specialise value with default_order_rule
      portal_rules = getToolByName(order, 'portal_rules')
      self.assertEquals(portal_rules.default_order_rule, \
                        applied_rule.getSpecialiseValue())
      
      simulation_movement_list = applied_rule.objectValues()
Sebastien Robin's avatar
Sebastien Robin committed
663
      sequence.edit(simulation_movement_list=simulation_movement_list)
664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705

      # Count the number of movement in order
      order_line_list = order.objectValues( \
                                 portal_type=self.order_line_portal_type)
      order_line_list = map(lambda x: x.getObject(), order_line_list)
      movement_list = []
      for order_line in order_line_list:
        if not order_line.hasCellContent():
          movement_list.append(order_line)
        else:
          cell_list = order_line.objectValues( \
                                 portal_type=self.cell_portal_type)
          movement_list.extend(map(lambda x: x.getObject(), cell_list))
      # Check if number of movement is equal to number of simulation movement
      self.assertEquals(len(movement_list), len(simulation_movement_list))
      # Check if each movement has only one simulation movement related
      order_movement_list = map(lambda x: x.getOrderValue(), \
                                simulation_movement_list)
      self.failIfDifferentSet(movement_list, order_movement_list)

      # Check each simulation movement
      for simulation_movement in simulation_movement_list:
        order_movement = simulation_movement.getOrderValue()
        # Test quantity
        self.assertEquals(order_movement.getQuantity(), \
                          simulation_movement.getQuantity())
        # Test price
        self.assertEquals(order_movement.getPrice(), \
                          simulation_movement.getPrice())
        # Test resource
        self.assertEquals(order_movement.getResource(), \
                          simulation_movement.getResource())
        # Test resource variation
        self.assertEquals(order_movement.getVariationText(), \
                          simulation_movement.getVariationText())
        self.assertEquals(order_movement.getVariationCategoryList(), \
                          simulation_movement.getVariationCategoryList())
        # XXX Test acquisition
        self.checkAcquisition(simulation_movement, order_movement)
        # Test other attributes
        self.assertEquals(1, simulation_movement.deliverable)

706 707 708 709 710 711 712 713
  def modifyOrderState(self, transition_name, sequence=None, 
                       sequence_list=None):
    order = sequence.get('order')
    order.portal_workflow.doActionFor(order, transition_name, \
                                      wf_id=self.order_workflow_id)

  def stepPlanOrder(self, sequence=None, sequence_list=None, **kw):
    self.modifyOrderState('plan_action', sequence=sequence)
714 715

  def stepOrderOrder(self, sequence=None, sequence_list=None, **kw):
716
    self.modifyOrderState('order_action', sequence=sequence)
717 718

  def stepConfirmOrder(self, sequence=None, sequence_list=None, **kw):
719
    self.modifyOrderState('confirm_action', sequence=sequence)
720 721

  def stepCancelOrder(self, sequence=None, sequence_list=None, **kw):
722
    self.modifyOrderState('cancel_action', sequence=sequence)
723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765

  def stepCheckPortalMethod(self, sequence=None, sequence_list=None, **kw):
    """
      Test if some portal method are well defined
    """
    order = sequence.get('order')
    self.failUnless('Simulation Movement' in order.getPortalMovementTypeList())
    self.failUnless('Sale Order Line' in order.getPortalMovementTypeList())

  def stepCheckDeliveryBuilderPresence(self, sequence=None,
                                       sequence_list=None, **kw):
    """
      Test if delivery builder exists
    """
    delivery_builder = getattr(self.getPortal().portal_deliveries,
                               self.delivery_builder_id)
    self.assertEquals('Delivery Builder', delivery_builder.getPortalType())

  def stepCreateOrganisation1(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty organisation
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                **kw)
    organisation = sequence.get('organisation')
    sequence.edit(organisation1=organisation)

  def stepCreateOrganisation2(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty organisation
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                **kw)
    organisation = sequence.get('organisation')
    sequence.edit(organisation2=organisation)

  def stepSetOrderProfile(self,sequence=None, sequence_list=None, **kw):
    """
      Set different source and destination on the order
    """
    organisation1 = sequence.get('organisation1')
    organisation2 = sequence.get('organisation2')
    order = sequence.get('order')
766 767 768 769
    order.edit( source_value = organisation1,
                source_section_value = organisation1,
                destination_value = organisation2,
                destination_section_value = organisation2 )
770
    self.failUnless('Site Error' not in order.view())
771 772 773 774 775 776 777 778 779 780 781 782

  def stepCheckDeliveryBuilding(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is well created.
    """
    order = sequence.get('order')
    related_applied_rule_list = order.getCausalityRelatedValueList( \
                                   portal_type=self.applied_rule_portal_type)
    related_packing_list_list = order.getCausalityRelatedValueList( \
                                   portal_type=self.packing_list_portal_type)
    packing_list_building_state = 'confirmed'
    order_state = order.getSimulationState()
783
    if order_state != packing_list_building_state:
784 785 786 787 788 789
      self.assertEquals(0, len(related_packing_list_list))
    else:
      self.assertEquals(1, len(related_packing_list_list))

      packing_list = related_packing_list_list[0].getObject()
      self.failUnless(packing_list is not None)
790
      sequence.edit(packing_list = packing_list)
791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815
      
      applied_rule = related_applied_rule_list[0].getObject()
      simulation_movement_list = applied_rule.objectValues()

      # Test that packing list is confirmed
      packing_list_state = packing_list.getSimulationState()
      self.assertEquals(packing_list_building_state, packing_list_state)

      # First, test if each Simulation Movement is related to a Packing List
      # Movement
      packing_list_relative_url = packing_list.getRelativeUrl()
      for simulation_movement in simulation_movement_list:
        packing_list_movement_list = simulation_movement.getDeliveryValueList()
        self.failUnless(len(packing_list_movement_list), 1)
        packing_list_movement = packing_list_movement_list[0]
        self.failUnless(packing_list_movement is not None)
        self.failUnless(packing_list_movement.getRelativeUrl().\
                                      startswith(packing_list_relative_url))

      # Then, test if each packing list movement is equals to the sum of somes
      # Simulation Movement
      packing_list_movement_list = []
      for packing_list_line in packing_list.objectValues(
                               portal_type=self.packing_list_line_portal_type):
        packing_list_line = packing_list_line.getObject()
Sebastien Robin's avatar
Sebastien Robin committed
816
        sequence.edit(packing_list_line=packing_list_line)
817 818 819 820 821 822 823 824 825 826
        cell_list = [x.getObject() for x in packing_list_line.objectValues(
                               portal_type=self.packing_list_cell_portal_type)]
        if len(cell_list) == 0:
          packing_list_movement_list.append(packing_list_line)
        else:
          packing_list_movement_list.extend(cell_list)

      for packing_list_movement in packing_list_movement_list:
        related_simulation_movement_list = packing_list_movement.\
                 getDeliveryRelatedValueList(portal_type='Simulation Movement')
827
        self.failUnless(len(related_simulation_movement_list)>0)
828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890
        quantity = 0
        total_price = 0
        packing_list_movement_quantity = packing_list_movement.getQuantity()
        for related_simulation_movement in related_simulation_movement_list:
          quantity += related_simulation_movement.getQuantity()
          total_price += related_simulation_movement.getPrice() *\
                         related_simulation_movement.getQuantity()
          # Test resource
          self.assertEquals(packing_list_movement.getResource(), \
                            related_simulation_movement.getResource())
          # Test resource variation
          self.assertEquals(packing_list_movement.getVariationText(), \
                            related_simulation_movement.getVariationText())
          self.assertEquals(packing_list_movement.getVariationCategoryList(), \
                        related_simulation_movement.getVariationCategoryList())
          # Test acquisition
          self.checkAcquisition(packing_list_movement,
                                related_simulation_movement)
          # Test delivery ratio
          self.assertEquals(related_simulation_movement.getQuantity() /\
                            packing_list_movement_quantity, \
                            related_simulation_movement.getDeliveryRatio())


        self.assertEquals(quantity, packing_list_movement.getQuantity())
        # Test price
        self.assertEquals(total_price / quantity, packing_list_movement.getPrice())

      sequence.edit(packing_list=packing_list)

      # Finally, test Packing List getTotalQuantity and getTotalPrice
      self.assertEquals(order.getTotalQuantity(), packing_list.getTotalQuantity())
      self.assertEquals(order.getTotalPrice(), packing_list.getTotalPrice())

  def stepModifyOrderStartDate(self, sequence=None, sequence_list=None, \
                               **kw):
    """
      Modify order start date
    """
    order = sequence.get('order')
    order.setStartDate(self.datetime + 77)
      
  def stepModifyOrderLineStartDate(self, sequence=None, sequence_list=None, \
                                   **kw):
    """
      Modify order line start date
    """
    order_line = sequence.get('order_line')
    order_line.setStartDate(self.datetime + 88)
      
  def stepModifyOrderCellStartDate(self, sequence=None, sequence_list=None, \
                                   **kw):
    """
      Modify order cell start date
    """
    order_line = sequence.get('order_line')
    cell_list = order_line.objectValues(portal_type=self.cell_portal_type)
    if len(cell_list) > 0:
      order_cell = cell_list[0].getObject()
    order_cell.setStartDate(self.datetime + 99)
      


891
class TestOrder(TestOrderMixin, ERP5TypeTestCase):
892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 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 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148
  """
    Test business template erp5_trade 
  """
  run_all_test = 1


  def getTitle(self):
    return "Order"

  def enableLightInstall(self):
    """
    You can override this. 
    Return if we should do a light install (1) or not (0)
    """
    return 1

  def enableActivityTool(self):
    """
    You can override this.
    Return if we should create (1) or not (0) an activity tool.
    """
    return 1


#   def stepCheckOrderLineCell(self, sequence=None, sequence_list=None, **kw):
#     """
#       Check cell comportment when some properties are not defined.
#     """
#     order_line = sequence.get('order_line')
#     base_id = 'movement'
#     cell_key_list = order_line.getCellKeyList(base_id=base_id)
#     # First, search a cell to test
#     for cell_key in cell_key_list:
#       if order_line.hasCell(base_id=base_id, *cell_key):
#         cell = order_line.getCell(base_id=base_id, *cell_key)
#         break
#     # Then, store his properties
#     price = cell.getProperty('price')
#     quantity = cell.getProperty('quantity')
#     # Modify, test, and restore old values
#     for new_quantity, new_price in [(None, 346), (123, None), (None, None), \
#                                     (quantity, price)]:
#       cell.edit(quantity=new_quantity, price=new_price)
#       if new_quantity == None:
#         new_quantity = 0.0
#       if new_price == None:
#         new_price = 0.0
#       self.assertEquals(new_quantity, cell.getProperty('quantity'))
#       self.assertEquals(new_price, cell.getProperty('price'))
# 
#       # XXX test getTotalPrice on OrderLine

  def test_01_OrderLine_getVariationRangeCategoryList(self, quiet=0, 
                                                      run=run_all_test):
    """
      Test order line getVariationRangeCategoryList.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when resource has no variation
    sequence_string = 'CreateOrder \
                      CreateOrderLine \
                      CheckOrderLineVRCL \
                      CreateNotVariatedResource \
                      Tic \
                      SetOrderLineResource \
                      CheckOrderLineVRCL \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variation
    sequence_string = 'CreateOrder \
                      CreateOrderLine \
                      CheckOrderLineVRCL \
                      CreateVariatedResource \
                      Tic \
                      SetOrderLineResource \
                      CheckOrderLineVRCL \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_02_OrderLine_getVariationRangeCategoryItemList(self, quiet=0,
                                                          run=run_all_test):
    """
      Test order line getVariationRangeCategoryItemList.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when resource has no variation
    sequence_string = 'CreateOrder \
                      CreateOrderLine \
                      CheckOrderLineVRCIL \
                      CreateNotVariatedResource \
                      Tic \
                      SetOrderLineResource \
                      CheckOrderLineVRCIL \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variation
    sequence_string = 'CreateOrder \
                      CreateOrderLine \
                      CheckOrderLineVRCIL \
                      CreateVariatedResource \
                      Tic \
                      SetOrderLineResource \
                      CheckOrderLineVRCIL \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_03_OrderLine_getVariationCategoryList(self, quiet=0,
                                                 run=run_all_test):
    """
      Test order line getVariationCategoryList.
      Not yet tested....
    """
    if not run: return
    pass

  def test_04_OrderLine_getVariationCategoryItemList(self, quiet=0,
                                                     run=run_all_test):
    """
      Test order line getVariationCategoryItemList.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when resource has variation
    sequence_string = 'CreateOrder \
                      CreateOrderLine \
                      CheckOrderLineVCIL \
                      CreateVariatedResource \
                      Tic \
                      SetOrderLineResource \
                      SetOrderLineHalfVCL \
                      Tic \
                      CheckOrderLineVCIL \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_05_OrderLine_Matrix(self, quiet=0, run=run_all_test):
    """
      Test order line movement matrix.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when resource has no variation
    sequence_string = 'CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      CheckOrderLineEmptyMatrix \
                      SetOrderLineResource \
                      CheckOrderLineEmptyMatrix \
                      SetOrderLineFullVCL \
                      CheckOrderLineRange \
                      CheckOrderLineEmptyMatrix \
                      CompleteOrderLineMatrix \
                      Tic \
                      CheckOrderLineCompleteMatrix \
                      SetOrderLineHalfVCL \
                      Tic \
                      CheckOrderLineRange \
                      CheckOrderLineCompleteMatrix \
                      SetOrderLineEmptyVCL \
                      Tic \
                      CheckOrderLineEmptyMatrix \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = 'CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      CheckOrderLineEmptyMatrix \
                      SetOrderLineResource \
                      CheckOrderLineEmptyMatrix \
                      SetOrderLineFullVCL \
                      CheckOrderLineRange \
                      CheckOrderLineEmptyMatrix \
                      CompleteOrderLineMatrix \
                      Tic \
                      CheckOrderLineCompleteMatrix \
                      SetOrderLineHalfVCL \
                      Tic \
                      CheckOrderLineRange \
                      CheckOrderLineCompleteMatrix \
                      SetOrderLineEmptyVCL \
                      Tic \
                      CheckOrderLineRange \
                      CheckOrderLineEmptyMatrix \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

#   def modifyOrderLineCellPrice(self, price):
#     """
#       Modify the properties of the first cell founded on the current
#       order line.
#     """
#     order_line = sequence.get('order_line')
#     base_id = 'movement'
#     cell_key_list = order_line.getCellKeyList(base_id=base_id)
#     # First, search a cell to test
#     cell = None
#     for cell_key in cell_key_list:
#       if order_line.hasCell(base_id=base_id, *cell_key):
#         cell = order_line.getCell(base_id=base_id, *cell_key)
#         break
#     if cell is not None:
#       # Then, store new properties
#       cell.edit(price=price)
#       self.assertEquals(price, cell.getProperty('price'))
# 
# #     for new_quantity, new_price in [(None, 346), (123, None), (None, None), \
# #                                     (quantity, price)]:
#   def stepSetCellPriceToNone(self, sequence=None, sequence_list=None, **kw):
#     """
#       Set the cell price to None
#     """
#       self.modifyOrderLineCellPrice(None)
# 
#   def stepSetCellQuantityToNone(self, sequence=None, sequence_list=None, **kw):
#     """
#       Set the cell price to None
#     """
#       self.modifyOrderLineCellQuantity(None)

  def test_06_OrderLine_getTotalQuantity(self, quiet=0, run=run_all_test):
    """
      Test the method getTotalQuantity on a order line.
    """
    if not run: return
    sequence_list = SequenceList()

    # Test when resource has no variation
    sequence_string = '\
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CheckOrderLineDefaultValues \
                      CheckOrderLineTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CheckOrderLineDefaultValues \
                      CheckOrderLineTotalQuantity \
Romain Courteaud's avatar
Romain Courteaud committed
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 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 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderLineTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # XXX test cell modification

    sequence_list.play(self)

  def test_07_OrderLine_getTotalPrice(self, quiet=0, run=run_all_test):
    """
      Test method getTotalPrice on order line.
    """
    if not run: return
    sequence_list = SequenceList()

    # Test when resource has not variation
    sequence_string = '\
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      CheckOrderLineEmptyMatrix \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CheckOrderLineDefaultValues \
                      CheckOrderLineTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CheckOrderLineDefaultValues \
                      CheckOrderLineTotalQuantity \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderLineTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # XXX test cell modification

    sequence_list.play(self)

  def test_08_Order_testTotalQuantity(self, quiet=0, run=run_all_test):
    """
      Test method getTotalQuantity on a order
    """
    if not run: return
    sequence_list = SequenceList()
    # Test with no order line
    sequence_string = '\
                      CreateOrder \
                      CheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has not variation
    sequence_string = '\
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
Sebastien Robin's avatar
Sebastien Robin committed
1217
                      Tic \
Romain Courteaud's avatar
Romain Courteaud committed
1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275
                      CheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test whith multiples order line
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderTotalQuantity \
                      CreateNotVariatedResource \
                      CreateOrderLine \
                      Tic \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      Tic \
                      CheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_09_Order_testTotalPrice(self, quiet=0, run=run_all_test):
    """
      Test method getTotalPrice on a order
    """
    if not run: return
    sequence_list = SequenceList()
    # Test with no order line
    sequence_string = '\
                      CreateOrder \
                      CheckOrderTotalPrice\
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has not variation
    sequence_string = '\
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
Sebastien Robin's avatar
Sebastien Robin committed
1276
                      Tic \
Romain Courteaud's avatar
Romain Courteaud committed
1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307
                      CheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test with multiples order line
    sequence_string = '\
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
Sebastien Robin's avatar
Sebastien Robin committed
1308
                      Tic \
Romain Courteaud's avatar
Romain Courteaud committed
1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320
                      CheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_10_Order_testSimulationState(self, quiet=0, run=run_all_test):
    """
      Test simulation state acquisition on Order
    """
    if not run: return
    sequence_list = SequenceList()
    sequence_string = '\
1321
                      CreateOrganisation \
Romain Courteaud's avatar
Romain Courteaud committed
1322 1323 1324 1325 1326
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CheckOrderInitialState \
                      CreateOrderLine \
1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342
                      Tic \
                      CheckOrderLineState \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      Tic \
                      CheckOrderCellState \
                      PlanOrder \
                      Tic \
                      CheckOrderPlanned \
                      CheckOrderLineState \
                      CheckOrderCellState \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)
Romain Courteaud's avatar
Romain Courteaud committed
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419

  def test_11_testPropertiesAcquisition(self, quiet=0, run=run_all_test):
    """
      Test if some properties on order line or order 
      cell are well acquired.
    """
    if not run: return
    sequence_list = SequenceList()
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CheckOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      CheckOrderLineAcquisition \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CheckOrderCellAcquisition \
                      Tic \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_12_testAppliedRuleGeneration(self, quiet=0, run=run_all_test):
    """
      Test generation and update of order applied rule.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test first some portal method
    sequence_string = '\
                      CreateOrder \
                      CheckPortalMethod \
                      '
    sequence_list.addSequenceString(sequence_string)
    
    # Test when order is cancelled
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CheckOrderSimulation \
                      PlanOrder \
                      Tic \
                      CheckOrderSimulation \
                      OrderOrder \
                      Tic \
                      CheckOrderSimulation \
                      CancelOrder \
                      Tic \
                      Tic \
                      CheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a simply order without cell
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      PlanOrder \
                      Tic \
                      CheckOrderSimulation \
                      OrderOrder \
                      Tic \
                      CheckOrderSimulation \
1420 1421 1422
                      ConfirmOrder \
                      Tic \
                      CheckOrderSimulation \
Romain Courteaud's avatar
Romain Courteaud committed
1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order without planned or ordered it
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      OrderOrder \
                      Tic \
                      CheckOrderSimulation \
1438 1439 1440
                      ConfirmOrder \
                      Tic \
                      CheckOrderSimulation \
Romain Courteaud's avatar
Romain Courteaud committed
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with variated resource
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckOrderSimulation \
1459 1460 1461
                      ConfirmOrder \
                      Tic \
                      CheckOrderSimulation \
Romain Courteaud's avatar
Romain Courteaud committed
1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with multiples lines
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckOrderSimulation \
1485 1486 1487
                      ConfirmOrder \
                      Tic \
                      CheckOrderSimulation \
Romain Courteaud's avatar
Romain Courteaud committed
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

  def test_13_testAppliedRuleUpdate(self, quiet=0, run=run_all_test):
    """
      Test update of applied rule when order is modified.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is modified
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      OrderOrder \
                      Tic \
                      ModifyOrderStartDate \
                      CheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when order line is modified
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      OrderOrder \
                      Tic \
                      ModifyOrderLineStartDate \
                      CheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when order cell is modified
    sequence_string = '\
                      CreateOrganisation \
                      CreateOrder \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      OrderOrder \
                      Tic \
                      ModifyOrderCellStartDate \
                      CheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

1553 1554 1555 1556 1557 1558 1559 1560 1561
# XXX
#   def test_14_readOnlyConfirmedOrder(self, quiet=0, run=run_all_test):
#     """
#       Test if confirmed order can not be modificated anymore.
#     """
#     if not run: return
#     self.failUnless(1==2)

  def test_15_deliveryBuilder(self, quiet=0, run=run_all_test):
Romain Courteaud's avatar
Romain Courteaud committed
1562 1563 1564 1565
    """
      Test generation of delivery list
    """
    if not run: return
1566
    sequence_list = SequenceList()
1567 1568 1569 1570 1571 1572
    # First, test if delivery buider exists
    sequence_string = '\
                      CheckDeliveryBuilderPresence \
                      '
    sequence_list.addSequenceString(sequence_string)

1573 1574
    # Test with a simply order without cell
    sequence_string = '\
1575 1576
                      CreateOrganisation1 \
                      CreateOrganisation2 \
1577
                      CreateOrder \
1578
                      SetOrderProfile \
1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      OrderOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with variated resource
    sequence_string = '\
1595 1596
                      CreateOrganisation1 \
                      CreateOrganisation2 \
1597
                      CreateOrder \
1598
                      SetOrderProfile \
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with multiples lines
    sequence_string = '\
1618 1619
                      CreateOrganisation1 \
                      CreateOrganisation2 \
1620
                      CreateOrder \
1621
                      SetOrderProfile \
1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

Romain Courteaud's avatar
Romain Courteaud committed
1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694
    # Test with a order with 2 lines and the same not variated resource
    sequence_string = '\
                      CreateOrganisation1 \
                      CreateOrganisation2 \
                      CreateOrder \
                      SetOrderProfile \
                      CreateNotVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      OrderOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a order with 2 lines and the same variated resource
    sequence_string = '\
                      CreateOrganisation1 \
                      CreateOrganisation2 \
                      CreateOrder \
                      SetOrderProfile \
                      CreateVariatedResource \
                      Tic \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

1695 1696
    sequence_list.play(self)

1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729
  def test_16_deliveryBuilderWithNoTic(self, quiet=0, run=run_all_test):
    """
      Test generation of delivery list with
      only a few tic
    """
    if not run: return
    sequence_list = SequenceList()

    # XXX Does not work yet
    # Test to confirm order without doing any tic
    # Except after creating organisations
     
    sequence_string = '\
                      CreateOrganisation1 \
                      CreateOrganisation2 \
                      Tic \
                      CreateOrder \
                      SetOrderProfile \
                      CreateVariatedResource \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      SetOrderLineFullVCL \
                      CompleteOrderLineMatrix \
                      CreateNotVariatedResource \
                      CreateOrderLine \
                      SetOrderLineResource \
                      SetOrderLineDefaultValues \
                      OrderOrder \
                      CheckDeliveryBuilding \
                      ConfirmOrder \
                      Tic \
                      Tic \
1730
                      Commit \
1731 1732 1733 1734 1735 1736
                      CheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

1737 1738 1739 1740 1741 1742
#   def test_16_packingListOrderAcquisition(self, quiet=0, run=run_all_test):
#     """
#       Test if packing list get some properties from order.
#     """
#     if not run: return
#     self.failUnless(1==2)
Romain Courteaud's avatar
Romain Courteaud committed
1743 1744 1745 1746 1747 1748 1749 1750 1751 1752

if __name__ == '__main__':
    framework()
else:
    import unittest
    def test_suite():
        suite = unittest.TestSuite()
        suite.addTest(unittest.makeSuite(TestOrder))
        return suite