testProductionOrder.py 72.3 KB
Newer Older
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
##############################################################################
#
# Copyright (c) 2005-2008 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
#          Romain Courteaud <romain@nexedi.com>
#          Lukasz Nowak <lukasz.nowak@ventis.com.pl>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

import unittest

33 34
import transaction

35 36 37 38 39 40 41 42 43 44 45 46
from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.CMFCore.utils import getToolByName
from testOrder import TestOrderMixin

class TestProductionOrderMixin(TestOrderMixin):

  run_all_test = 1
  resource_portal_type = 'Product'
  order_portal_type = 'Production Order'
  order_line_portal_type = 'Production Order Line'
47
  order_cell_portal_type = 'Production Order Cell'
48 49 50 51 52 53 54 55 56
  supply_chain_portal_type = 'Supply Chain'
  supply_node_portal_type = 'Supply Node'
  supply_link_portal_type = 'Supply Link'
  component_portal_type = 'Component'
  transformation_portal_type = 'Transformation'
  transformed_resource_portal_type = \
                        'Transformation Transformed Resource'
  operation_line_portal_type = 'Transformation Operation'

57
  operation_category_list = ['operation1', 'operation2']
58 59
  colour_variation_portal_type = 'Product Individual Variation'
  morphology_variation_portal_type = 'Product Individual Variation'
60 61 62 63 64

  colour_list = ['green','blue']
  mrp_size_list = ['Man','Woman']


65 66 67 68 69
  def getBusinessTemplateList(self):
    """
    """
    return ('erp5_base','erp5_pdm', 'erp5_trade', 'erp5_mrp',)

70 71 72 73 74 75 76 77 78 79 80
  def setUpPreferences(self):
    portal = self.getPortal()
    preferences = getToolByName(portal,'portal_preferences')

    system_preference = preferences.newContent(
      portal_type = 'System Preference'
    )

    system_preference.edit(
      preferred_product_individual_variation_base_category = ('variation',),
      preferred_component_individual_variation_base_category = ('variation',),
81
      preferred_product_variation_base_category = ('industrial_phase', 'colour', 'size'),
82
      preferred_component_variation_base_category = ('colour', 'size'),
83 84 85 86
      priority = 1,
    )

    system_preference.enable()
87
    transaction.commit()
88 89 90 91 92 93
    self.tic()

  def afterSetUp(self):
    TestOrderMixin.afterSetUp(self)
    self.setUpPreferences()

94 95 96 97 98 99 100
  def createCategories(self):
    """ 
      Light install create only base categories, so we create 
      some categories for testing them
    """
    TestOrderMixin.createCategories(self)
    if len(self.category_tool.operation.contentValues()) == 0:
101
      for category_id in self.operation_category_list:
102 103 104 105
        o = self.category_tool.operation.newContent(
                                               portal_type='Category',
                                               id=category_id)

106
  def stepCreateColourSizeVariatedComponent1(self,sequence=None, sequence_list=None, \
107 108
                                    **kw):
    """
109
      Create a resource with colour and size variation
110 111 112 113 114 115 116
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.component_portal_type)
    resource = resource_module.newContent(
                                  portal_type=self.component_portal_type)
    resource.edit(
      title = "ColourSizeVariatedComponent1",
117
      variation_base_category_list = ['colour','size'],
118
    )
119
    resource.setVariationCategoryList(['size/'+q for q in self.mrp_size_list] + ['colour/'+q for q in self.colour_list])
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
    sequence.edit(component1=resource)

  def stepCreateColourSizeVariatedResource(self, sequence=None, sequence_list=None, \
                                 **kw):
    """
      Create a resource with colour and size 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 = "ColourSizeVariatedResource",
      industrial_phase_list=["phase1", "phase2"],
      variation_base_category_list = ['size','colour'],
    )
    resource.setVariationCategoryList(['size/'+q for q in self.mrp_size_list] + ['colour/'+q for q in self.colour_list])

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

142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  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",
      industrial_phase_list=["phase1", "phase2"],
      product_line = 'apparel'
    )
#    resource.setSizeList(self.size_list)
    # Add colour variation
157
    
158 159
    colour_variation_count = 3
    for i in range(colour_variation_count):
160
      variation = resource.newContent(portal_type = self.colour_variation_portal_type)
161 162 163 164 165 166 167
      variation.edit(
        title = 'ColourVariation%s' % str(i),
        variation_base_category_list = ('variation',)
      )
    # Add morphology variation
    morphology_variation_count = 2
    for i in range(morphology_variation_count) :
168
      variation = resource.newContent(portal_type=self.morphology_variation_portal_type)
169 170 171 172 173 174 175 176 177 178
      variation.edit(
        title = 'MorphologyVariation%s' % str(i),
        variation_base_category_list = ('variation',)
      )

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

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
  def stepClearActivities(self, sequence=None, sequence_list=None, 
                          **kw):
    """
    Clear activity tables
    """
    activity_tool = self.getPortal().portal_activities
    activity_tool.manageClearActivities(keep=0)

  def stepCreateProductionOrganisation1(self, sequence=None, sequence_list=None, 
                                        **kw):
    """
      Create a organisation for supply
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                title='production_organisation1', **kw)

  # Note: SC means Supply Chain
  def stepCreateGenericSC(self, sequence=None, sequence_list=None, **kw):
    """
      Create a empty Supply Chain
    """
    portal = self.getPortal()
    supply_chain_module = portal.getDefaultModule( \
                                   portal_type=self.supply_chain_portal_type)
    supply_chain = supply_chain_module.newContent( \
                                   portal_type=self.supply_chain_portal_type)
    supply_chain.edit(
206
      title = "Supply Chain Generic",
207 208 209 210 211 212 213 214 215 216 217 218
    )
    sequence.edit(supply_chain=supply_chain)

  def stepCreateProductionSC(self, sequence=None, sequence_list=None, 
                             **kw):
    """
      Create a empty organisation
    """
    # Create supply chain
    self.stepCreateGenericSC(sequence=sequence, sequence_list=sequence_list,
                             **kw)
    supply_chain = sequence.get('supply_chain')
219 220 221
    supply_chain.edit(
      title = 'Supply Chain Production'
    )
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295
    # Create production node
    production_organisation  = sequence.get('production_organisation1')
    production_node = supply_chain.newContent(
                         portal_type=self.supply_node_portal_type)
    production_node.edit(
      destination_value=production_organisation
    )
    sequence.edit(production_node1=production_node)
    # Create production link
    production_link = supply_chain.newContent(
                         portal_type=self.supply_link_portal_type)
    production_link.edit(
      destination_value=production_node,
      destination_section_value=production_organisation,
      min_delay=5,
      max_delay=6,
      deliverable=1,
      industrial_phase_list=["phase1"]
    )

  def stepCreateComponent1(self,sequence=None, sequence_list=None, \
                                    **kw):
    """
      Create a resource with no variation
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.component_portal_type)
    resource = resource_module.newContent(
                                  portal_type=self.component_portal_type)
    resource.edit(
      title = "Component1"
    )
    sequence.edit(component1=resource)

  def stepCreateComponent2(self,sequence=None, sequence_list=None, \
                                    **kw):
    """
      Create a resource with no variation
    """
    portal = self.getPortal()
    resource_module = portal.getDefaultModule(self.component_portal_type)
    resource = resource_module.newContent(
                                  portal_type=self.component_portal_type)
    resource.edit(
      title = "Component2"
    )
    sequence.edit(component2=resource)

  def stepInvalidateTransformation(self, sequence=None, sequence_list=None,
                               **kw):
    transformation = sequence.get('transformation')

    workflow_tool = self.getPortal().portal_workflow

    workflow_tool.doActionFor(
        transformation,
        'invalidate_action'
    )

    self.assertEquals('invalidated',transformation.getValidationState())

  def stepValidateTransformation(self, sequence=None, sequence_list=None,
                               **kw):
    transformation = sequence.get('transformation')

    workflow_tool = self.getPortal().portal_workflow

    workflow_tool.doActionFor(
        transformation,
        'validate_action'
    )

    self.assertEquals('validated',transformation.getValidationState())

296 297 298 299 300 301 302 303 304 305
  def stepCreateEmptyTransformation(self, sequence=None, sequence_list=None,
                               **kw):
    portal = self.getPortal()
    transformation_module = portal.getDefaultModule(
                                     self.transformation_portal_type)
    transformation = transformation_module.newContent(
                                   portal_type=self.transformation_portal_type)
    sequence.edit(transformation=transformation)


306 307
  def stepSetTransformationTransformedResourceQuantityMatrix(self, sequence=None, sequence_list=None,
                               **kw):
308 309 310
    """
      Fills variation based quantity matrix
    """
311 312 313 314 315

    transformation_transformed_resource = sequence.get('transformation_transformed_resource')

    for colour in self.colour_list:
      for size in self.mrp_size_list:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
316 317 318
        transformation_transformed_resource.newCell(
          'colour/%s' % colour,
          'size/%s' % size,
319
          quantity = self.colour_size_quantity_dict[colour][size],
Nicolas Dumazet's avatar
Nicolas Dumazet committed
320
          base_id="quantity",
321 322 323 324
        )

  def stepSetTransformationTransformedResourceVariationMatrix(self, sequence=None, sequence_list=None,
                               **kw):
325 326 327
    """
      Fills variation matrix
    """
328 329 330 331 332

    transformation_transformed_resource = sequence.get('transformation_transformed_resource')

    for colour in self.colour_list:
      for size in self.mrp_size_list:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
333 334 335
        transformation_transformed_resource.newCell(
          'colour/%s' % colour,
          'size/%s' % size,
336
          categories = self.colour_size_variation_dict[colour][size],
Nicolas Dumazet's avatar
Nicolas Dumazet committed
337
          base_id="variation",
338 339
        )

340 341
  def stepSetOrderLineQuantityMatrix(self, sequence=None, sequence_list=None,
                               **kw):
342 343 344
    """
      Fills variation based quantity matrix
    """
345 346 347 348
    order_line = sequence.get('order_line')

    for colour in self.colour_list:
      for size in self.mrp_size_list:
Nicolas Dumazet's avatar
Nicolas Dumazet committed
349 350
        order_line.newCell(
          'size/%s' % size,
Nicolas Dumazet's avatar
Nicolas Dumazet committed
351
          'colour/%s' % colour,
Nicolas Dumazet's avatar
Nicolas Dumazet committed
352
          quantity = self.order_line_colour_size_quantity_dict[colour][size],
Nicolas Dumazet's avatar
Nicolas Dumazet committed
353
          base_id='movement',
354 355 356 357 358 359 360 361 362 363
        )

  def stepSetOrderLineVariationCategories(self, sequence=None, sequence_list=None,
                               **kw):
    order_line = sequence.get('order_line')

    order_line.setVariationCategoryList(
      value = self.order_line_variation_category_list
    )

364 365
  def stepSetTransformationTransformedResourceVariation(self, sequence=None, sequence_list=None,
                               **kw):
366 367 368
    """
      Fills categories of variation
    """
369 370 371 372 373 374 375 376 377 378

    transformation_transformed_resource = sequence.get('transformation_transformed_resource')

    transformation_transformed_resource.edit(
        v_variation_base_category_list = self.variation_category_list,
        q_variation_base_category_list = self.variation_category_list,
    )

  def stepSetTransformationVariation(self, sequence=None, sequence_list=None,
                               **kw):
379 380 381
    """
      Fills categories of variation
    """
382 383 384 385 386 387 388

    transformation = sequence.get('transformation')

    transformation.edit(
        variation_base_category_list = self.variation_category_list
    )
    
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
  def stepFillTransformationWithResource(self, sequence=None, sequence_list=None,
                               **kw):

    transformation = sequence.get('transformation')

    resource = sequence.get('resource')

    self.assertNotEquals(None, resource)

    transformation.edit(
      resource_value = resource
    )

  def stepSetOrderLineQuantity(self, sequence=None, sequence_list=None,
                               **kw):
    order_line = sequence.get('order_line')
    order_line.edit(
        quantity = self.production_order_line_quantity
    )

  def stepSetTransformationTransformedResourceQuantity(self, sequence=None, sequence_list=None,
                               **kw):
    transformation_transformed_resource = sequence.get('transformation_transformed_resource')
    transformation_transformed_resource.edit(
      quantity = self.transformation_transformed_resource_quantity
    )

  def stepSetTransformationTransformedResourceEfficiency(self, sequence=None, sequence_list=None,
                               **kw):
    transformation_transformed_resource = sequence.get('transformation_transformed_resource')
    transformation_transformed_resource.edit(
      efficiency = self.transformation_transformed_resource_efficiency
    )

  def stepSetTransformationTransformedResourceIndustrialPhaseList(self, sequence=None, sequence_list=None,
                               **kw):
    transformation_transformed_resource = sequence.get('transformation_transformed_resource')
    transformation_transformed_resource.edit(
      industrial_phase_list = self.transformation_transformed_resource_industrial_phase_list
    )

  def stepFillTransformationTransformedResourceWithComponent1(self, sequence=None, sequence_list=None,
                               **kw):
    transformation_transformed_resource = sequence.get('transformation_transformed_resource')
    component1 = sequence.get('component1')

    self.assertNotEquals(None, component1)

    transformation_transformed_resource.edit(
      resource_value = component1,
    )

  def stepCreateTransformationTransformedResource(self, sequence=None, sequence_list=None,
                               **kw):

    transformation = sequence.get('transformation')
    transformation_transformed_resource = transformation.newContent(
      portal_type = self.transformed_resource_portal_type,
        )

    sequence.edit(transformation_transformed_resource = transformation_transformed_resource)

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 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507
  def stepCreateTransformation(self, sequence=None, sequence_list=None,
                               **kw):
    """
      Create a transformation
    """
    # Create transformation
    portal = self.getPortal()
    transformation_module = portal.getDefaultModule(
                                     self.transformation_portal_type)
    transformation = transformation_module.newContent(
                                   portal_type=self.transformation_portal_type)
    sequence.edit(transformation=transformation)
    # Set resource
    resource = sequence.get('resource')
    transformation.setResourceValue(resource)
    # Create operation line 1
    operation_line = transformation.newContent(
        portal_type=self.operation_line_portal_type)
    operation_line.edit(
        # FIXME hardcoded
        quantity=2,
        resource_value=portal.portal_categories.resolveCategory(
                                     'operation/operation1'),
        industrial_phase_list=['phase1']
    )

    # Create operation line 2
    operation_line = transformation.newContent(
        portal_type=self.operation_line_portal_type)
    operation_line.edit(
        # FIXME hardcoded
        quantity=3,
        resource_value=portal.portal_categories.resolveCategory(
                                     'operation/operation2'),
        industrial_phase_list=['phase2']
    )
    # Create transformed resource line 1
    line = transformation.newContent(
        portal_type=self.transformed_resource_portal_type)
    line.edit(
        # FIXME hardcoded
        quantity=6,
        resource_value=sequence.get('component1'),
        industrial_phase_list=['supply_phase1']
    )
    # Create transformed resource line 2
    line = transformation.newContent(
        portal_type=self.transformed_resource_portal_type)
    line.edit(
        # FIXME hardcoded
        quantity=7,
        resource_value=sequence.get('component2'),
        industrial_phase_list=['supply_phase2']
    )

  def stepCreateOrder(self, sequence=None, sequence_list=None, **kw):
    """
508
      Create a filled order
509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525
    """
    portal = self.getPortal()
    order_module = portal.getDefaultModule(portal_type=self.order_portal_type)
    order = order_module.newContent(portal_type=self.order_portal_type)
    organisation = sequence.get('organisation')
    supply_chain = sequence.get('supply_chain')
    order.edit(
      start_date = self.datetime + 10,
      stop_date = self.datetime + 20,
      destination_value=organisation,
      destination_section_value=organisation,
      specialise_value=supply_chain
    )
    sequence.edit(order=order)

  def stepCreateOrderLine(self, sequence=None, sequence_list=None, **kw):
    """
526
      Create a filled order line
527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551
    """
    order = sequence.get('order')
    order_line = order.newContent(portal_type=self.order_line_portal_type)
    resource = sequence.get('resource')
    transformation = sequence.get('transformation')
    order_line.edit(
      resource_value=resource,
      specialise_value=transformation,
      quantity=5
    )
    sequence.edit(order_line=order_line)

  def stepCreateOrderLineWithoutTransformation(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)
    resource = sequence.get('resource')
    order_line.edit(
      resource_value=resource,
      quantity=5
    )
    sequence.edit(order_line=order_line)

552 553 554 555 556
  def stepCheckVariationSimulation(self, sequence=None, sequence_list=None, **kw):
    # XXX: This check is not testing too much, beside for variation system
    #      used in production simulations.
    order = sequence.get('order')

Nicolas Dumazet's avatar
Nicolas Dumazet committed
557 558 559 560
    movement_list = order.getMovementList()
    self.assertNotEqual(len(movement_list), 0)

    for order_movement in movement_list:
561 562 563
      size = order_movement.getSize()
      colour = order_movement.getColour()

564 565 566
      self.assertNotEqual(size, None)
      self.assertNotEqual(colour, None)

567 568 569 570
      want_produced_quantity = self.order_line_colour_size_quantity_dict[colour][size]
      want_consume_quantity = self.colour_size_quantity_dict[colour][size]
      want_consume_for_production = want_produced_quantity * want_consume_quantity
      
571
      order_simulation_movement = order_movement.getDeliveryRelatedValue(\
572
          portal_type='Simulation Movement')
573
      produced_movement = order_simulation_movement.contentValues()[0].contentValues()[0]
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 604 605

      self.assertEquals(
        want_produced_quantity,
        produced_movement.getQuantity()
      )

      transformation_rule = produced_movement.contentValues()[0]

      consumption_movement = [q for q in transformation_rule.contentValues() \
          if q.getId().startswith('cr')][0]
      production_delivery_movement = [q for q in transformation_rule.contentValues() \
          if q.getId().startswith('pr')][0]

      self.assertEquals(
          want_consume_for_production,
          consumption_movement.getQuantity()
      )

      self.assertEquals(
        want_produced_quantity,
        production_delivery_movement.getQuantity()
      )

      transformation_sourcing_rule = consumption_movement.contentValues()[0]

      consume_delivery_movement = transformation_sourcing_rule.contentValues()[0]

      self.assertEquals(
        want_consume_for_production,
        consume_delivery_movement.getQuantity()
      )

606 607 608
  def stepCheckEfficiencySimulation(self, sequence=None, sequence_list=None, **kw):
    """Check that efficiency is applied where is it needed"""

609
    # XXX: This check is not testing too much, beside for efficiency related quantity
610 611 612 613 614
    #      in just two places.
    order = sequence.get('order')

    applied_rule = order.getCausalityRelatedValue(portal_type = self.applied_rule_portal_type)

615
    order_simulation_movement_list = applied_rule.contentValues()
616 617 618 619

    # XXX: hardcode
    self.assertEquals(
        1,
620
        len(order_simulation_movement_list)
621 622
    )

623 624 625
    order_simulation_movement = order_simulation_movement_list[0]
    production_applied_rule = order_simulation_movement.contentValues()[0]
    production_movement_list = production_applied_rule.contentValues()
626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647
    production_movement = production_movement_list[0]

    transformation_applied_rule = production_movement.contentValues()[0]

    consumed_movement = [q for q in transformation_applied_rule.contentValues() \
        if q.getId().startswith('cr')][0]

    self.assertEquals(
        consumed_movement.getQuantity(),
        self.quantity_after_efficiency_calculation
    )

    transformation_sourcing_rule = consumed_movement.contentValues()[0]

    consumption_delivery_movement = [q for q in transformation_sourcing_rule.contentValues() \
        if q.getId().startswith('ts')][0]
    
    self.assertEquals(
        consumption_delivery_movement.getQuantity(),
        self.quantity_after_efficiency_calculation
    )

648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688
  def stepCheckOrderLineTransformationIsSet(self, sequence=None, sequence_list=None, **kw):
    order_line = sequence.get('order_line')
    transformation = sequence.get('transformation')

    self.assertNotEquals(None, transformation)

    self.assertEquals(order_line.getSpecialiseValue(), transformation)

  def stepCheckOrderLineTransformationIsNotSet(self, sequence=None, sequence_list=None, **kw):
    order_line = sequence.get('order_line')

    self.assertEquals(order_line.getSpecialiseValue(), None)

  def stepRemoveResourceFromOrderLine(self, sequence=None, sequence_list=None, **kw):
    order_line = sequence.get('order_line')

    order_line.edit(
        resource = None
    )

  def stepCheckOrderSimulation(self, sequence=None, sequence_list=None, **kw):
    """
      Test if simulation is matching order
    """
    order = sequence.get('order')
    related_applied_rule_list = order.getCausalityRelatedValueList( \
                                   portal_type=self.applied_rule_portal_type)
    no_applied_rule_state = ('draft', 'auto_planned')
    order_state = order.getSimulationState()
    if order_state in no_applied_rule_state:
      self.assertEquals(0, len(related_applied_rule_list))
    else:
      self.assertEquals(1, len(related_applied_rule_list))
      applied_rule = related_applied_rule_list[0].getObject()
      sequence.edit(applied_rule=applied_rule)
      self.failUnless(applied_rule is not None)
      self.failUnless(order_state, \
                      applied_rule.getLastExpandSimulationState())
      # Test if applied rule has a specialise value with default_order_rule
      portal_rules = getToolByName(order, 'portal_rules')
      # XXX hardcoded value
689 690
      self.assertEquals('default_production_order_rule', \
                        applied_rule.getSpecialiseReference())
691 692 693 694 695 696 697 698 699 700 701 702 703 704
      
      simulation_movement_list = applied_rule.objectValues()
      sequence.edit(simulation_movement_list=simulation_movement_list)

  def checkObjectAttributes(self, object, attribute_list):
    LOG('checkObjectAttributes object.getPath',0,object.getPath())
    for value, attribute in attribute_list:
      try:
        self.assertEquals(value,
                          getattr(object, attribute)())
      except AssertionError:
        LOG('Raise Assertion error',0,'')
        LOG('object.getQuantity()',0,object.getQuantity())
        LOG('object.__dict__',0,object.__dict__)
705
        LOG('object.getDeliveryValue().getQuantity()',0,object.getDeliveryValue().getQuantity())
706 707 708 709 710 711 712 713 714 715 716 717 718 719
        raise AssertionError, "Attribute: %s, Value: %s, Result: %s" %\
                    (attribute, value, getattr(object, attribute)())

  def stepCheckProductionSimulation(self, sequence=None, sequence_list=None,
                                    **kw):
    """
      Hardcoded check
    """
    self.stepCheckOrderSimulation(sequence=sequence,
                                  sequence_list=sequence_list, **kw)
    # Test simulation movement generated related to order line
    simulation_movement_list = sequence.get('simulation_movement_list')
    self.assertEquals(1, len(simulation_movement_list))
    order_line = sequence.get('order_line')
720
    related_simulation_movement_list = order_line.getDeliveryRelatedValueList()
721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
    self.assertEquals(1, len(related_simulation_movement_list))
    related_simulation_movement = related_simulation_movement_list[0]
    self.assertEquals(related_simulation_movement,
                      simulation_movement_list[0])
    production_organisation1 = sequence.get('production_organisation1')
    # XXX FIXME test date
    self.checkObjectAttributes(
           related_simulation_movement, (
             (order_line.getQuantity(), 'getQuantity'),
             (order_line.getResourceValue(), 'getResourceValue'),
             (order_line.getVariationCategoryList(), 
              'getVariationCategoryList'),
             (order_line.getDestinationValue(), 'getDestinationValue'),
             (order_line.getDestinationSectionValue(), 
              'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    # Test next applied rule
    applied_rule_list = related_simulation_movement.objectValues()
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
744 745 746 747 748 749 750 751 752 753 754
    self.assertEquals('default_delivering_rule', \
                      applied_rule.getSpecialiseReference())
    # Test next applied rule
    simulation_movement_list = applied_rule.objectValues()
    self.assertEquals(1, len(simulation_movement_list))
    simulation_movement = simulation_movement_list[0]
    applied_rule_list = simulation_movement.objectValues()
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
755 756
    self.assertEquals('default_transformation_rule', \
                      applied_rule.getSpecialiseReference())
757 758 759 760 761
    # Test deeper simulation 
    simulation_movement_list = applied_rule.objectValues()
    self.assertEquals(2, len(simulation_movement_list))
    # Test consumed movement
    transformation = sequence.get('transformation')
762 763
    consumed_movement_id = 'cr_%s_1_%s' % (transformation.getId(),
                                           applied_rule.getParentId())
764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807
    consumed_movement = applied_rule[consumed_movement_id]
    operation_resource = consumed_movement.portal_categories.resolveCategory(
                                              'operation/operation1')
    # FIXME
    self.checkObjectAttributes(
           consumed_movement, (
             (10, 'getQuantity'),
             (operation_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    # Test produced resource
    produced_movement = applied_rule.pr
    resource = sequence.get('resource')
    production_organisation1 = sequence.get('production_organisation1')
    self.checkObjectAttributes(
           produced_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
             (production_organisation1, 'getDestinationSectionValue'),
             (None, 'getSourceValue'),
             (None, 'getSourceSectionValue')))

  def stepCreateSupplyOrganisation1(self, sequence=None, sequence_list=None, 
                                        **kw):
    """
      Create a organisation for supply
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                title='supply_organisation1', **kw)

  def stepCreateSourcingSC(self, sequence=None, sequence_list=None, 
                             **kw):
    """
      Create a empty organisation
    """
    # Create supply chain
    self.stepCreateProductionSC(sequence=sequence, sequence_list=sequence_list,
                                **kw)
    supply_chain = sequence.get('supply_chain')
808 809 810
    supply_chain.edit(
      title = 'Supply Chain Sourcing',
    )
811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844
    # Create supply node
    supply_organisation  = sequence.get('supply_organisation1')
    supply_node = supply_chain.newContent(
                         portal_type=self.supply_node_portal_type)
    supply_node.edit(
      destination_value=supply_organisation
    )
    # Create sourcing link
    supply_link = supply_chain.newContent(
                         portal_type=self.supply_link_portal_type)
    production_node1 = sequence.get('production_node1')
    production_organisation1 = sequence.get('production_organisation1')
    supply_link.edit(
      source_value=supply_node,
      source_section_value=supply_organisation,
      destination_value=production_node1,
      destination_section_value=production_organisation1,
      min_delay=5,
      max_delay=6,
      deliverable=0,
      industrial_phase_list=["supply_phase1"]
    )

  def stepCheckSourcingSimulation(self, sequence=None, sequence_list=None,
                                  **kw):
    """
      Hardcoded check
    """
    self.stepCheckOrderSimulation(sequence=sequence,
                                  sequence_list=sequence_list, **kw)
    # Test simulation movement generated related to order line
    simulation_movement_list = sequence.get('simulation_movement_list')
    self.assertEquals(1, len(simulation_movement_list))
    order_line = sequence.get('order_line')
845
    related_simulation_movement_list = order_line.getDeliveryRelatedValueList()
846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863
    self.assertEquals(1, len(related_simulation_movement_list))
    related_simulation_movement = related_simulation_movement_list[0]
    self.assertEquals(related_simulation_movement,
                      simulation_movement_list[0])
    production_organisation1 = sequence.get('production_organisation1')
    # XXX FIXME test date
    self.checkObjectAttributes(
           related_simulation_movement, (
             (order_line.getQuantity(), 'getQuantity'),
             (order_line.getResourceValue(), 'getResourceValue'),
             (order_line.getVariationCategoryList(), 
              'getVariationCategoryList'),
             (order_line.getDestinationValue(), 'getDestinationValue'),
             (order_line.getDestinationSectionValue(), 
              'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    # Test next applied rule
864
    applied_rule_list = related_simulation_movement.objectValues()[0].objectValues()[0].objectValues()
865 866 867 868
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
869 870
    self.assertEquals('default_transformation_rule', \
                      applied_rule.getSpecialiseReference())
871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927
    # Test deeper simulation 
    simulation_movement_list = list(applied_rule.objectValues())
    # FIXME
    self.assertEquals(3, len(simulation_movement_list))
    # Test produced resource
    produced_movement = applied_rule.pr
    resource = sequence.get('resource')
    production_organisation1 = sequence.get('production_organisation1')
    self.checkObjectAttributes(
           produced_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
             (production_organisation1, 'getDestinationSectionValue'),
             (None, 'getSourceValue'),
             (None, 'getSourceSectionValue')))
    self.assertEquals(0, len(produced_movement.objectValues()))

    simulation_movement_list.remove(produced_movement)
    # All code before is a stupid copy (except movement count)
    # Test consumed movement
    operation_resource = resource.portal_categories.resolveCategory(
                                              'operation/operation1')
    component_resource = sequence.get('component1')
#     for consumed_movement in (applied_rule.cr_1, applied_rule.cr_2):
    for consumed_movement in simulation_movement_list:
      if consumed_movement.getResourceValue() == operation_resource:
        operation_movement = consumed_movement
      else:
        component_movement = consumed_movement
    # Check operation movement
    self.checkObjectAttributes(
           operation_movement, (
             (10, 'getQuantity'),
             (operation_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    self.assertEquals(0, len(operation_movement.objectValues()))
    # Check component movement
    self.checkObjectAttributes(
           component_movement, (
             (30, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    self.assertEquals(1, len(component_movement.objectValues()))
    # Test supply applied rule
    applied_rule = component_movement.objectValues()[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
928 929
    self.assertEquals('default_transformation_sourcing_rule', \
                      applied_rule.getSpecialiseReference())
930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
    # Test supply movement
    simulation_movement_list = applied_rule.objectValues()
    # FIXME
    self.assertEquals(1, len(simulation_movement_list))
    # Test supply resource
    supply_movement = applied_rule.ts
    supply_organisation1 = sequence.get('supply_organisation1')
    self.checkObjectAttributes(
           supply_movement, (
             (30, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
             (production_organisation1, 'getDestinationSectionValue'),
             (supply_organisation1, 'getSourceValue'),
             (supply_organisation1, 'getSourceSectionValue')))
    self.assertEquals(0, len(supply_movement.objectValues()))
    
    sequence.edit(
      produced_movement = produced_movement,
      operation_movement = operation_movement,
      component_movement = component_movement,
      supply_movement = supply_movement,
953
      produced_delivery_movement = related_simulation_movement.objectValues()[0].objectValues()[0],
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
    )

  def stepCreateProductionOrganisation2(self, sequence=None, 
                                        sequence_list=None, **kw):
    """
      Create a organisation for supply
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                title='production_organisation2', **kw)

  def stepCreateSupplyOrganisation2(self, sequence=None, sequence_list=None, 
                                        **kw):
    """
      Create a organisation for supply
    """
    self.stepCreateOrganisation(sequence=sequence, sequence_list=sequence_list,
                                title='supply_organisation2', **kw)

  def stepCreateTwoPhasesSC(self, sequence=None, sequence_list=None, 
                             **kw):
    """
      Create a empty organisation
    """
    # Create supply chain
    self.stepCreateSourcingSC(sequence=sequence, sequence_list=sequence_list,
                              **kw)
    supply_chain = sequence.get('supply_chain')
981 982 983
    supply_chain.edit(
      title = 'Supply Chain Two Phases',
    )
984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045
    # Create production node
    production_organisation2  = sequence.get('production_organisation2')
    production_node2 = supply_chain.newContent(
                         portal_type=self.supply_node_portal_type)
    production_node2.edit(
      destination_value=production_organisation2
    )
    sequence.edit(production_node2=production_node2)
    # Create production link
    production_link2 = supply_chain.newContent(
                         portal_type=self.supply_link_portal_type)
    production_link2.edit(
      destination_value=production_node2,
      min_delay=5,
      max_delay=6,
      deliverable=0,
      industrial_phase_list=["phase2"]
    )
    # Link production_node2 and production_node1
    supply_link = supply_chain.newContent(
                         portal_type=self.supply_link_portal_type)
    production_node1 = sequence.get('production_node1')
    supply_link.edit(
      source_value=production_node2,
      destination_value=production_node1,
      min_delay=5,
      max_delay=6,
      deliverable=0,
      industrial_phase_list=[]
    )
    # Create supply node
    supply_organisation2  = sequence.get('supply_organisation2')
    supply_node2 = supply_chain.newContent(
                         portal_type=self.supply_node_portal_type)
    supply_node2.edit(
      destination_value=supply_organisation2
    )
    # Create sourcing link
    supply_link2 = supply_chain.newContent(
                         portal_type=self.supply_link_portal_type)
    supply_link2.edit(
      source_value=supply_node2,
      destination_value=production_node2,
      min_delay=5,
      max_delay=6,
      deliverable=0,
      industrial_phase_list=["supply_phase2"]
    )

  def stepCheckTwoPhasesSimulation(self, sequence=None, sequence_list=None,
                                   **kw):
    """
      Hardcoded check
    """
#     self.stepCheckSourcingSimulation(sequence=sequence,
#                                      sequence_list=sequence_list, **kw)
    self.stepCheckOrderSimulation(sequence=sequence,
                                  sequence_list=sequence_list, **kw)
    # Test simulation movement generated related to order line
    simulation_movement_list = sequence.get('simulation_movement_list')
    self.assertEquals(1, len(simulation_movement_list))
    order_line = sequence.get('order_line')
1046
    related_simulation_movement_list = order_line.getDeliveryRelatedValueList()
1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069
    self.assertEquals(1, len(related_simulation_movement_list))
    related_simulation_movement = related_simulation_movement_list[0]
    self.assertEquals(related_simulation_movement,
                      simulation_movement_list[0])
    production_organisation1 = sequence.get('production_organisation1')
    # XXX FIXME test date
    self.checkObjectAttributes(
           related_simulation_movement, (
             (order_line.getQuantity(), 'getQuantity'),
             (order_line.getResourceValue(), 'getResourceValue'),
             (order_line.getVariationCategoryList(), 
              'getVariationCategoryList'),
             (order_line.getDestinationValue(), 'getDestinationValue'),
             (order_line.getDestinationSectionValue(), 
              'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    # Test next applied rule
    applied_rule_list = related_simulation_movement.objectValues()
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080
    self.assertEquals('default_delivering_rule', \
                      applied_rule.getSpecialiseReference())
    # Test next applied rule
    simulation_movement_list = applied_rule.objectValues()
    self.assertEquals(1, len(simulation_movement_list))
    simulation_movement = simulation_movement_list[0]
    applied_rule_list = simulation_movement.objectValues()
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1081 1082
    self.assertEquals('default_transformation_rule', \
                      applied_rule.getSpecialiseReference())
1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142
    # Test deeper simulation 
    simulation_movement_list = list(applied_rule.objectValues())
    # FIXME
    self.assertEquals(4, len(simulation_movement_list))
    # Test produced resource
    produced_movement = applied_rule.pr
    resource = sequence.get('resource')
    production_organisation1 = sequence.get('production_organisation1')
    self.checkObjectAttributes(
           produced_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
             (production_organisation1, 'getDestinationSectionValue'),
             (None, 'getSourceValue'),
             (None, 'getSourceSectionValue')))
    self.assertEquals(0, len(produced_movement.objectValues()))

    # Get modified resource (test later)
    modified_movement = applied_rule.mr_1
    simulation_movement_list.remove(produced_movement)
    simulation_movement_list.remove(modified_movement)
    # All code before is a stupid copy (except movement count)
    # Test consumed movement
    operation_resource = resource.portal_categories.resolveCategory(
                                              'operation/operation1')
    component_resource = sequence.get('component1')
#     for consumed_movement in (applied_rule.cr_1, applied_rule.cr_2):
    for consumed_movement in simulation_movement_list:
      if consumed_movement.getResourceValue() == operation_resource:
        operation_movement = consumed_movement
      else:
        component_movement = consumed_movement
    # Check operation movement
    self.checkObjectAttributes(
           operation_movement, (
             (10, 'getQuantity'),
             (operation_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    self.assertEquals(0, len(operation_movement.objectValues()))
    # Check component movement
    self.checkObjectAttributes(
           component_movement, (
             (30, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue')))
    self.assertEquals(1, len(component_movement.objectValues()))
    # Test supply applied rule
    applied_rule = component_movement.objectValues()[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1143 1144
    self.assertEquals('default_transformation_sourcing_rule', \
                      applied_rule.getSpecialiseReference())
1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180
    # Test supply movement
    simulation_movement_list = applied_rule.objectValues()
    # FIXME
    self.assertEquals(1, len(simulation_movement_list))
    # Test supply resource
    supply_movement = applied_rule.ts
    supply_organisation1 = sequence.get('supply_organisation1')
    self.checkObjectAttributes(
           supply_movement, (
             (30, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
             (production_organisation1, 'getDestinationSectionValue'),
             (supply_organisation1, 'getSourceValue'),
             (supply_organisation1, 'getSourceSectionValue')))
    self.assertEquals(0, len(supply_movement.objectValues()))

    # Test modified movement
    resource = sequence.get('resource')
    production_organisation1 = sequence.get('production_organisation1')
    self.checkObjectAttributes(
           modified_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             (['industrial_phase/phase2'], 'getVariationCategoryList'),
             (production_organisation1, 'getSourceValue'),
             (production_organisation1, 'getSourceSectionValue'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue')))
    self.assertEquals(1, len(modified_movement.objectValues()))
    # Test next applied rule
    applied_rule_list = modified_movement.objectValues()
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1181 1182
    self.assertEquals('default_transformation_sourcing_rule', \
                      applied_rule.getSpecialiseReference())
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
    # Test deeper simulation 
    simulation_movement_list = list(applied_rule.objectValues())
    self.assertEquals(1, len(simulation_movement_list))
    # Test produced resource
    sourcing_movement = simulation_movement_list[0]
    resource = sequence.get('resource')
    production_organisation1 = sequence.get('production_organisation1')
    production_organisation2 = sequence.get('production_organisation2')
    self.checkObjectAttributes(
           sourcing_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             (['industrial_phase/phase2'], 'getVariationCategoryList'),
             (production_organisation1, 'getDestinationValue'),
# XXX             (production_organisation1, 'getDestinationSectionValue'),
             (production_organisation2, 'getSourceValue'),
# XXX             (production_organisation2, 'getSourceSectionValue')))
           ))
    self.assertEquals(1, len(sourcing_movement.objectValues()))
    # Test next applied rule
    applied_rule_list = sourcing_movement.objectValues()
    self.assertEquals(1, len(applied_rule_list))
    applied_rule = applied_rule_list[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1208 1209
    self.assertEquals('default_transformation_rule', \
                      applied_rule.getSpecialiseReference())
1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267
    # Test deeper simulation 
    simulation_movement_list = list(applied_rule.objectValues())
    # FIXME
    self.assertEquals(3, len(simulation_movement_list))
    # Test produced resource
    produced_movement = applied_rule.pr
    resource = sequence.get('resource')
    production_organisation2 = sequence.get('production_organisation2')
    self.checkObjectAttributes(
           produced_movement, (
             (5, 'getQuantity'),
             (resource, 'getResourceValue'),
             (['industrial_phase/phase2'], 'getVariationCategoryList'),
             (production_organisation2, 'getDestinationValue'),
# XXX             (production_organisation2, 'getDestinationSectionValue'),
             (None, 'getSourceValue'),
             (None, 'getSourceSectionValue')))
    self.assertEquals(0, len(produced_movement.objectValues()))

    simulation_movement_list.remove(produced_movement)
    # All code before is a stupid copy (except movement count)
    # Test consumed movement
    operation_resource = resource.portal_categories.resolveCategory(
                                              'operation/operation2')
    component_resource = sequence.get('component2')
    for consumed_movement in simulation_movement_list:
      if consumed_movement.getResourceValue() == operation_resource:
        operation_movement = consumed_movement
      else:
        component_movement = consumed_movement
    # Check operation movement
    self.checkObjectAttributes(
           operation_movement, (
             (15, 'getQuantity'),
             (operation_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation2, 'getSourceValue'),
# XXX              (production_organisation2, 'getSourceSectionValue')))
           ))
    self.assertEquals(0, len(operation_movement.objectValues()))
    # Check component movement
    self.checkObjectAttributes(
           component_movement, (
             (35, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (None, 'getDestinationValue'),
             (None, 'getDestinationSectionValue'),
             (production_organisation2, 'getSourceValue'),
# XXX              (production_organisation2, 'getSourceSectionValue')))
           ))
    self.assertEquals(1, len(component_movement.objectValues()))
    # Test supply applied rule
    applied_rule = component_movement.objectValues()[0]
    self.assertEquals("Applied Rule", applied_rule.getPortalType())
    portal_rules = getToolByName(applied_rule, 'portal_rules')
1268 1269
    self.assertEquals('default_transformation_sourcing_rule', \
                      applied_rule.getSpecialiseReference())
1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 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 1444 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
    # Test supply movement
    simulation_movement_list = applied_rule.objectValues()
    # FIXME
    self.assertEquals(1, len(simulation_movement_list))
    # Test supply resource
    supply_movement = applied_rule.ts
    supply_organisation2  = sequence.get('supply_organisation2')
    self.checkObjectAttributes(
           supply_movement, (
             (35, 'getQuantity'),
             (component_resource, 'getResourceValue'),
             ([], 'getVariationCategoryList'),
             (production_organisation2, 'getDestinationValue'),
# XXX              (production_organisation2, 'getDestinationSectionValue'),
             (supply_organisation2, 'getSourceValue'),
# XXX              (supply_organisation2, 'getSourceSectionValue')))
           ))
    self.assertEquals(0, len(supply_movement.objectValues()))

  SOURCING_ORDER_SEQUENCE = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateSupplyOrganisation1 \
                      CreateSourcingSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckSourcingSimulation \
                      ConfirmOrder \
                      Tic \
                      CheckSourcingSimulation \
                      '
    
class TestProductionOrder(TestProductionOrderMixin, ERP5TypeTestCase):
  """
    Test business template erp5_mrp
  """
  run_all_test = 1

  def getTitle(self):
    return "Production Order"

  def test_01_testProductionSimulationExpand(self, quiet=0, run=run_all_test):
    """
      Test generation and update of order applied rule.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateProductionSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckProductionSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_02_testSourcingSimulationExpand(self, quiet=0, 
                                                     run=run_all_test):
    """
      Test generation and update of order applied rule.
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateSupplyOrganisation1 \
                      CreateSourcingSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckSourcingSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_03_testIndustrialPhase(self, quiet=0, run=run_all_test):
    """
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateProductionOrganisation2 \
                      CreateSupplyOrganisation1 \
                      CreateSupplyOrganisation2 \
                      CreateTwoPhasesSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateComponent2 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckTwoPhasesSimulation \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_04_testProductionSimulationBuild(self, quiet=0, run=run_all_test):
    """
    Test delivery building.
    XXX Test method still required
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateProductionSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      ConfirmOrder \
                      Tic \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def test_05_testSourcingSimulationBuild(self, quiet=0, 
                                          run=run_all_test):
    """
    Test delivery building.
    XXX Test method still required
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_list.addSequenceString(self.SOURCING_ORDER_SEQUENCE)
    sequence_list.play(self)

  def test_06_testIndustrialPhase(self, quiet=0, run=run_all_test):
    """
    Test delivery building.
    XXX Test method still required
    """
    if not run: return
    sequence_list = SequenceList()
    # Test when order is 
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateProductionOrganisation2 \
                      CreateSupplyOrganisation1 \
                      CreateSupplyOrganisation2 \
                      CreateTwoPhasesSC \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateComponent2 \
                      CreateTransformation \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      Tic \
                      OrderOrder \
                      Tic \
                      ConfirmOrder \
                      Tic \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def stepCopyPasteSupplyChain(self, sequence=None, sequence_list=None, 
                               **kw):
    """
    Copy/Paste the supply chain
    """
    portal = self.getPortal()
    supply_chain_module = portal.getDefaultModule( \
                                   portal_type=self.supply_chain_portal_type)
    supply_chain = sequence.get('supply_chain')

    cb_data = supply_chain_module.manage_copyObjects([supply_chain.getId()])
    copied, = supply_chain_module.manage_pasteObjects(cb_data)
    pasted_sc = supply_chain_module[copied['new_id']]
    sequence.edit(pasted_sc=pasted_sc)

  def stepCheckPastedSupplyChain(self, sequence=None, sequence_list=None, 
                                 **kw):
    """
    Check pasted supply chain
    """
    pasted_sc = sequence.get('pasted_sc')
    pasted_supply_node = pasted_sc.contentValues(portal_type='Supply Node')[0]
    pasted_supply_link = pasted_sc.contentValues(portal_type='Supply Link')[0]
    self.assertEquals(pasted_supply_node.getRelativeUrl(),
                      pasted_supply_link.getDestination())

  def test_07_testTransformationInteractionProductionOrderLine(self, quiet=0, run=run_all_test):
    """
    Test for setting/resetting Transformation on Production Order Line
    """
    if not run: return

    bootstrap_sequence_string = '\
                      ClearActivities \
                      CreateNotVariatedResource \
                      CreateOrder \
                      '
    sequence_list = SequenceList()

    # normal case
    sequence_string = bootstrap_sequence_string + '\
                      CreateTransformation \
                      Tic \
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    # no transformation
    sequence_string = bootstrap_sequence_string + '\
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsNotSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    # transformation set, then unset
    sequence_string = bootstrap_sequence_string + '\
                      CreateTransformation \
                      Tic \
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsSet \
                      RemoveResourceFromOrderLine \
                      Tic \
                      CheckOrderLineTransformationIsNotSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    # more than one transformation
    sequence_string = bootstrap_sequence_string + '\
                      CreateTransformation \
                      CreateTransformation \
                      Tic \
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsNotSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    # case of invalidated Transformation
    sequence_string = bootstrap_sequence_string + '\
                      CreateTransformation \
                      Tic \
                      ValidateTransformation \
                      InvalidateTransformation \
                      Tic \
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsNotSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    # case of invalidated Transformation and other
    sequence_string = bootstrap_sequence_string + '\
                      CreateTransformation \
                      Tic \
                      ValidateTransformation \
                      InvalidateTransformation \
                      Tic \
                      CreateTransformation \
                      Tic \
                      CreateOrderLineWithoutTransformation \
                      Tic \
                      CheckOrderLineTransformationIsSet \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)
    
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 1614 1615 1616 1617 1618 1619 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
  def test_08_testTransformationWithEfficiency(self, quiet=0, run=run_all_test):
    """
    Test, that efficiency from transformation applies correctly
    """
    if not run: return

    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateSupplyOrganisation1 \
                      CreateSourcingSC \
                      Tic \
                      CreateNotVariatedResource \
                      CreateComponent1 \
                      CreateEmptyTransformation \
                      FillTransformationWithResource \
                      Tic \
                      CreateTransformationTransformedResource \
                      FillTransformationTransformedResourceWithComponent1 \
                      SetTransformationTransformedResourceQuantity \
                      SetTransformationTransformedResourceEfficiency \
                      SetTransformationTransformedResourceIndustrialPhaseList \
                      Tic \
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
                      SetOrderLineQuantity \
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckEfficiencySimulation \
                      '
    sequence_list = SequenceList()
    sequence_list.addSequenceString(sequence_string)

    # case - we need Q:10.0, efficiency is 80% (we need more), producing 1.0
    self.transformation_transformed_resource_quantity = 10.0
    self.transformation_transformed_resource_efficiency = 0.8 # 80%
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]

    self.production_order_line_quantity = 1.0
    self.quantity_after_efficiency_calculation = 12.5 # (1.0 * 10.0) / 0.8

    sequence_list.play(self)

    # case - we need Q:10.0, efficiency is None (normal, nothing set), producing 1.0
    self.transformation_transformed_resource_quantity = 10.0
    self.transformation_transformed_resource_efficiency = None
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]

    self.production_order_line_quantity = 1.0
    self.quantity_after_efficiency_calculation = 10.0 # (1.0 * 10.0) / 1.0

    sequence_list.play(self)

    # case - we need Q:10.0, efficiency is 100% (normal), producing 1.0
    self.transformation_transformed_resource_quantity = 10.0
    self.transformation_transformed_resource_efficiency = 1.0
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]

    self.production_order_line_quantity = 1.0
    self.quantity_after_efficiency_calculation = 10.0 # (1.0 * 10.0) / 1.0

    sequence_list.play(self)

    # case - we need Q:10.0, efficiency is 125% (miracle?), producing 1.0
    self.transformation_transformed_resource_quantity = 10.0
    self.transformation_transformed_resource_efficiency = 1.25
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]

    self.production_order_line_quantity = 1.0
    self.quantity_after_efficiency_calculation = 8.0 # (1.0 * 10.0) / 1.25

    sequence_list.play(self)

    # case - we need Q:10.0, efficiency is -80% (nonsense?), producing 1.0
    self.transformation_transformed_resource_quantity = 10.0
    self.transformation_transformed_resource_efficiency = -0.8
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]

    self.production_order_line_quantity = 1.0
    self.quantity_after_efficiency_calculation = -12.5 # (1.0 * 10.0) / -0.8

    sequence_list.play(self)

1664 1665 1666 1667
  def test_09_testTransformationWithVariation(self, quiet=0, run=run_all_test):
    """
    Test, that variation from transformation works correctly on order

1668
    Note: Read below variables to know, what and how was defined
1669 1670 1671 1672 1673 1674 1675 1676
    """
    if not run: return

    self.transformation_transformed_resource_quantity = 0.0
    self.transformation_transformed_resource_industrial_phase_list = ['supply_phase1',]
    self.production_order_line_quantity = 0.0
    self.variation_category_list = ['colour','size']

1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698
    self.colour_size_quantity_dict = {
      'green' : {
        'Man' : 1.0,
        'Woman' : 2.0
      },
      'blue' : {
        'Man' : 3.0,
        'Woman' : 4.0
      },
    }

    self.colour_size_variation_dict = {
      'green' : {
        'Man' : ('colour/green','size/Man'),
        'Woman' : ('colour/green','size/Woman')
      },
      'blue' : {
        'Man' : ('colour/blue','size/Man'),
        'Woman' : ('colour/blue','size/Woman')
      },
    }

1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716
    self.order_line_variation_category_list = [
      'size/Man',
      'size/Woman',
      'colour/green',
      'colour/blue',
    ]

    self.order_line_colour_size_quantity_dict = {
      'green' : {
        'Man' : 9.0,
        'Woman' : 8.0
      },
      'blue' : {
        'Man' : 7.0,
        'Woman' : 6.0
      },
    }

1717 1718 1719 1720 1721 1722 1723
    sequence_string = '\
                      ClearActivities \
                      CreateProductionOrganisation1 \
                      CreateSupplyOrganisation1 \
                      CreateSourcingSC \
                      Tic \
                      CreateColourSizeVariatedResource \
1724
                      CreateColourSizeVariatedComponent1 \
1725 1726 1727 1728 1729 1730 1731 1732 1733 1734
                      Tic \
                      CreateEmptyTransformation \
                      FillTransformationWithResource \
                      SetTransformationVariation \
                      Tic \
                      CreateTransformationTransformedResource \
                      FillTransformationTransformedResourceWithComponent1 \
                      SetTransformationTransformedResourceVariation \
                      SetTransformationTransformedResourceIndustrialPhaseList \
                      Tic \
1735 1736 1737
                      SetTransformationTransformedResourceQuantityMatrix \
                      SetTransformationTransformedResourceVariationMatrix \
                      Tic \
1738 1739 1740
                      CreateOrganisation \
                      CreateOrder \
                      CreateOrderLine \
1741 1742
                      SetOrderLineVariationCategories \
                      SetOrderLineQuantityMatrix \
1743 1744 1745 1746
                      Tic \
                      OrderOrder \
                      Tic \
                      CheckVariationSimulation \
1747 1748
                      ConfirmOrder \
                      Tic \
1749 1750 1751 1752 1753 1754
                      '
    sequence_list = SequenceList()
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self)

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 1854 1855 1856
  def test_50_testCopyPaste(self, quiet=0, run=run_all_test):
    """
    Check that relation are changed when doing a copy/paste,
    on supply chain
    """
    if not run: return
    sequence_list = SequenceList()
    sequence_string = '\
            ClearActivities \
            CreateProductionOrganisation1 \
            CreateProductionSC \
            CopyPasteSupplyChain \
            Tic \
            CheckPastedSupplyChain \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

  def stepCreateEmptySC(self, sequence=None, sequence_list=None, **kw):
    """
      Create a empty Supply Chain
    """
    portal = self.getPortal()
    supply_chain_module = portal.getDefaultModule( \
                                   portal_type=self.supply_chain_portal_type)
    supply_chain = supply_chain_module.newContent( \
                                   portal_type=self.supply_chain_portal_type)
    supply_chain.edit(
      title = "Supply Chain Empty",
    )
    sequence.edit(empty_supply_chain=supply_chain)

  def stepCutPasteSupplyNodeInAnotherContainer(self, sequence=None, 
                                               sequence_list=None, **kw):
    """
    Cut/Paste a supply node in another container
    """
    supply_chain = sequence.get('supply_chain')
    empty_supply_chain = sequence.get('empty_supply_chain')

    supply_node = supply_chain.contentValues(portal_type='Supply Node')[0]
    cb_data = supply_chain.manage_cutObjects([supply_node.getId()])
    copied, = empty_supply_chain.manage_pasteObjects(cb_data)

  def stepCheckPastedSupplyNode(self, sequence=None, sequence_list=None, 
                                 **kw):
    """
    Check pasted supply node
    """
    supply_chain = sequence.get('supply_chain')
    empty_supply_chain = sequence.get('empty_supply_chain')

    supply_node = empty_supply_chain.contentValues(portal_type='Supply Node')[0]
    supply_link = supply_chain.contentValues(portal_type='Supply Link')[0]
    self.assertEquals(supply_node.getRelativeUrl(),
                      supply_link.getDestination())

  def test_51_testCutPasteInAnotherContainer(self, quiet=0, run=run_all_test):
    """
    Check that relations are changed when doing a copy/paste,
    on a supply chain.

    The point in this test is that internal relations should be updated
    when copying an object. Suppose that a document D1 contains sub-objects
    S1_1 and S1_2, and S1_1 is related to S1_2. When copying D1 to D2,
    S2_1 and S2_2 are also copied from S1_1 and S1_2. Now S2_1 should be
    related to S2_2, instead of S1_2.

    Good:

    D1 -+- S1_1          D1 -+- S1_1   D2 -+- S2_1
        |    |      =>       |    |        |    |
        |    v               |    v        |    v
        +- S1_2              +- S1_2       +- S2_2

    Bad:

    D1 -+- S1_1          D1 -+- S1_1   D2 -+- S2_1
        |    |      =>       |    |      __|_/    
        |    v               |    v     /  |     
        +- S1_2              +- S1_2<--/   +- S2_2

    """
    if not run: return
    sequence_list = SequenceList()
    sequence_string = '\
            ClearActivities \
            CreateProductionOrganisation1 \
            CreateProductionSC \
            CreateEmptySC \
            Tic \
            CutPasteSupplyNodeInAnotherContainer \
            Tic \
            CheckPastedSupplyNode \
                      '
    sequence_list.addSequenceString(sequence_string)
    sequence_list.play(self)

def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestProductionOrder))
  return suite