testOrder.py 120 KB
Newer Older
Aurel's avatar
Aurel 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
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (c) 2004-2008 Nexedi SA 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 responsibility 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
# guarantees 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 unittest
import os

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
35 36
from Products.ERP5Type.tests.utils import FileUpload,\
    SubcontentReindexingWrapper
Aurel's avatar
Aurel committed
37 38 39 40 41 42
from AccessControl.SecurityManagement import newSecurityManager
from DateTime import DateTime
from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.CMFCore.utils import getToolByName

43
class TestOrderMixin(SubcontentReindexingWrapper):
Aurel's avatar
Aurel committed
44 45 46 47 48 49 50 51 52

  default_quantity = 99
  default_price = 555
  default_negative_price = -5550
  resource_portal_type = 'Apparel Model'
  order_portal_type = 'Sale Order'
  order_line_portal_type = 'Sale Order Line'
  order_cell_portal_type = 'Sale Order Cell'
  applied_rule_portal_type = 'Applied Rule'
53
  simulation_movement_portal_type = 'Simulation Movement'
54 55
  # see comment about self.datetime on afterSetUp() below
  datetime = DateTime() - 2
Aurel's avatar
Aurel committed
56 57 58 59 60
  packing_list_portal_type = 'Sale Packing List'
  packing_list_line_portal_type = 'Sale Packing List Line'
  packing_list_cell_portal_type = 'Sale Packing List Cell'
  delivery_builder_id = 'sale_packing_list_builder'
  size_list = ['Baby','Child/32','Child/34','Man','Woman']
61
  business_process = 'business_process_module/erp5_default_business_process'
Aurel's avatar
Aurel committed
62 63 64 65

  def getBusinessTemplateList(self):
    """
    """
66 67 68 69 70
    return ('erp5_core_proxy_field_legacy', 'erp5_base','erp5_pdm',
            'erp5_simulation', 'erp5_trade', 'erp5_apparel', 'erp5_project',
            'erp5_configurator_standard_solver',
            'erp5_configurator_standard_trade_template',
            'erp5_simulation_test', 'erp5_administration')
Aurel's avatar
Aurel committed
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97

  def login(self, quiet=0, run=1):
    uf = self.getPortal().acl_users
    uf._doAddUser('rc', '', ['Manager', 'Member', 'Assignee'], [])
    user = uf.getUserById('rc').__of__(uf)
    newSecurityManager(None, user)

  def setUpPreferences(self):
    #create apparel variation preferences
    portal_preferences = self.getPreferenceTool()
    preference = getattr(portal_preferences, 'test_site_preference', None)
    if preference is None:
      preference = portal_preferences.newContent(portal_type='System Preference',
                                title='Default Site Preference',
                                id='test_site_preference')
      if preference.getPreferenceState() == 'disabled':
        preference.enable()

    preference.setPreferredApparelModelVariationBaseCategoryList(('size', 'industrial_phase',))
    preference.setPreferredApparelClothVariationBaseCategoryList(('size',))
    preference.setPreferredApparelComponentVariationBaseCategoryList(('variation',))
    preference.setPreferredApparelModelIndividualVariationBaseCategoryList(('colour', 'morphology'))

    if preference.getPreferenceState() == 'disabled':
      preference.enable()
    self.tic()

98 99 100 101 102 103
  def afterSetUp(self):
    # XXX-Leo: cannot call super here, because other classes call
    # SuperClass.afterSetUp(self) directly... this needs to be cleaned
    # up, including consolidating all conflicting definitions of
    # .createCategories()
    #super(TestOrderMixin, self).afterSetUp()
Aurel's avatar
Aurel committed
104 105 106 107 108 109 110
    self.login()
    self.category_tool = self.getCategoryTool()
    portal_catalog = self.getCatalogTool()
    #portal_catalog.manage_catalogClear()
    self.createCategories()
    self.validateRules()
    self.setUpPreferences()
111 112 113 114 115 116 117 118 119
    # pin datetime on the day before yesterday, to make sure that:
    #
    # 1. All calculations are done relative to the same time
    # 2. We don't get random failures when tests run close to midnight
    self.pinDateTime(self.datetime)

  def beforeTearDown(self):
    self.unpinDateTime()
    super(TestOrderMixin, self).beforeTearDown()
Aurel's avatar
Aurel committed
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 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 222 223 224 225 226 227 228 229 230 231 232 233

  def createCurrency(self):
    currency_module = self.getPortal().currency_module
    if currency_module._getOb('euro', None) is None:
      currency_module.newContent(id='euro', reference='EUR', title='EURO')

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

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

    industrial_phase_category_list = ['phase1', 'phase2',
                                      'supply_phase1', 'supply_phase2']
    if len(category_tool.industrial_phase.contentValues()) == 0:
      for category_id in industrial_phase_category_list:
        o = category_tool.industrial_phase.newContent(
                                                 portal_type='Category',
                                                 id=category_id)

    product_line_category_list = ['apparel', 'cancel']
    if len(category_tool.product_line.contentValues()) == 0:
      for category_id in product_line_category_list:
        o = category_tool.product_line.newContent(
                                                 portal_type='Category',
                                                 id=category_id)

  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(
      title = "NotVariatedResource%s" % resource.getId(),
      industrial_phase_list=["phase1", "phase2"],
      product_line = 'apparel'
    )

    sequence.edit( resource = resource )
    resource_list = sequence.get('resource_list',default=[])
    resource_list.append(resource)
    sequence.edit( resource_list = resource_list )

  def stepCreateNotVariatedResourceForNegativePriceOrderLine(self, sequence=None, sequence_list=None, **kw):
    """
      Create a resource with no variation for negative price order line.
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(portal_type=self.resource_portal_type)
    resource.edit(
      title = "NotVariatedResourceForNegativePriceOrderLine%s" % resource.getId(),
      product_line = 'cancel'
    )

    sequence.edit( resource = resource )
    resource_list = sequence.get('resource_list',default=[])
    resource_list.append(resource)
    sequence.edit( resource_list = resource_list )

  def stepCreateVariatedResource(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
      Create a resource with variation
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(portal_type=self.resource_portal_type)
    resource.edit(
      title = "VariatedResource%s" % resource.getId(),
      industrial_phase_list=["phase1", "phase2"],
      product_line = 'apparel'
    )
    resource.setSizeList(self.size_list)
    # 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 )
    resource_list = sequence.get('resource_list',default=[])
    resource_list.append(resource)
    sequence.edit( resource_list = resource_list )

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 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
  def stepCreateVariatedMultipleQuantityUnitResource(self, sequence=None, sequence_list=None, **kw):
    """
    Create a resource with variation and multiple quantity units
    """
    # Extend quantity_unit category if needed
    quantity_unit = self.portal.portal_categories.quantity_unit
    if not 'unit' in quantity_unit.objectIds():
      quantity_unit.newContent(id='unit')
    if not 'drum' in quantity_unit.unit.objectIds():
      quantity_unit.unit.newContent(id='drum', quantity=1)
    if not 'mass' in quantity_unit.objectIds():
      quantity_unit.newContent(id='mass')
    if not 'kilogram' in quantity_unit.mass.objectIds():
      quantity_unit.mass.newContent(id='kilogram', quantity=1)
    # Extend metric_type category if needed
    metric_type = self.portal.portal_categories.metric_type
    if not 'unit' in metric_type.objectIds():
      metric_type.newContent(id='unit')
    if not 'mass' in metric_type.objectIds():
      metric_type.newContent(id='mass')

    # Create resource
    self.stepCreateVariatedResource(sequence, sequence_list, **kw)
    resource = sequence.get('resource')

    # Extend resource portal type
    resource_portal_type = getattr(self.portal.portal_types, resource.portal_type)
    type_allowed_content_type_list = resource_portal_type.getTypeAllowedContentTypeList()
    if not 'Measure' in type_allowed_content_type_list:
      type_allowed_content_type_list.append('Measure')
      resource_portal_type.setTypeAllowedContentTypeList(type_allowed_content_type_list)

    # Set quantity units to product
    resource.setQuantityUnitValueList([quantity_unit.mass.kilogram,
                                       quantity_unit.unit.drum])
    # Set measures to products
    resource.newContent(portal_type='Measure',
                        metric_type_value=metric_type.mass,
                        default_metric_type=True,
                        quantity_unit_value=quantity_unit.mass.kilogram,
                        quantity=1)
    resource.newContent(portal_type='Measure',
                        metric_type_value=metric_type.unit,
                        quantity_unit_value=quantity_unit.unit.drum,
                        quantity=0.01)

Aurel's avatar
Aurel committed
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331
  def stepCreateOrganisation(self, sequence=None, sequence_list=None,
                             title=None, **kw):
    """
      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)
    bank_account = organisation.newContent(id='bank',
                                           portal_type='Bank Account',
                                           title='bank%s' % organisation.getId())
    if title is None:
      organisation.edit(title='organisation%s' % organisation.getId())
      sequence.edit(organisation=organisation)
    else:
      organisation.edit(title=title)
      sequence.edit(**{title:organisation})

  def stepCreateProject(self, sequence=None, sequence_list=None,
                        title=None, **kw):
    """
      Create a project
    """
    project = sequence.get('project')
    project_portal_type = 'Project'
    portal = self.getPortal()
    project_module = portal.getDefaultModule( \
                                   portal_type=project_portal_type)
    project = project_module.newContent( \
                                   portal_type=project_portal_type)
    if title is None:
      project.edit(title='project%s' % project.getId())
      sequence.edit(project=project)
    else:
      project.edit(title=title)
      sequence.edit(**{title:project})

  def stepCreateOrder(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty order
    """
    organisation = sequence.get('organisation')
    project = sequence.get('project')
#     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(
Jérome Perrin's avatar
Jérome Perrin committed
332
      title = "Order%s (%s)" % (order.getId(), self.id()),
Aurel's avatar
Aurel committed
333 334
      start_date = self.datetime + 10,
      stop_date = self.datetime + 20,
335
      specialise = self.business_process,
Aurel's avatar
Aurel committed
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355
    )
    if organisation is not None:
      order.edit(source_value=organisation,
                 source_section_value=organisation,
                 destination_value=organisation,
                 destination_section_value=organisation,
                 # Added for test Packing List Copy
                 source_decision_value=organisation,
                 destination_decision_value=organisation,
                 source_administration_value=organisation,
                 destination_administration_value=organisation,
                 )
    if project is not None:
      order.edit(source_project_value=project,
                 destination_project_value=project,
                 )
    sequence.edit( order = order )

  def stepCheckOrder(self, sequence=None, sequence_list=None, **kw):
    """
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
      Check if order was well created, either by stepCreateOrder of
      stepSetOrderProfile
    """
    source_organisation = sequence.get('organisation1')
    if source_organisation is None:
      source_organisation = sequence.get('organisation')
    destination_organisation = sequence.get('organisation2')
    if destination_organisation is None:
      destination_organisation = sequence.get('organisation')
    source_project = sequence.get('project1')
    if source_project is None:
      source_project = sequence.get('project')
    destination_project = sequence.get('project2')
    if destination_project is None:
      destination_project = sequence.get('project')
Aurel's avatar
Aurel committed
371
    order = sequence.get('order')
372 373 374 375 376 377 378 379
    self.assertEqual(self.datetime+10, order.getStartDate())
    self.assertEqual(self.datetime+20, order.getStopDate())
    self.assertEqual(source_organisation, order.getSourceValue())
    self.assertEqual(destination_organisation, order.getDestinationValue())
    self.assertEqual(source_organisation, order.getSourceSectionValue())
    self.assertEqual(destination_organisation, order.getDestinationSectionValue())
    self.assertEqual(source_project, order.getSourceProjectValue())
    self.assertEqual(destination_project, order.getDestinationProjectValue())
Aurel's avatar
Aurel committed
380 381 382 383 384 385 386 387 388 389 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 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488


  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)
    cell_list = order_line.objectValues(portal_type=self.order_cell_portal_type)
#     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')
    cell_list = order_line.objectValues(portal_type=self.order_cell_portal_type)
    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:
      LOG('stepSetOrderLineHalfVCL', 0, 'vbc: %s' % str(vbc))
      resource_vcl = list(resource.getVariationCategoryList(
                                  base_category_list=[vbc],
                                  omit_individual_variation=0))
      LOG('stepSetOrderLineHalfVCL', 0,
                        'resource_vcl: %s' % str(resource_vcl))
      resource_vcl.sort()
      LOG('stepSetOrderLineHalfVCL', 0, 'split resource_vcl: %s' %
                           str(self.splitList(resource_vcl)[0]))
      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'
    vcl = order_line.getVariationCategoryList(omit_optional_variation=1)
    cell_range = order_line.OrderLine_asCellRange(matrixbox=0)

    l = len(vcl)
    s = sum(map(lambda x: len(x), cell_range))
489
    self.assertEqual(l,s)
Aurel's avatar
Aurel committed
490 491
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if cell_range == []:
492
      self.assertEqual(len(cell_key_list), 0)
Aurel's avatar
Aurel committed
493 494
    else:
      len_range = map(lambda x: len(x), cell_range)
495
      self.assertEqual(len(cell_key_list), reduce(lambda x,y: x*y, len_range))
Aurel's avatar
Aurel committed
496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527

  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.order_cell_portal_type, *cell_key)
      cell.edit(mapped_value_property_list=['price','quantity'],
                price=price, quantity=quantity,
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
      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()
    cell_list = order_line.objectValues(portal_type=self.order_cell_portal_type)
528
    self.assertEqual(len(cell_list), len(cell_key_list))
Aurel's avatar
Aurel committed
529 530 531
    price = 100
    quantity = 200
    for cell_key in cell_key_list:
532
      self.assertTrue(order_line.hasCell(base_id=base_id, *cell_key))
Aurel's avatar
Aurel committed
533
      cell = order_line.getCell(base_id=base_id, *cell_key)
534
      self.assertEqual(self.order_cell_portal_type, cell.getPortalType())
Aurel's avatar
Aurel committed
535
      # XXX How can I check the cell content ?
536 537
#       self.assertEqual(price , cell.getProperty('price'))
#       self.assertEqual(quantity, cell.getProperty('quantity'))
Aurel's avatar
Aurel committed
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603
#       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()
    LOG('stepCheckOrderLineVCIL', 0, 'vcl: %s\n' % str(vcl))
    LOG('stepCheckOrderLineVCIL', 0, 'vcil: %s\n' % str(vcil))
    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')
    order_line.edit(quantity=self.default_quantity,
                    price=self.default_price)

  def stepSetOrderLineDefaultNegativePriceValue(self, sequence=None, \
                                           sequence_list=None, **kw):
    """
      Set the default negative price and 1 to quantity on the order line.
    """
    order_line = sequence.get('order_line')
    order_line.edit(quantity=1,
                    price=self.default_negative_price)

  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')
604 605
    self.assertEqual(self.default_quantity, order_line.getQuantity())
    self.assertEqual(self.default_price, order_line.getPrice())
Aurel's avatar
Aurel committed
606 607 608 609 610 611 612 613

  def stepCheckOrderLineTotalQuantity(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check the method getTotalQuantity on a order line.
    """

    # order_line needs to be indexed for 'fast' calculation to work as expected
614
    self.tic()
Aurel's avatar
Aurel committed
615 616 617 618 619

    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if list(cell_key_list) == []:
620
      self.assertEqual(order_line.getQuantity(), \
Aurel's avatar
Aurel committed
621 622 623 624 625 626 627
                        order_line.getTotalQuantity())
    else:
      total_quantity = 0
      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)
          total_quantity += cell.getProperty('quantity')
628 629
      self.assertEqual(total_quantity, order_line.getTotalQuantity())
    self.assertEqual( order_line.getTotalQuantity(fast = 0),
Aurel's avatar
Aurel committed
630 631 632 633 634 635 636 637 638 639
                       order_line.getTotalQuantity(fast = 1) )
    self.assertNotEquals(order_line.getTotalQuantity(fast = 1),0)

  def stepCheckOrderLineTotalPrice(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check the method getTotalPrice on a order line.
    """

    # order_line needs to be indexed for 'fast' calculation to work as expected
640
    self.tic()
Aurel's avatar
Aurel committed
641 642 643 644 645

    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    if list(cell_key_list) == []:
646
      self.assertEqual(order_line.getProperty('price') *
Aurel's avatar
Aurel committed
647 648 649 650 651 652 653 654 655
                        order_line.getProperty('quantity'),
                        order_line.getTotalPrice())
    else:
      total_price = 0
      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)
          total_price +=  ( cell.getProperty('quantity') *
                            cell.getProperty('price'))
656 657
      self.assertEqual(total_price, order_line.getTotalPrice())
    self.assertEqual( order_line.getTotalPrice(fast = 0),
Aurel's avatar
Aurel committed
658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679
                       order_line.getTotalPrice(fast = 1) )
    self.assertNotEquals(order_line.getTotalPrice(fast = 1),0)

  def stepCheckOrderLineTotalPriceAndQuantityFastParameter(self, sequence=None, \
                                    sequence_list=None, **kw):
    """
      Check the method getTotalPrice on a order line.

      Here we will check that very carefully ther parameter fast
    """
    portal_catalog = self.getCatalogTool()
    total_price = 0
    total_quantity = 0
    order_line = sequence.get('order_line')
    base_id = 'movement'
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    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)
        total_price +=  ( cell.getProperty('quantity') *
                          cell.getProperty('price'))
        total_quantity += (cell.getProperty('quantity'))
680
    self.assertEqual(len(portal_catalog(
Aurel's avatar
Aurel committed
681
                          relative_url=order_line.getRelativeUrl())),0)
682 683 684 685
    self.assertEqual(total_price, order_line.getTotalPrice(fast=0))
    self.assertEqual(total_quantity, order_line.getTotalQuantity(fast=0))
    self.assertEqual(0, order_line.getTotalPrice(fast=1))
    self.assertEqual(0, order_line.getTotalQuantity(fast=1))
Aurel's avatar
Aurel committed
686
    self.assertNotEquals(total_price, 0)
687
    self.tic()
688
    self.assertEqual(len(portal_catalog(relative_url=
Aurel's avatar
Aurel committed
689
                                         order_line.getRelativeUrl())),1)
690 691 692 693
    self.assertEqual(total_price, order_line.getTotalPrice(fast=1))
    self.assertEqual(total_price, order_line.getTotalPrice(fast=0))
    self.assertEqual(total_quantity, order_line.getTotalQuantity(fast=1))
    self.assertEqual(total_quantity, order_line.getTotalQuantity(fast=0))
Aurel's avatar
Aurel committed
694 695 696 697 698 699 700 701

  def stepCheckOrderTotalQuantity(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check the method getTotalQuantity on a order .
    """

    # order needs to be indexed for 'fast' calculation to work as expected
702
    self.tic()
Aurel's avatar
Aurel committed
703 704 705 706 707 708 709 710

    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()
711 712
    self.assertEqual(total_quantity, order.getTotalQuantity())
    self.assertEqual( order.getTotalQuantity(fast = 0),
Aurel's avatar
Aurel committed
713 714 715 716 717 718 719 720 721
                       order.getTotalQuantity(fast = 1) )

  def stepCheckOrderTotalPrice(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check the method getTotalPrice on a order .
    """

    # order needs to be indexed for 'fast' calculation to work as expected
722
    self.tic()
Aurel's avatar
Aurel committed
723 724 725 726 727 728 729 730

    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()
731 732
    self.assertEqual(total_price, order.getTotalPrice())
    self.assertEqual( order.getTotalPrice(fast = 0),
Aurel's avatar
Aurel committed
733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749
                       order.getTotalPrice(fast = 1) )

  def stepCheckOrderTotalPriceAndQuantityFastParameter(self,
                                  sequence=None, sequence_list=None, **kw):
    """
      Check the method getTotalPrice on a order .

      Here we will look carefully at the parameter fast
    """
    portal_catalog = self.getCatalogTool()

    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:
750
      total_price += order_line.getTotalPrice()
751 752
    self.assertEqual(0, len(portal_catalog(relative_url=order.getRelativeUrl())))
    self.assertEqual(total_price, order.getTotalPrice(fast=0))
Aurel's avatar
Aurel committed
753
    self.assertNotEquals(total_price, 0)
754
    self.assertEqual(0, order.getTotalPrice(fast=1))
755
    self.tic()
756 757 758
    self.assertEqual(1, len(portal_catalog(relative_url=order.getRelativeUrl())))
    self.assertEqual(total_price, order.getTotalPrice(fast=1))
    self.assertEqual(total_price, order.getTotalPrice(fast=0))
Aurel's avatar
Aurel committed
759 760 761 762 763 764 765

  def stepCheckOrderInitialState(self, sequence=None, sequence_list=None, \
                                  **kw):
    """
      Check if the first state of a order is draft.
    """
    order = sequence.get('order')
766
    self.assertEqual('draft', order.getSimulationState())
Aurel's avatar
Aurel committed
767 768 769 770 771 772 773 774

  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')
775
    self.assertEqual(order.getSimulationState(), order_line.getSimulationState())
Aurel's avatar
Aurel committed
776 777 778 779 780 781 782 783 784 785

  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.order_cell_portal_type)
    for cell in cell_list:
786
      self.assertEqual(order.getSimulationState(), cell.getSimulationState())
Aurel's avatar
Aurel committed
787 788 789

  def stepCheckOrderPlanned(self, sequence=None, sequence_list=None, **kw):
    order = sequence.get('order')
790
    self.assertEqual('planned', order.getSimulationState())
Aurel's avatar
Aurel committed
791 792 793 794 795 796 797

  def checkAcquisition(self, object, acquired_object):
    """
      Check if properties are well acquired
    """
    # packing_list_movement, simulation_movement

798 799 800
    self.assertEqual(acquired_object.getStartDate(), object.getStartDate())
    self.assertEqual(acquired_object.getStopDate(), object.getStopDate())
    self.assertEqual(acquired_object.getSourceValue(), \
Aurel's avatar
Aurel committed
801
                      object.getSourceValue())
802
    self.assertEqual(acquired_object.getDestinationValue(), \
Aurel's avatar
Aurel committed
803 804 805
                      object.getDestinationValue())


806
    self.assertEqual(acquired_object.getSourceSectionValue(), \
Aurel's avatar
Aurel committed
807
                      object.getSourceSectionValue())
808
    self.assertEqual(acquired_object.getDestinationSectionValue(), \
Aurel's avatar
Aurel committed
809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831
                      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_list = order_line.getCellValueList()
    self.assertTrue(len(cell_list) > 0)
    cell = cell_list[0]

    self.checkAcquisition(cell, order_line)
    # Test resource
832
    self.assertEqual(order_line.getResource(), \
Aurel's avatar
Aurel committed
833 834 835 836 837
                      cell.getResource())
    # Test resource variation
    cvcl = cell.getVariationCategoryList()
    olvcl = order_line.getVariationCategoryList()
    # This test is not valide anymore, because of option variation
838
#     self.assertEqual(len(order_line.getVariationRangeBaseCategoryList()), \
Aurel's avatar
Aurel committed
839 840
#                       len(cvcl))
    for variation_category in cvcl:
841
      self.assertTrue(variation_category in olvcl)
Aurel's avatar
Aurel committed
842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861

  def stepCheckOrderSimulation(self, sequence=None, sequence_list=None, **kw):
    """
      Test if simulation is matching order
    """
    self.checkOrderRuleSimulation(rule_reference='default_order_rule', sequence=sequence, \
        sequence_list=sequence_list, **kw)

  def checkOrderRuleSimulation(self, rule_reference, sequence=None, sequence_list=None, **kw):
    """
      Test if simulation is matching order, be sure that rule_reference is used
      to expand simulation for 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:
862
      self.assertEqual(0, len(related_applied_rule_list))
Aurel's avatar
Aurel committed
863 864 865
    else:
      LOG('stepCheckOrderRuleSimulation', 0, 'related_applied_rule_list: %s' %
                   str([x.getObject() for x in related_applied_rule_list]))
866
      self.assertEqual(1, len(related_applied_rule_list))
Aurel's avatar
Aurel committed
867 868
      applied_rule = related_applied_rule_list[0].getObject()
      sequence.edit(applied_rule=applied_rule)
869
      self.assertTrue(applied_rule is not None)
Aurel's avatar
Aurel committed
870 871 872

      # Test if applied rule has a specialise value with passed rule_reference
      portal_rules = getToolByName(order, 'portal_rules')
873
      self.assertEqual(rule_reference,
Aurel's avatar
Aurel committed
874 875 876 877 878 879 880 881
                        applied_rule.getSpecialiseReference())

      simulation_movement_list = applied_rule.objectValues()
      sequence.edit(simulation_movement_list=simulation_movement_list)

      # Count the number of movement in order
      movement_list = order.getMovementList()
      # Check if number of movement is equal to number of simulation movement
882
      self.assertEqual(len(movement_list), len(simulation_movement_list))
Aurel's avatar
Aurel committed
883 884 885 886 887 888 889 890 891
      # Check if each movement has only one simulation movement related
      order_movement_list = [x.getDeliveryValue() for x in \
                             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.getDeliveryValue()
        # Test quantity
892
        self.assertEqual(order_movement.getQuantity(), \
Aurel's avatar
Aurel committed
893 894
                          simulation_movement.getQuantity())
        # Test price
895
        self.assertEqual(order_movement.getPrice(), \
Aurel's avatar
Aurel committed
896 897
                          simulation_movement.getPrice())
        # Test resource
898
        self.assertEqual(order_movement.getResource(), \
Aurel's avatar
Aurel committed
899 900
                          simulation_movement.getResource())
        # Test resource variation
901
        self.assertEqual(order_movement.getVariationText(), \
Aurel's avatar
Aurel committed
902
                          simulation_movement.getVariationText())
903
        self.assertEqual(order_movement.getVariationCategoryList(), \
Aurel's avatar
Aurel committed
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
                          simulation_movement.getVariationCategoryList())
        # XXX Test acquisition
        self.checkAcquisition(simulation_movement, order_movement)

  def modifyOrderState(self, transition_name, sequence=None,
                       sequence_list=None):
    order = sequence.get('order')
    order.portal_workflow.doActionFor(order, transition_name)

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

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

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

  def stepCancelOrder(self, sequence=None, sequence_list=None, **kw):
    self.modifyOrderState('cancel_action', sequence=sequence)

  def stepCheckPortalMethod(self, sequence=None, sequence_list=None, **kw):
    """
      Test if some portal method are well defined
    """
    order = sequence.get('order')
930 931
    self.assertTrue('Simulation Movement' in order.getPortalMovementTypeList())
    self.assertTrue(self.order_line_portal_type in order.getPortalMovementTypeList())
Aurel's avatar
Aurel committed
932 933 934 935 936 937 938 939

  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)
940
    self.assertEqual('Delivery Builder', delivery_builder.getPortalType())
Aurel's avatar
Aurel committed
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

  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 stepCreateProject1(self,sequence=None, sequence_list=None, **kw):
    """
      Create a project
    """
    self.stepCreateProject(sequence=sequence, sequence_list=sequence_list,
                           **kw)
    project = sequence.get('project')
    sequence.edit(project1=project)

  def stepCreateProject2(self,sequence=None, sequence_list=None, **kw):
    """
      Create a project
    """
    self.stepCreateProject(sequence=sequence, sequence_list=sequence_list,
                           **kw)
    project = sequence.get('project')
    sequence.edit(project2=project)

  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')
    project1 = sequence.get('project1')
    project2 = sequence.get('project2')
    order = sequence.get('order')
    order.edit( source_value = organisation1,
                source_section_value = organisation1,
                source_payment_value = organisation1['bank'],
                destination_value = organisation2,
                destination_section_value = organisation2,
                destination_payment_value = organisation2['bank'],
                source_project_value = project1,
                destination_project_value = project2 )
    order.setPaymentConditionEfficiency(1.0)
996
    self.assertTrue('Site Error' not in order.view())
Aurel's avatar
Aurel committed
997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009

  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()
    if order_state != packing_list_building_state:
1010
      self.assertEqual(0, len(related_packing_list_list))
Aurel's avatar
Aurel committed
1011
    else:
1012
      self.assertEqual(1, len(related_packing_list_list))
Aurel's avatar
Aurel committed
1013 1014

      packing_list = related_packing_list_list[0].getObject()
1015
      self.assertTrue(packing_list is not None)
Aurel's avatar
Aurel committed
1016 1017 1018 1019 1020 1021 1022
      sequence.edit(packing_list = packing_list)

      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()
1023
      self.assertEqual(packing_list_building_state, packing_list_state)
Aurel's avatar
Aurel committed
1024 1025 1026 1027 1028 1029 1030

      # First, test if each Simulation Movement is related to a Packing List
      # Movement
      order_relative_url = order.getRelativeUrl()
      packing_list_relative_url = packing_list.getRelativeUrl()
      for simulation_movement in simulation_movement_list:
        order_movement_list = simulation_movement.getDeliveryValueList()
1031
        self.assertTrue(len(order_movement_list), 1)
Aurel's avatar
Aurel committed
1032
        order_movement = order_movement_list[0]
1033 1034
        self.assertTrue(order_movement is not None)
        self.assertTrue(order_movement.getRelativeUrl().\
Aurel's avatar
Aurel committed
1035 1036
                                      startswith(order_relative_url))
        rule_list = simulation_movement.objectValues()
1037
        self.assertTrue(len(rule_list), 1)
Aurel's avatar
Aurel committed
1038
        delivering_rule = rule_list[0]
1039
        self.assertTrue(delivering_rule.getSpecialiseValue().getPortalType(),
Aurel's avatar
Aurel committed
1040 1041
                        'Delivering Rule')
        child_simulation_movement_list = delivering_rule.objectValues()
1042
        self.assertTrue(len(child_simulation_movement_list), 1)
Aurel's avatar
Aurel committed
1043
        packing_list_movement_list = child_simulation_movement_list[0].getDeliveryValueList()
1044
        self.assertTrue(len(packing_list_movement_list), 1)
Aurel's avatar
Aurel committed
1045
        packing_list_movement = packing_list_movement_list[0]
1046 1047
        self.assertTrue(packing_list_movement is not None)
        self.assertTrue(packing_list_movement.getRelativeUrl().\
Aurel's avatar
Aurel committed
1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066
                                      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()
        sequence.edit(packing_list_line=packing_list_line)
        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')
1067
        self.assertTrue(len(related_simulation_movement_list)>0)
Aurel's avatar
Aurel committed
1068 1069 1070 1071 1072 1073 1074 1075
        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
1076
          self.assertEqual(packing_list_movement.getResource(), \
Aurel's avatar
Aurel committed
1077 1078
                            related_simulation_movement.getResource())
          # Test resource variation
1079
          self.assertEqual(packing_list_movement.getVariationText(), \
Aurel's avatar
Aurel committed
1080
                            related_simulation_movement.getVariationText())
1081
          self.assertEqual(packing_list_movement.getVariationCategoryList(), \
Aurel's avatar
Aurel committed
1082 1083 1084 1085 1086
                        related_simulation_movement.getVariationCategoryList())
          # Test acquisition
          self.checkAcquisition(packing_list_movement,
                                related_simulation_movement)
          # Test delivery ratio
1087
          self.assertEqual(related_simulation_movement.getQuantity() /\
Aurel's avatar
Aurel committed
1088 1089 1090 1091
                            packing_list_movement_quantity, \
                            related_simulation_movement.getDeliveryRatio())


1092
        self.assertEqual(quantity, packing_list_movement.getQuantity())
Aurel's avatar
Aurel committed
1093
        # Test price
1094
        self.assertEqual(total_price / quantity, packing_list_movement.getPrice())
Aurel's avatar
Aurel committed
1095 1096 1097 1098

      sequence.edit(packing_list=packing_list)

      # Finally, test Packing List getTotalQuantity and getTotalPrice
1099 1100
      self.assertEqual(order.getTotalQuantity(), packing_list.getTotalQuantity())
      self.assertEqual(order.getTotalPrice(), packing_list.getTotalPrice())
Aurel's avatar
Aurel committed
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

  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.order_cell_portal_type)
    self.assertTrue(len(cell_list) > 0)
    order_cell = cell_list[0].getObject()
    order_cell.setStartDate(self.datetime + 99)

  def stepModifyOrderLineQuantity(self, sequence=None, sequence_list=None, \
      **kw):
    """
    Modify order line quantity
    """
    order_line = sequence.get('order_line')
    order_line.setQuantity(order_line.getQuantity() + 111)

  def stepDeleteOrderLine(self, sequence=None, sequence_list=None, **kw):
    """
      Delete order line
    """
    order_line = sequence.get('order_line')
    order_line.getParentValue().manage_delObjects([order_line.getId()])

1144
  def stepCheckOrderConvergent(self, sequence=None, sequence_list=None, **kw):
Aurel's avatar
Aurel committed
1145 1146 1147 1148 1149
    """
    Tests that the simulation related to the order is stable and not
    divergent
    """
    order = sequence.get('order')
1150
    self.assertTrue(order.isConvergent())
Aurel's avatar
Aurel committed
1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161

  def stepPackingListAdoptPrevision(self,sequence=None, sequence_list=None,
                                    **kw):
    """
    Check if simulation movement are disconnected
    """
    packing_list = sequence.get('packing_list')
    packing_list.portal_workflow.doActionFor(packing_list,
                                             'adopt_prevision_action')

  non_variated_order_creation = '\
1162 1163 1164 1165
      stepCreateOrganisation1 \
      stepCreateOrganisation2 \
      stepCreateProject1 \
      stepCreateProject2 \
Aurel's avatar
Aurel committed
1166
      stepCreateOrder \
1167
      stepSetOrderProfile \
Aurel's avatar
Aurel committed
1168 1169 1170 1171 1172 1173 1174 1175 1176
      stepCreateNotVariatedResource \
      stepCreateOrderLine \
      stepCheckOrderLineEmptyMatrix \
      stepSetOrderLineResource \
      stepSetOrderLineDefaultValues \
      stepCheckOrderLineDefaultValues \
      '

  variated_order_line_creation = '\
1177 1178 1179 1180
      stepCreateOrganisation1 \
      stepCreateOrganisation2 \
      stepCreateProject1 \
      stepCreateProject2 \
Aurel's avatar
Aurel committed
1181
      stepCreateOrder \
1182
      stepSetOrderProfile \
Aurel's avatar
Aurel committed
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 1217
      stepCreateVariatedResource \
      stepCreateOrderLine \
      '
  variated_line_completion = '\
      stepSetOrderLineResource \
      stepSetOrderLineDefaultValues \
      stepCheckOrderLineDefaultValues \
      stepCheckOrderLineTotalQuantity \
      stepSetOrderLineFullVCL \
      stepCompleteOrderLineMatrix \
      '
  variated_order_creation = variated_order_line_creation + \
      variated_line_completion

  variated_line_completion_without_tic = '\
    stepSetOrderLineResource \
    stepSetOrderLineDefaultValues \
    stepCheckOrderLineDefaultValues \
    stepSetOrderLineFullVCL \
    stepCompleteOrderLineMatrix \
    '
  variated_order_creation_without_tic = variated_order_line_creation + \
    variated_line_completion_without_tic

  def stepCheckCatalogued(self, sequence=None,
                          sequence_list=None, **kw):
    """
    Check that order is catalogued
    """
    order = sequence.get('order')
    sql_connection = self.getSQLConnection()
    sql = 'SELECT simulation_state FROM catalog WHERE uid=%s' % \
                      order.getUid()
    result = sql_connection.manage_test(sql)
    simulation_state_list = [x['simulation_state'] for x in result]
1218 1219
    self.assertEqual(1, len(simulation_state_list))
    self.assertEqual(order.getSimulationState(),
Aurel's avatar
Aurel committed
1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234
                      simulation_state_list[0])

  def stepCheckCataloguedSimulation(self, sequence=None,
                                    sequence_list=None, **kw):
    """
    Check that simulation is catalogued
    """
    order = sequence.get('order')
    for order_movement in order.getMovementList():
      for sim_mvt in order_movement.getOrderRelatedValueList():
        sql_connection = self.getSQLConnection()
        sql = 'SELECT simulation_state FROM catalog WHERE uid=%s' % \
                          sim_mvt.getUid()
        result = sql_connection.manage_test(sql)
        simulation_state_list = [x['simulation_state'] for x in result]
1235 1236
        self.assertEqual(1, len(simulation_state_list))
        self.assertEqual(order.getSimulationState(),
Aurel's avatar
Aurel committed
1237 1238
                          simulation_state_list[0])

1239 1240
  def stepPackingListBuilderAlarm(self, sequence=None,
                                  sequence_list=None, **kw):
1241 1242 1243 1244
    # global builder alarm does not exist in legacy simulation
    # business templates.
    alarm = getattr(self.portal.portal_alarms, 'packing_list_builder_alarm', None)
    if alarm is not None:
1245
      alarm.activeSense()
1246

Aurel's avatar
Aurel committed
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 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
class TestOrder(TestOrderMixin, ERP5TypeTestCase):
  """
    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
1294 1295
#       self.assertEqual(new_quantity, cell.getProperty('quantity'))
#       self.assertEqual(new_price, cell.getProperty('price'))
Aurel's avatar
Aurel committed
1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 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 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
#
#       # 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 = 'stepCreateOrder \
                       stepCreateOrderLine \
                       stepCheckOrderLineVRCL \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepSetOrderLineResource \
                       stepCheckOrderLineVRCL \
                       '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variation
    sequence_string = 'stepCreateOrder \
                       stepCreateOrderLine \
                       stepCheckOrderLineVRCL \
                       stepCreateVariatedResource \
                       stepTic \
                       stepSetOrderLineResource \
                       stepCheckOrderLineVRCL \
                       '
    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 = 'stepCreateOrder \
                       stepCreateOrderLine \
                       stepCheckOrderLineVRCIL \
                       stepCreateNotVariatedResource \
                       stepTic \
                       stepSetOrderLineResource \
                       stepCheckOrderLineVRCIL \
                       '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variation
    sequence_string = 'stepCreateOrder \
                       stepCreateOrderLine \
                       stepCheckOrderLineVRCIL \
                       stepCreateVariatedResource \
                       stepTic \
                       stepSetOrderLineResource \
                       stepCheckOrderLineVRCIL \
                       '
    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 = 'stepCreateOrder \
                       stepCreateOrderLine \
                       stepCheckOrderLineVCIL \
                       stepCreateVariatedResource \
                       stepTic \
                       stepSetOrderLineResource \
                       stepSetOrderLineHalfVCL \
                       stepTic \
                       stepCheckOrderLineVCIL \
                       '
    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()
    # common part of sequence
    base_sequence  = 'stepTic \
                      stepCreateOrderLine \
                      stepCheckOrderLineEmptyMatrix \
                      stepSetOrderLineResource \
                      stepCheckOrderLineEmptyMatrix \
                      stepSetOrderLineFullVCL \
                      stepCheckOrderLineRange \
                      stepCheckOrderLineEmptyMatrix \
                      stepCompleteOrderLineMatrix \
                      stepTic \
                      stepCheckOrderLineCompleteMatrix \
                      stepSetOrderLineHalfVCL \
                      stepTic \
                      stepCheckOrderLineRange \
                      stepCheckOrderLineCompleteMatrix \
                      stepSetOrderLineEmptyVCL \
                      stepTic \
                      stepCheckOrderLineEmptyMatrix \
                      '
    # Test when resource has no variation
    sequence_string = 'stepCreateOrder \
                       stepCreateNotVariatedResource \
                      ' + base_sequence
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = 'stepCreateOrder \
                       stepCreateVariatedResource \
                      ' + base_sequence + \
                      'stepCheckOrderLineRange \
                      '
    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)
1444
#       self.assertEqual(price, cell.getProperty('price'))
Aurel's avatar
Aurel committed
1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 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 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613
#
# #     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 = self.non_variated_order_creation + '\
                      stepCheckOrderLineTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderLineTotalQuantity \
                      '
    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 = self.non_variated_order_creation + '\
                      stepCheckOrderLineTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderLineTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # XXX test cell modification

    sequence_list.play(self)

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

    # Test when resource has variations
    sequence_string = self.variated_order_creation_without_tic + '\
                      stepCheckOrderLineTotalPriceAndQuantityFastParameter \
                      '
    sequence_list.addSequenceString(sequence_string)

    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 = '\
                      stepCreateOrder \
                      stepCheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has not variation
    sequence_string = self.non_variated_order_creation + '\
                      stepCheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test whith multiples order line
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderTotalQuantity \
                      stepCreateNotVariatedResource \
                      stepCreateOrderLine \
                      stepTic \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepCheckOrderTotalQuantity \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_08b_Order_testTotalPriceAndQuantityFastParameter(self, quiet=0, run=run_all_test):
    """
      Test method getTotalQuantity on a order
    """
    if not run: return
    sequence_list = SequenceList()
    # Test whith multiples order line
    sequence_string = self.variated_order_creation_without_tic + '\
                      stepCreateNotVariatedResource \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepCheckOrderTotalPriceAndQuantityFastParameter \
                      '
    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 = '\
                      stepCreateOrder \
                      stepCheckOrderTotalPrice\
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has not variation
    sequence_string = self.non_variated_order_creation + '\
                      stepCheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when resource has variations
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test with multiples order line
    sequence_string = self.variated_order_creation + '\
                      stepCheckOrderTotalQuantity \
                      stepCreateNotVariatedResource \
                      stepCreateOrderLine \
                      stepTic \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepCheckOrderTotalPrice \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_09b_Order_testTotalPriceWithNegativePriceOrderLine(self, quiet=0, run=run_all_test):
    """
      Test method getTotalPrice on a order
    """
    if not run: return
    sequence_list = SequenceList()
    # Test with positive price order line and negative price order line.
    sequence_string = '\
1614 1615 1616 1617
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
Aurel's avatar
Aurel committed
1618
                      stepCreateOrder \
1619
                      stepSetOrderProfile \
Aurel's avatar
Aurel committed
1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 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 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853
                      stepCheckOrderTotalQuantity \
                      stepCreateNotVariatedResource \
                      stepCreateOrderLine \
                      stepTic \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepCreateNotVariatedResourceForNegativePriceOrderLine \
                      stepCreateOrderLine \
                      stepTic \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultNegativePriceValue \
                      stepTic \
                      stepCheckOrderTotalPrice \
                      '
    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 = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_line_creation + '\
                      stepCheckOrder \
                      stepCheckOrderInitialState \
                      stepTic \
                      stepCheckOrderLineState \
                      ' + self.variated_line_completion + '\
                      stepTic \
                      stepCheckOrderCellState \
                      stepPlanOrder \
                      stepTic \
                      stepCheckOrderPlanned \
                      stepCheckOrderLineState \
                      stepCheckOrderCellState \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  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 = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_line_creation + '\
                      stepCheckOrder \
                      stepCheckOrderInitialState \
                      stepCheckOrderLineAcquisition \
                      ' + self.variated_line_completion + '\
                      stepCheckOrderCellAcquisition \
                      stepTic \
                      '
    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 = '\
                      stepCreateOrder \
                      stepCheckPortalMethod \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test when order is cancelled
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.non_variated_order_creation + '\
                      stepCheckOrderSimulation \
                      stepPlanOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCancelOrder \
                      stepTic \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a simply order without cell
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.non_variated_order_creation + '\
                      stepPlanOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order without planned or ordered it
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_line_creation + '\
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with variated resource
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with multiples lines
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    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 = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepOrderOrder \
                      stepTic \
                      stepModifyOrderStartDate \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when order line is modified
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepOrderOrder \
                      stepTic \
                      stepModifyOrderLineStartDate \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    # Test when order cell is modified
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepOrderOrder \
                      stepTic \
                      stepModifyOrderCellStartDate \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test when workflow state is modified
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.variated_order_creation + '\
                      stepPlanOrder \
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test when order line is deleted
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.non_variated_order_creation + '\
                      stepOrderOrder \
                      stepTic \
                      stepDeleteOrderLine \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
1854 1855
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

# 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
1868
#     self.assertTrue(1==2)
Aurel's avatar
Aurel committed
1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899

  def test_15_deliveryBuilder(self, quiet=0, run=run_all_test):
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()
    # First, test if delivery buider exists
    sequence_string = '\
                      stepCheckDeliveryBuilderPresence \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a simply order without cell
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
1900 1901
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with variated resource
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      ' + self.variated_line_completion + '\
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
1924 1925
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test to confirm order with multiples lines
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      ' + self.variated_line_completion + '\
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
1953 1954
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a order with 2 lines and the same not variated resource
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
1980 1981
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    # Test with a order with 2 lines and the same variated resource
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      ' + self.variated_line_completion + '\
                      stepCreateOrderLine \
                      ' + self.variated_line_completion + '\
                      stepTic \
                      stepOrderOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
2006 2007
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

  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 = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepTic \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateVariatedResource \
                      stepCreateOrderLine \
                      ' + self.variated_line_completion + '\
                      stepCreateNotVariatedResource \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
2045 2046
                      stepPackingListBuilderAlarm \
                      stepTic \
Aurel's avatar
Aurel committed
2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092
                      stepCheckDeliveryBuilding \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

  def test_17_orderExpand(self, quiet=0, run=run_all_test):
    """
    This tests the behaviour of expand.
    First, without delivery:
      - create an order, apply a rule
      - modify the order line, expand the rule
      - check that the simulation is not Divergent and Stable (simulation must
        match order value)

    Second, with delivery:
      - create an order, apply a rule
      - build a packing list
      - modify the order line, expand the rule
      - adopt prevision to fix the delivery
      - check that the simulation is not Divergent and Stable (simulation must
        match delivery value)
    """
    if not run: return
    sequence_list = SequenceList()

    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepModifyOrderLineQuantity \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
2093
                      stepCheckOrderConvergent \
Aurel's avatar
Aurel committed
2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123
                      '
    sequence_list.addSequenceString(sequence_string)
    # XXX XXX FIXME
    # The idea of this test is to create a PackingList
    # Before the Order is in state confirmed.
    # And then, check the behaviour of isDivergent
    # when the Order is modified
    sequence_string = '\
                      stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateProject1 \
                      stepCreateProject2 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckDeliveryBuilding \
                      stepModifyOrderLineQuantity \
                      stepTic \
                      stepPackingListAdoptPrevision \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
2124
                      stepCheckOrderConvergent \
Aurel's avatar
Aurel committed
2125 2126 2127 2128 2129 2130 2131 2132 2133 2134
                      '
#     sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

#   def test_16_packingListOrderAcquisition(self, quiet=0, run=run_all_test):
#     """
#       Test if packing list get some properties from order.
#     """
#     if not run: return
2135
#     self.assertTrue(1==2)
Aurel's avatar
Aurel committed
2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179

  def test_18_SimulationStateIndexation(self, quiet=0, run=run_all_test):
    """
    Test that the simulation state is well indexed.
    """
    if not run: return

    sequence_list = SequenceList()

    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + self.non_variated_order_creation + '\
                      stepTic \
                      stepCheckCatalogued \
                      stepCheckCataloguedSimulation \
                      stepPlanOrder \
                      stepTic \
                      stepCheckCatalogued \
                      stepCheckCataloguedSimulation \
                      stepOrderOrder \
                      stepTic \
                      stepCheckCatalogued \
                      stepCheckCataloguedSimulation \
                      stepCancelOrder \
                      stepTic \
                      stepCheckCatalogued \
                      stepCheckCataloguedSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

  def test_19_getMovementList(self, quiet=0, run=run_all_test):
    """
    Check getMovementList.
    Verify that it supports hierarchical order lines.
    Check that order cells are returned when defined on a leaf line, and not
    returned when defined on a non leaf line.
    """
    if not run: return

    portal = self.getPortal()
    order_module = portal.getDefaultModule(portal_type=self.order_portal_type)
2180 2181
    order = order_module.newContent(portal_type=self.order_portal_type,
                                    specialise=self.business_process)
Aurel's avatar
Aurel committed
2182
    # No line, no movement
2183
    self.assertEqual(0, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2184 2185 2186

    # One line is considered as a movement
    order_line = order.newContent(portal_type=self.order_line_portal_type)
2187
    self.assertEqual(1, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2188 2189 2190 2191 2192

    # If a sub line is created, its parent should not be considered
    # as a movement
    sub_order_line = order_line.newContent(
               portal_type=self.order_line_portal_type)
2193
    self.assertEqual(1, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2194 2195 2196 2197

    # Create another subline to be sure it increases the line count
    sub_order_line = order_line.newContent(
               portal_type=self.order_line_portal_type)
2198
    self.assertEqual(2, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2199 2200 2201 2202 2203 2204

    # Create recursively sub lines, and check that the ovement number
    # is still the same.
    for i in range(5):
      sub_order_line = sub_order_line.newContent(
          portal_type=self.order_line_portal_type)
2205
      self.assertEqual(2, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228

    # Create a variated resource
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(portal_type=self.resource_portal_type)
    resource.edit(
      industrial_phase_list=["phase1", "phase2"],
      size_list=self.size_list,
    )

    # Prepare line variation category list
    order_line_vcl = []
    resource_vbcl = resource.getVariationBaseCategoryList()
    for vbc in resource_vbcl:
      resource_vcl = list(resource.getVariationCategoryList(
                                  base_category_list=[vbc],
                                  omit_individual_variation=0))
      resource_vcl.sort()
      order_line_vcl.extend(self.splitList(resource_vcl)[0])

    # Create cell on the deepest sub line.
    # Check that those cells increase the movement count
    sub_order_line.setResourceValue(resource)
    sub_order_line.setVariationCategoryList(order_line_vcl)
2229
    self.assertEqual(1, len(order.getMovementList()))
Aurel's avatar
Aurel committed
2230 2231 2232 2233 2234 2235 2236 2237

    base_id = 'movement'
    cell_key_list = list(sub_order_line.getCellKeyList(base_id=base_id))
    cell_key_list.sort()
    for cell_key in cell_key_list:
      cell = sub_order_line.newCell(base_id=base_id,
                                portal_type=self.order_cell_portal_type,
                                *cell_key)
2238
    self.assertEqual(2-1+len(cell_key_list), len(order.getMovementList()))
Aurel's avatar
Aurel committed
2239 2240 2241 2242

    # Check that cells defined on a non leaf line are not returned.
    order_line.setResourceValue(resource)
    order_line.setVariationCategoryList(order_line_vcl)
2243
    self.assertEqual(2-1+len(cell_key_list), len(order.getMovementList()))
Aurel's avatar
Aurel committed
2244 2245 2246 2247 2248 2249 2250 2251

    base_id = 'movement'
    cell_key_list = list(order_line.getCellKeyList(base_id=base_id))
    cell_key_list.sort()
    for cell_key in cell_key_list:
      cell = order_line.newCell(base_id=base_id,
                                portal_type=self.order_cell_portal_type,
                                *cell_key)
2252
    self.assertEqual(2-1+len(cell_key_list), len(order.getMovementList()))
Aurel's avatar
Aurel committed
2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278

    # Make sure that portal_type argument works correctly.
    self.assertEqual(len(order.getMovementList(portal_type='Sale Order Line')),
                     len([movement
                          for movement in order.getMovementList()
                          if movement.portal_type=='Sale Order Line']))
    self.assertEqual(len(order.getMovementList(portal_type='Sale Order Cell')),
                     len([movement
                          for movement in order.getMovementList()
                          if movement.portal_type=='Sale Order Cell']))
    self.assertEqual(len(order.getMovementList(portal_type=['Sale Order Line',
                                                            'Sale Order Cell'])),
                     len([movement
                          for movement in order.getMovementList()
                          if movement.portal_type in ('Sale Order Line',
                                                      'Sale Order Cell')]))

  def test_19b_getTotalQuantityAndPrice(self, quiet=0, run=run_all_test):
    """
    Check getTotalQuantity and getTotalPrice.
    Check isMovement.
    Verify that it supports hierarchical order lines.
    Note that this depends on isMovement and Order Line reindexation
    """
    if not run: return

2279
    portal = self.portal
Aurel's avatar
Aurel committed
2280 2281
    base_id = 'movement'
    order_line_vcl=['size/Baby']
2282 2283
    section = portal.organisation_module.newContent(
      portal_type='Organisation')
Aurel's avatar
Aurel committed
2284
    order_module = portal.getDefaultModule(portal_type=self.order_portal_type)
2285
    order = order_module.newContent(portal_type=self.order_portal_type,
2286 2287
                                    destination_section_value=section,
                                    destination_value=section,
2288
                                    specialise=self.business_process)
Aurel's avatar
Aurel committed
2289
    # No line, no movement
2290 2291 2292 2293
    self.assertEqual(order.getTotalQuantity(fast=0), 0)
    self.assertEqual(order.getTotalQuantity(fast=1), 0)
    self.assertEqual(order.getTotalPrice(fast=0), 0)
    self.assertEqual(order.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309

    # Create a variated resource
    resource_module = portal.getDefaultModule(self.resource_portal_type)
    resource = resource_module.newContent(
        portal_type=self.resource_portal_type,
        variation_base_category_list=['size'],
        size_list=self.size_list)

    # One line is considered as a movement
    order_line = order.newContent(
        portal_type=self.order_line_portal_type,
        resource_value=resource,
        price=2,
        quantity=3)
    self.tic()

2310
    self.assertEqual(order_line.isMovement(), True)
Aurel's avatar
Aurel committed
2311

2312 2313 2314 2315
    self.assertEqual(order.getTotalQuantity(fast=0), 3)
    self.assertEqual(order.getTotalQuantity(fast=1), 3)
    self.assertEqual(order.getTotalPrice(fast=0), 6)
    self.assertEqual(order.getTotalPrice(fast=1), 6)
Aurel's avatar
Aurel committed
2316

2317 2318 2319 2320
    self.assertEqual(order_line.getTotalQuantity(fast=0), 3)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 3)
    self.assertEqual(order_line.getTotalPrice(fast=0), 6)
    self.assertEqual(order_line.getTotalPrice(fast=1), 6)
Aurel's avatar
Aurel committed
2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336

    # add cell to line, line is not a movement anymore
    order_line.setVariationCategoryList(order_line_vcl)
    cell_key_list = order_line.getCellKeyList(base_id=base_id)
    self.assertTrue(len(cell_key_list) > 0)
    cell_key = cell_key_list[0]
    cell = order_line.newCell(
        base_id=base_id,
        portal_type=self.order_cell_portal_type,
        *cell_key)
    cell.edit(mapped_value_property_list=['price', 'quantity'],
        price=3, quantity=4,
        predicate_category_list=cell_key,
        variation_category_list=cell_key)
    self.tic()

2337 2338
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), True)
Aurel's avatar
Aurel committed
2339

2340 2341 2342 2343
    self.assertEqual(order.getTotalQuantity(fast=0), 4)
    self.assertEqual(order.getTotalQuantity(fast=1), 4)
    self.assertEqual(order.getTotalPrice(fast=0), 12)
    self.assertEqual(order.getTotalPrice(fast=1), 12)
Aurel's avatar
Aurel committed
2344

2345 2346 2347 2348
    self.assertEqual(order_line.getTotalQuantity(fast=0), 4)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 4)
    self.assertEqual(order_line.getTotalPrice(fast=0), 12)
    self.assertEqual(order_line.getTotalPrice(fast=1), 12)
Aurel's avatar
Aurel committed
2349

2350 2351
    self.assertEqual(cell.getTotalQuantity(), 4)
    self.assertEqual(cell.getTotalPrice(), 12)
Aurel's avatar
Aurel committed
2352 2353 2354 2355 2356 2357

    # if cell has no price, the total price is None, but a default value can be
    # provided
    cell.setPrice(None)
    self.tic()

2358 2359
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), True)
Aurel's avatar
Aurel committed
2360

2361 2362 2363 2364
    self.assertEqual(order.getTotalQuantity(fast=0), 4)
    self.assertEqual(order.getTotalQuantity(fast=1), 4)
    self.assertEqual(order.getTotalPrice(fast=0), 0)
    self.assertEqual(order.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2365

2366 2367 2368 2369
    self.assertEqual(order_line.getTotalQuantity(fast=0), 4)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 4)
    self.assertEqual(order_line.getTotalPrice(fast=0), 0)
    self.assertEqual(order_line.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2370

2371 2372
    self.assertEqual(cell.getTotalQuantity(), 4)
    self.assertEqual(cell.getTotalPrice(), 0)
Aurel's avatar
Aurel committed
2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384

    # restore the price on the line
    cell.setPrice(3)
    self.tic()

    # add sub_line to line, cell and line are not movements
    sub_order_line = order_line.newContent(
        portal_type=self.order_line_portal_type,
        price=4,
        quantity=5)
    self.tic()

2385 2386 2387
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), False)
    self.assertEqual(sub_order_line.isMovement(), True)
Aurel's avatar
Aurel committed
2388

2389 2390 2391 2392
    self.assertEqual(order.getTotalQuantity(fast=0), 5)
    self.assertEqual(order.getTotalQuantity(fast=1), 5)
    self.assertEqual(order.getTotalPrice(fast=0), 20)
    self.assertEqual(order.getTotalPrice(fast=1), 20)
Aurel's avatar
Aurel committed
2393

2394 2395 2396 2397
    self.assertEqual(order_line.getTotalQuantity(fast=0), 5)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 5)
    self.assertEqual(order_line.getTotalPrice(fast=0), 20)
    self.assertEqual(order_line.getTotalPrice(fast=1), 20)
Aurel's avatar
Aurel committed
2398

2399 2400
    self.assertEqual(cell.getTotalQuantity(), 0)
    self.assertEqual(cell.getTotalPrice(), 0)
Aurel's avatar
Aurel committed
2401

2402 2403 2404 2405
    self.assertEqual(sub_order_line.getTotalQuantity(fast=0), 5)
    self.assertEqual(sub_order_line.getTotalQuantity(fast=1), 5)
    self.assertEqual(sub_order_line.getTotalPrice(fast=0), 20)
    self.assertEqual(sub_order_line.getTotalPrice(fast=1), 20)
Aurel's avatar
Aurel committed
2406 2407 2408 2409

    # if this line has no price, getTotalPrice returns 0
    sub_order_line.setPrice(None)
    self.tic()
2410 2411 2412
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), False)
    self.assertEqual(sub_order_line.isMovement(), True)
Aurel's avatar
Aurel committed
2413

2414 2415 2416 2417
    self.assertEqual(order.getTotalQuantity(fast=0), 5)
    self.assertEqual(order.getTotalQuantity(fast=1), 5)
    self.assertEqual(order.getTotalPrice(fast=0), 0)
    self.assertEqual(order.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2418

2419 2420 2421 2422
    self.assertEqual(order_line.getTotalQuantity(fast=0), 5)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 5)
    self.assertEqual(order_line.getTotalPrice(fast=0), 0)
    self.assertEqual(order_line.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2423

2424 2425
    self.assertEqual(cell.getTotalQuantity(), 0)
    self.assertEqual(cell.getTotalPrice(), 0)
Aurel's avatar
Aurel committed
2426

2427 2428 2429 2430
    self.assertEqual(sub_order_line.getTotalQuantity(fast=0), 5)
    self.assertEqual(sub_order_line.getTotalQuantity(fast=1), 5)
    self.assertEqual(sub_order_line.getTotalPrice(fast=0), 0)
    self.assertEqual(sub_order_line.getTotalPrice(fast=1), 0)
Aurel's avatar
Aurel committed
2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449

    # restore price on the sub line
    sub_order_line.setPrice(4)
    self.tic()


    # add sub_cell to sub_line, only sub_cell is movement
    sub_order_line.setVariationCategoryList(order_line_vcl)
    sub_cell_key = sub_order_line.getCellKeyList(base_id=base_id)[0]
    sub_cell = sub_order_line.newCell(
        base_id=base_id,
        portal_type=self.order_cell_portal_type,
        *cell_key)
    sub_cell.edit(mapped_value_property_list=['price', 'quantity'],
        price=5, quantity=6,
        predicate_category_list=cell_key,
        variation_category_list=cell_key)
    self.tic()

2450 2451 2452 2453
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), False)
    self.assertEqual(sub_order_line.isMovement(), False)
    self.assertEqual(sub_cell.isMovement(), True)
Aurel's avatar
Aurel committed
2454

2455 2456 2457 2458
    self.assertEqual(order.getTotalQuantity(fast=0), 6)
    self.assertEqual(order.getTotalQuantity(fast=1), 6)
    self.assertEqual(order.getTotalPrice(fast=0), 30)
    self.assertEqual(order.getTotalPrice(fast=1), 30)
Aurel's avatar
Aurel committed
2459

2460 2461 2462 2463
    self.assertEqual(order_line.getTotalQuantity(fast=0), 6)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 6)
    self.assertEqual(order_line.getTotalPrice(fast=0), 30)
    self.assertEqual(order_line.getTotalPrice(fast=1), 30)
Aurel's avatar
Aurel committed
2464

2465 2466
    self.assertEqual(cell.getTotalQuantity(), 0)
    self.assertEqual(cell.getTotalPrice(), 0)
Aurel's avatar
Aurel committed
2467

2468 2469 2470 2471
    self.assertEqual(sub_order_line.getTotalQuantity(fast=0), 6)
    self.assertEqual(sub_order_line.getTotalQuantity(fast=1), 6)
    self.assertEqual(sub_order_line.getTotalPrice(fast=0), 30)
    self.assertEqual(sub_order_line.getTotalPrice(fast=1), 30)
Aurel's avatar
Aurel committed
2472

2473 2474
    self.assertEqual(sub_cell.getTotalQuantity(), 6)
    self.assertEqual(sub_cell.getTotalPrice(), 30)
Aurel's avatar
Aurel committed
2475 2476 2477 2478 2479

    # delete sub_line, cell is movement again
    order_line.manage_delObjects([sub_order_line.getId()])
    self.tic()

2480 2481
    self.assertEqual(order_line.isMovement(), False)
    self.assertEqual(cell.isMovement(), True)
Aurel's avatar
Aurel committed
2482

2483 2484 2485 2486
    self.assertEqual(order.getTotalQuantity(fast=0), 4)
    self.assertEqual(order.getTotalQuantity(fast=1), 4)
    self.assertEqual(order.getTotalPrice(fast=0), 12)
    self.assertEqual(order.getTotalPrice(fast=1), 12)
Aurel's avatar
Aurel committed
2487

2488 2489 2490 2491
    self.assertEqual(order_line.getTotalQuantity(fast=0), 4)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 4)
    self.assertEqual(order_line.getTotalPrice(fast=0), 12)
    self.assertEqual(order_line.getTotalPrice(fast=1), 12)
Aurel's avatar
Aurel committed
2492

2493 2494
    self.assertEqual(cell.getTotalQuantity(), 4)
    self.assertEqual(cell.getTotalPrice(), 12)
Aurel's avatar
Aurel committed
2495 2496 2497 2498 2499 2500

    # delete cell, line is movement again
    order_line.manage_delObjects([cell.getId()])
    order_line.setVariationCategoryList([])
    self.tic()

2501
    self.assertEqual(order_line.isMovement(), True)
Aurel's avatar
Aurel committed
2502

2503 2504 2505 2506
    self.assertEqual(order.getTotalQuantity(fast=0), 3)
    self.assertEqual(order.getTotalQuantity(fast=1), 3)
    self.assertEqual(order.getTotalPrice(fast=0), 6)
    self.assertEqual(order.getTotalPrice(fast=1), 6)
Aurel's avatar
Aurel committed
2507

2508 2509 2510 2511
    self.assertEqual(order_line.getTotalQuantity(fast=0), 3)
    self.assertEqual(order_line.getTotalQuantity(fast=1), 3)
    self.assertEqual(order_line.getTotalPrice(fast=0), 6)
    self.assertEqual(order_line.getTotalPrice(fast=1), 6)
Aurel's avatar
Aurel committed
2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618

  def stepCreateSubOrderLine(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty order line
    """
    order = sequence.get('order')
    # Create sub line in the first order line
    order_line = \
        order.contentValues(portal_type=self.order_line_portal_type)[0]
    sub_order_line = order_line.newContent(
        portal_type=self.order_line_portal_type,
        title="Sub Order Line")
    sequence.edit(order_line=sub_order_line,
                  sub_order_line=sub_order_line)

  def stepCreateSubSubOrderLine(self,sequence=None, sequence_list=None, **kw):
    """
      Create a empty order line
    """
    sub_order_line = sequence.get('sub_order_line')
    # Create sub line in the first sub order line
    order_line = sub_order_line.newContent(
        portal_type=self.order_line_portal_type,
        title="Sub Order Line")
    sequence.edit(order_line=order_line)

  def test_20_testHierarchicalOrderAppliedRuleGeneration(self, quiet=0,
                                                         run=run_all_test):
    """
    Test generation and update of an hierarchical order applied rule.
    """
    if not run: return
    sequence_list = SequenceList()

    hierarchical_order_creation = '\
        stepCreateOrder \
        stepCreateNotVariatedResource \
        stepCreateOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        \
        stepCreateSubOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        \
        stepCreateSubSubOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        \
        stepCreateSubSubOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        \
        stepCreateSubOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        \
        stepCreateOrderLine \
        stepCheckOrderLineEmptyMatrix \
        stepSetOrderLineResource \
        stepSetOrderLineDefaultValues \
        stepCheckOrderLineDefaultValues \
        '

    # Test when order is cancelled
    sequence_string = '\
                      stepCreateOrganisation \
                      stepCreateProject \
                      ' + hierarchical_order_creation + '\
                      stepCheckOrderSimulation \
                      stepPlanOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepOrderOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCancelOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)


  def test_order_cell_getTotalPrice(self):
    # test getTotalPrice and getTotalQuantity on a line with cells
    # More precisely, it tests a previous bug where creating a line with
    # quantity X and then adding a cell with quantity, cell.edit where
    # comparing quantities (X and X) and didn't really edit the quantity.
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',
                    variation_base_category_list=['size'])

    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2619
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2620 2621 2622 2623 2624
                              title='Order')
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
2625 2626 2627 2628
    self.assertEqual(10, line.getTotalQuantity())
    self.assertEqual(10 * 3, line.getTotalPrice())
    self.assertEqual(10, order.getTotalQuantity())
    self.assertEqual(10 * 3, order.getTotalPrice())
Aurel's avatar
Aurel committed
2629 2630

    line.setVariationCategoryList(['size/Baby', 'size/Child/32'])
2631 2632 2633 2634
    self.assertEqual(0, line.getTotalQuantity())
    self.assertEqual(0, line.getTotalPrice())
    self.assertEqual(0, order.getTotalQuantity())
    self.assertEqual(0, order.getTotalPrice())
Aurel's avatar
Aurel committed
2635 2636 2637 2638

    self.assertTrue(line.hasInRange('size/Baby', base_id='movement'))
    cell_baby = line.newCell('size/Baby', base_id='movement',
                             portal_type=self.order_cell_portal_type)
2639 2640
    self.assertEqual(0, cell_baby.getProperty("quantity"))
    self.assertEqual(0, cell_baby.getQuantity())
Aurel's avatar
Aurel committed
2641 2642 2643 2644 2645 2646
    self.assertFalse(cell_baby.hasProperty('quantity'))
    cell_baby.edit(quantity=10,
                   price=4,
                   variation_category_list=['size/Baby'],
                   mapped_value_property_list=['quantity', 'price'],
                   edit_order=[])
2647 2648
    self.assertEqual(10, cell_baby.getQuantity())
    self.assertEqual(4, cell_baby.getPrice())
Aurel's avatar
Aurel committed
2649 2650 2651 2652

    self.assertTrue(line.hasInRange('size/Child/32', base_id='movement'))
    cell_child_32 = line.newCell('size/Child/32', base_id='movement',
                                 portal_type=self.order_cell_portal_type)
2653
    self.assertEqual(0, cell_child_32.getQuantity())
Aurel's avatar
Aurel committed
2654 2655 2656 2657 2658
    cell_child_32.edit(quantity=20,
                       price=5,
                       variation_category_list=['size/Child/32'],
                       mapped_value_property_list=['quantity', 'price'],
                       edit_order=[])
2659 2660
    self.assertEqual(20, cell_child_32.getQuantity())
    self.assertEqual(5, cell_child_32.getPrice())
Aurel's avatar
Aurel committed
2661

2662 2663
    self.assertEqual(10 + 20, line.getTotalQuantity())
    self.assertEqual(10*4 + 20*5, line.getTotalPrice())
Aurel's avatar
Aurel committed
2664

2665 2666
    self.assertEqual(10 + 20, order.getTotalQuantity())
    self.assertEqual(10*4 + 20*5, order.getTotalPrice())
Aurel's avatar
Aurel committed
2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679

  def test_order_payment_condition_copied(self):
    # Payment Condition should be copied in the packing list
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2680
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2681
                              title='Order',
2682
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2683 2684 2685 2686 2687 2688 2689 2690 2691 2692
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    # set properties, on the default payment condition
    order.setDefaultPaymentConditionQuantity(10)
2693
    self.assertEqual(1, len(order.contentValues(
Aurel's avatar
Aurel committed
2694 2695 2696 2697
                              portal_type='Payment Condition')))

    order.confirm()
    self.tic()
2698 2699
    self.stepPackingListBuilderAlarm()
    self.tic()
Aurel's avatar
Aurel committed
2700 2701 2702
    related_packing_list = order.getCausalityRelatedValue(
                                   portal_type=self.packing_list_portal_type)
    self.assertNotEquals(related_packing_list, None)
2703
    self.assertEqual(1, len(related_packing_list.contentValues(
Aurel's avatar
Aurel committed
2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717
                                          portal_type='Payment Condition')))

  def test_Order_viewAsODT(self):
    # tests order printout
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2718
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2719
                              title='Order',
2720
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    order.setReference('OrderReference')
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))
    # The name of the printout is the reference of the order
    content_disposition = self.portal.REQUEST.RESPONSE.getHeader('content-disposition')
2741
    self.assertEqual(content_disposition, 'attachment; filename="OrderReference.odt"')
Aurel's avatar
Aurel committed
2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754

  def test_Order_viewAsODT_person(self):
    # test order printout with a person as destination
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.person_module.newContent(
                              portal_type='Person', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2755
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2756
                              title='Order',
2757
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))


  def test_Order_viewAsODT_image(self):
    # tests order printout with images
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    image = FileUpload(os.path.join(os.path.dirname(__file__),
                      'test_data', 'images', 'erp5_logo.png'), 'rb')
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client',
                              default_image_file=image)
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor',
                              default_image_file=image)
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2793
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2794
                              title='Order',
2795
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))

  def test_Order_viewAsODT_big_image(self):
    # tests order printout with big images (that has Pdata)
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    image = FileUpload(os.path.join(os.path.dirname(__file__),
                      'test_data', 'images', 'erp5_logo.bmp'), 'rb')
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client',
                              default_image_file=image)
    from OFS.Image import Pdata
    self.assertTrue(isinstance(client.getDefaultImageValue().data, Pdata))
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor',
                              default_image_file=image)
    from OFS.Image import Pdata
    self.assertTrue(isinstance(vendor.getDefaultImageValue().data, Pdata))
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2834
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2835
                              title='Order',
2836
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))

  def test_Order_viewAsODT_non_ascii(self):
    # test order printout with non ascii characters
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Résource',)
    
    # TODO: once we have updated order printout to use trade model lines, test
    # the case of a trade model line with non ascii title on resource.
    
    # tax = self.portal.tax_module.newContent(portal_type='Tax', title='tàx')
 
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Cliént',
                              default_address_city='Vïllà')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation',
                              title='Vendœr',
                              default_address_city='Vïllà')
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2877
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2878
                              title='Ordàr',
2879
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            reference='à',
                            resource_value=resource,
                            quantity=10,
                            price=3)

    # see TODO above
    #tax_line = order.newContent(portal_type='Tax Line',
    #                            resource_value=tax,
    #                            quantity=30,
    #                            price=.26)

    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))

  def test_Order_viewAsODT_hierarchical(self):
    # tests order printout with hierearchical order (with lines inside lines)
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
                              portal_type=self.order_portal_type,
2918
                              specialise=self.business_process,
Aurel's avatar
Aurel committed
2919
                              title='Order',
2920
                              start_date=self.datetime,
Aurel's avatar
Aurel committed
2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
    line = order.newContent(portal_type=self.order_line_portal_type,
                            description='Content')
    if self.order_line_portal_type not in [x.getId() for x in
                                           line.allowedContentTypes()]:
      return # skip this test if hierarchical orders are not available (eg.
             # for Purchase Order)

    line = line.newContent(portal_type=self.order_line_portal_type,
                            resource_value=resource,
                            quantity=10,
                            price=3)
    order.confirm()
    self.tic()

    odt = order.Order_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))

  # TODO: test with cells ?

  def test_subcontent_reindexing(self):
    """Tests, that modification on Order are propagated to lines and cells
    during reindxation"""
    order = self.portal.getDefaultModule(self.order_portal_type).newContent(
2952 2953
                              portal_type=self.order_portal_type,
                              specialise=self.business_process)
Aurel's avatar
Aurel committed
2954 2955
    order_line = order.newContent(portal_type=self.order_line_portal_type)
    inner_order_line = order_line.newContent(
2956 2957
            portal_type=self.order_line_portal_type,
            start_date=self.datetime)
Aurel's avatar
Aurel committed
2958 2959 2960 2961 2962
    order_cell = order_line.newContent(
        portal_type=self.order_cell_portal_type)
    self._testSubContentReindexing(order, [order_line, inner_order_line,
      order_cell])

2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973
  def test_sale_order_view_parent_domain(self):
    # test that arent domain can be used by non manager users
    uf = self.portal.acl_users
    uf._doAddUser(self.id(), '', ['Author', 'Member', 'Assignee'], [])
    user = uf.getUserById(self.id()).__of__(uf)

    newSecurityManager(None, user)
    sale_order = self.portal.sale_order_module.newContent(
                              portal_type='Sale Order')
    sale_order.newContent(portal_type='Sale Order Line')
    
2974 2975
    # XXX: hard coding a selection_name is bad
    selection_name = 'SaleOrder_view_listbox_selection'
2976
    self.assertEqual(selection_name,
2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993
        sale_order.SaleOrder_view.listbox.get_value('selection_name'))
    
    # activate report tree
    self.portal.portal_selections.setListboxDisplayMode(
        self.portal.REQUEST, 'ReportTreeMode', selection_name)
    self.portal.portal_selections.setSelectionParamsFor(
        selection_name=selection_name,
        params=dict(report_path="parent_domain",
                    report_opened=1,
                    report_tree_mode=1))

    html = sale_order.view()
    # report tree is used, and we had no error
    self.assertTrue('listbox-table-report-tree-selection-cell' in html)
    self.assertTrue('Object Tree' in html)


Aurel's avatar
Aurel committed
2994 2995 2996 2997
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestOrder))
  return suite