testPackingList.py 35.9 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
##############################################################################
#
# Copyright (c) 2004, 2005 Nexedi SARL and Contributors. All Rights Reserved.
#          Sebastien Robin <seb@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsability of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# garantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

29
import unittest
Sebastien Robin's avatar
Sebastien Robin committed
30 31 32

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from zLOG import LOG
33
from Products.ERP5Type.tests.Sequence import SequenceList
34
from testOrder import TestOrderMixin
Sebastien Robin's avatar
Sebastien Robin committed
35

36
class TestPackingListMixin(TestOrderMixin):
Sebastien Robin's avatar
Sebastien Robin committed
37 38 39
  """
    Test business template erp5_trade 
  """
40
  packable_packing_list_portal_type_list = ['Sale Packing List']
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
  container_portal_type = 'Container'
  container_line_portal_type = 'Container Line'
  container_cell_portal_type = 'Container Cell'

  default_sequence = 'stepCreateOrganisation1 \
                      stepCreateOrganisation2 \
                      stepCreateOrganisation3 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
                      stepCheckPackingListIsNotDivergent '

63 64
  default_sequence_with_two_lines = '\
                      stepCreateOrganisation1 \
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86
                      stepCreateOrganisation2 \
                      stepCreateOrganisation3 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
                      stepCheckPackingListIsNotDivergent '

87 88
  variated_default_sequence = '\
                      stepCreateOrganisation1 \
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
                      stepCreateOrganisation2 \
                      stepCreateOrganisation3 \
                      stepCreateOrder \
                      stepSetOrderProfile \
                      stepCreateVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepSetOrderLineFullVCL \
                      stepCompleteOrderLineMatrix \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
                      stepCheckPackingListIsNotDivergent '
107

Sebastien Robin's avatar
Sebastien Robin committed
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124
  def getTitle(self):
    return "Packing List"

  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

125 126
  def stepCheckPackingListIsDivergent(self, sequence=None, sequence_list=None, 
                                      packing_list=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
127 128 129
    """
      Test if packing list is divergent
    """
130 131
    if packing_list is None:
      packing_list = sequence.get('packing_list')
132 133
    self.failIf('Site Error' in packing_list.view())
    self.assertTrue(packing_list.isDivergent())
134 135 136 137 138 139

  def stepCheckNewPackingListIsDivergent(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is divergent
    """
    packing_list = sequence.get('new_packing_list')
140
    self.failIf('Site Error' in packing_list.view())
141
    self.stepCheckPackingListIsDivergent(packing_list=packing_list,sequence=sequence)
Sebastien Robin's avatar
Sebastien Robin committed
142

143 144
  def stepCheckPackingListIsCalculating(self, sequence=None, sequence_list=None, **kw):
    """
145
      Test if packing list is calculating
146 147 148 149 150 151
    """
    packing_list = sequence.get('packing_list')
    self.assertEquals('calculating',packing_list.getCausalityState())

  def stepCheckPackingListIsSolved(self, sequence=None, sequence_list=None, **kw):
    """
152
      Test if packing list is solved
153 154 155 156 157 158 159 160 161
    """
    packing_list = sequence.get('packing_list')
    self.assertEquals('solved',packing_list.getCausalityState())

  def stepCheckPackingListIsDiverged(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is divergent
    """
    packing_list = sequence.get('packing_list')
162
    self.assertEquals('diverged', packing_list.getCausalityState())
163

Sebastien Robin's avatar
Sebastien Robin committed
164 165 166 167 168
  def stepCheckPackingListIsNotDivergent(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is not divergent
    """
    packing_list = sequence.get('packing_list')
169
    self.assertFalse(packing_list.isDivergent())
Sebastien Robin's avatar
Sebastien Robin committed
170

171 172 173 174 175 176 177 178 179 180 181
  def stepChangePackingListLineResource(self, sequence=None, 
                                        sequence_list=None, **kw):
    """
    Change the resource of the packing list.
    """
    packing_list = sequence.get('packing_list')
    resource = sequence.get('resource')
    for packing_list_line in packing_list.objectValues(
                             portal_type=self.packing_list_line_portal_type):
      packing_list_line.edit(resource_value=resource)

182 183
  def stepDecreasePackingListLineQuantity(self, sequence=None,
      sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
184
    """
185
    Set a decreased quantity on packing list lines
Sebastien Robin's avatar
Sebastien Robin committed
186 187
    """
    packing_list = sequence.get('packing_list')
188
    quantity = sequence.get('line_quantity',default=self.default_quantity)
189
    quantity = quantity - 1
190
    sequence.edit(line_quantity=quantity)
Sebastien Robin's avatar
Sebastien Robin committed
191
    for packing_list_line in packing_list.objectValues(
192
        portal_type=self.packing_list_line_portal_type):
193
      packing_list_line.edit(quantity=quantity)
194
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) - 1.0)
Sebastien Robin's avatar
Sebastien Robin committed
195

196 197
  def stepIncreasePackingListLineQuantity(self, sequence=None,
      sequence_list=None, **kw):
198
    """
199
    Set a increased quantity on packing list lines
200 201
    """
    packing_list = sequence.get('packing_list')
202 203 204
    quantity = sequence.get('line_quantity',default=self.default_quantity)
    quantity = quantity + 1
    sequence.edit(line_quantity=quantity)
205
    for packing_list_line in packing_list.objectValues(
206
        portal_type=self.packing_list_line_portal_type):
207 208
      packing_list_line.edit(quantity=quantity)
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) + 1.0)
209

Sebastien Robin's avatar
Sebastien Robin committed
210 211 212 213 214 215 216 217 218 219 220 221
  def stepSplitAndDeferPackingList(self, sequence=None, sequence_list=None, **kw):
    """
      Do the split and defer action
    """
    packing_list = sequence.get('packing_list')
    packing_list.portal_workflow.doActionFor(packing_list,'split_prevision_action',
                                             wf_id='packing_list_causality_workflow',
                                             start_date=self.datetime + 15,
                                             stop_date=self.datetime + 25)

  def stepCheckPackingListSplitted(self, sequence=None, sequence_list=None, **kw):
    """
222
      Test if packing list was splitted
Sebastien Robin's avatar
Sebastien Robin committed
223 224 225 226 227 228 229 230 231 232 233 234
    """
    order = sequence.get('order')
    packing_list_list = order.getCausalityRelatedValueList(
                               portal_type=self.packing_list_portal_type)
    self.assertEquals(2,len(packing_list_list))
    packing_list1 = None
    packing_list2 = None
    for packing_list in packing_list_list:
      if packing_list.getUid() == sequence.get('packing_list').getUid():
        packing_list1 = packing_list
      else:
        packing_list2 = packing_list
235
    sequence.edit(new_packing_list=packing_list2)
Sebastien Robin's avatar
Sebastien Robin committed
236 237 238 239 240 241 242
    for line in packing_list1.objectValues(
          portal_type= self.packing_list_line_portal_type):
      self.assertEquals(self.default_quantity-1,line.getQuantity())
    for line in packing_list2.objectValues(
          portal_type= self.packing_list_line_portal_type):
      self.assertEquals(1,line.getQuantity())

243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264
  def stepCheckPackingListSplittedTwoTimes(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is divergent
    """
    order = sequence.get('order')
    packing_list_list = order.getCausalityRelatedValueList(
                               portal_type=self.packing_list_portal_type)
    self.assertEquals(2,len(packing_list_list))
    packing_list1 = None
    packing_list2 = None
    for packing_list in packing_list_list:
      if packing_list.getUid() == sequence.get('packing_list').getUid():
        packing_list1 = packing_list
      else:
        packing_list2 = packing_list
    for line in packing_list1.objectValues(
          portal_type= self.packing_list_line_portal_type):
      self.assertEquals(self.default_quantity-2,line.getQuantity())
    for line in packing_list2.objectValues(
          portal_type= self.packing_list_line_portal_type):
      self.assertEquals(2,line.getQuantity())

265 266 267 268 269 270 271 272 273
  def stepCheckPackingListNotSplitted(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is divergent
    """
    order = sequence.get('order')
    packing_list_list = order.getCausalityRelatedValueList(
                               portal_type=self.packing_list_portal_type)
    self.assertEquals(1,len(packing_list_list))
    packing_list1 = sequence.get('packing_list')
274
    last_delta = sequence.get('last_delta', 0.0)
275 276
    for line in packing_list1.objectValues(
          portal_type= self.packing_list_line_portal_type):
277 278
      self.assertEquals(self.default_quantity + last_delta,
          line.getQuantity())
279 280 281 282
      simulation_list = line.getDeliveryRelatedValueList(
                            portal_type='Simulation Movement')
      self.assertEquals(len(simulation_list),1)
      simulation_movement = simulation_list[0]
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
      self.assertEquals(self.default_quantity + last_delta,
          simulation_movement.getCorrectedQuantity())

  def stepCheckPackingListNotSolved(self, sequence=None, sequence_list=None, **kw):
    """
      This step is specific to test_10 : the incorrectly used solver didn't
      solve anything.
    """
    order = sequence.get('order')
    packing_list_list = order.getCausalityRelatedValueList(
                               portal_type=self.packing_list_portal_type)
    self.assertEquals(1,len(packing_list_list))
    packing_list1 = sequence.get('packing_list')
    last_delta = sequence.get('last_delta', 0.0)
    for line in packing_list1.objectValues(
          portal_type= self.packing_list_line_portal_type):
      self.assertEquals(self.default_quantity + last_delta,
          line.getQuantity())
      simulation_list = line.getDeliveryRelatedValueList(
                            portal_type='Simulation Movement')
      self.assertEquals(len(simulation_list),1)
      simulation_movement = simulation_list[0]

      # Here we don't add last_delta, as the solver didn't do its work.
      self.assertEquals(self.default_quantity,
          simulation_movement.getCorrectedQuantity())
309

310 311
  def stepChangePackingListDestination(self, sequence=None, 
                                       sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
312 313 314 315 316
    """
      Test if packing list is divergent
    """
    organisation3 = sequence.get('organisation3')
    packing_list = sequence.get('packing_list')
317
    packing_list.edit(destination_value=organisation3)
Sebastien Robin's avatar
Sebastien Robin committed
318 319 320 321 322 323 324 325 326 327 328 329

  def stepCreateOrganisation3(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(organisation3=organisation)

  def stepCheckSimulationDestinationUpdated(self,sequence=None, sequence_list=None, **kw):
    """
Alexandre Boeglin's avatar
Alexandre Boeglin committed
330
      Test if the destination of the simulation movement was changed
Sebastien Robin's avatar
Sebastien Robin committed
331 332 333 334 335 336 337 338 339 340
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),1)
    org3 = sequence.get('organisation3')
    for simulation_line in simulation_line_list:
      self.assertEquals(simulation_line.getDestinationValue(),org3)

  def stepChangePackingListStartDate(self, sequence=None, sequence_list=None, **kw):
    """
Alexandre Boeglin's avatar
Alexandre Boeglin committed
341
      Change the start_date of the packing_list.
Sebastien Robin's avatar
Sebastien Robin committed
342 343
    """
    packing_list = sequence.get('packing_list')
344
    packing_list.edit(start_date=self.datetime + 15)
Sebastien Robin's avatar
Sebastien Robin committed
345 346 347

  def stepCheckSimulationStartDateUpdated(self,sequence=None, sequence_list=None, **kw):
    """
Alexandre Boeglin's avatar
Alexandre Boeglin committed
348
      Test if the start_date of the simulation movement was changed
Sebastien Robin's avatar
Sebastien Robin committed
349 350 351 352 353 354 355
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),1)
    for simulation_line in simulation_line_list:
      self.assertEquals(simulation_line.getStartDate(),self.datetime + 15)

356 357 358 359 360 361 362
  def stepEditPackingListLine(self,sequence=None, sequence_list=None, **kw):
    """
      Edits a Packing List Line
    """
    packing_list_line = sequence.get('packing_list_line')
    packing_list_line.edit(description='This line was edited!')

Sebastien Robin's avatar
Sebastien Robin committed
363 364
  def stepDeletePackingListLine(self,sequence=None, sequence_list=None, **kw):
    """
365
      Deletes a Packing List Line
Sebastien Robin's avatar
Sebastien Robin committed
366 367 368 369 370
    """
    packing_list = sequence.get('packing_list')
    packing_list_line_id = sequence.get('packing_list_line').getId()
    packing_list.manage_delObjects([packing_list_line_id])

371 372 373 374 375 376 377 378 379 380 381 382 383
  def stepAddPackingListLine(self,sequence=None, sequence_list=None, **kw):
    """
      Adds a Packing List Line
    """
    packing_list = sequence.get('packing_list')
    packing_list_line = packing_list.newContent(
        portal_type=self.packing_list_line_portal_type)
    self.stepCreateNotVariatedResource(sequence=sequence,
        sequence_list=sequence_list, **kw)
    resource = sequence.get('resource')
    packing_list_line.setResourceValue(resource)
    packing_list_line.edit(price=100, quantity=200)

Sebastien Robin's avatar
Sebastien Robin committed
384 385 386 387 388 389 390 391 392 393 394
  def stepCheckSimulationConnected(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),1)
    packing_list = sequence.get('packing_list')
    packing_list_line = sequence.get('packing_list_line')
    for simulation_line in simulation_line_list:
      self.assertEquals(simulation_line.getDeliveryValue(),packing_list_line)
395 396
      self.assertEquals(packing_list_line.getCausalityValue(), 
                        simulation_line.getOrderValue())
Sebastien Robin's avatar
Sebastien Robin committed
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415

  def stepCheckSimulationDisconnected(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),1)
    for simulation_line in simulation_line_list:
      self.assertEquals(simulation_line.getDeliveryValue(),None)

  def stepModifySimulationLineQuantity(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),1)
    for simulation_line in simulation_line_list:
416
      simulation_line.edit(quantity=self.default_quantity-1)
Sebastien Robin's avatar
Sebastien Robin committed
417 418 419 420 421 422 423

  def stepModifySimulationLineStartDate(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
424 425
    resource_list = sequence.get('resource_list')
    self.assertEquals(len(simulation_line_list),len(resource_list))
Sebastien Robin's avatar
Sebastien Robin committed
426
    for simulation_line in simulation_line_list:
427
      simulation_line.edit(start_date=self.datetime+15)
Sebastien Robin's avatar
Sebastien Robin committed
428

429 430
  def stepAdoptPrevision(self,sequence=None, sequence_list=None, 
                         packing_list=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
431 432 433
    """
      Check if simulation movement are disconnected
    """
434 435
    if packing_list is None:
      packing_list = sequence.get('packing_list')
436 437
    LOG('packing_list.getSimulationState()',0,packing_list.getSimulationState())
    LOG('packing_list.getCausalityState()',0,packing_list.getCausalityState())
Sebastien Robin's avatar
Sebastien Robin committed
438 439
    packing_list.portal_workflow.doActionFor(packing_list,'adopt_prevision_action')

440 441 442 443 444 445 446
  def stepNewPackingListAdoptPrevision(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('new_packing_list')
    self.stepAdoptPrevision(sequence=sequence,packing_list=packing_list)

447
  def stepAcceptDecisionPackingList(self,sequence=None, sequence_list=None, **kw):
448 449 450 451 452 453
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('packing_list')
    packing_list.portal_workflow.doActionFor(packing_list,'accept_decision_action')

Sebastien Robin's avatar
Sebastien Robin committed
454 455 456 457 458 459 460 461 462 463 464 465 466
  def stepCheckPackingListLineWithNewQuantityPrevision(self,sequence=None, sequence_list=None, **kw):
    """
      Look if the packing list has new previsions
    """
    packing_list_line = sequence.get('packing_list_line')
    self.assertEquals(packing_list_line.getQuantity(),self.default_quantity-1)

  def stepCheckNewPackingListAfterStartDateAdopt(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    packing_list_line = sequence.get('packing_list_line')
467 468 469
    packing_list = sequence.get('packing_list')
    LOG('CheckNewPackingList, self.datetime+15',0,self.datetime+15)
    LOG('CheckNewPackingList, packing_list.getStartDate',0,packing_list.getStartDate())
470 471
    self.assertEquals(packing_list_line.getQuantity(),self.default_quantity)
    self.assertEquals(packing_list.getStartDate(),self.datetime+15)
Sebastien Robin's avatar
Sebastien Robin committed
472
    simulation_line_list = applied_rule.objectValues()
473 474 475
    resource_list = sequence.get('resource_list')
    self.assertEquals(len(simulation_line_list),len(resource_list))
    delivery_value_list = []
Sebastien Robin's avatar
Sebastien Robin committed
476
    for simulation_line in simulation_line_list:
477
#      self.assertNotEquals(simulation_line.getDeliveryValue(),None)
478
      delivery_value = simulation_line.getDeliveryValue()
479 480 481 482 483
      if delivery_value not in delivery_value_list:
        delivery_value_list.append(delivery_value_list)
#      new_packing_list = delivery_value.getParent()
#      self.assertNotEquals(new_packing_list.getUid(),packing_list.getUid())
    self.assertEquals(len(delivery_value_list),len(resource_list))
Sebastien Robin's avatar
Sebastien Robin committed
484

485 486
  def stepAddPackingListContainer(self,sequence=None, 
                                  packing_list=None,sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
487 488 489
    """
      Check if simulation movement are disconnected
    """
490 491
    if packing_list is None:
      packing_list = sequence.get('packing_list')
492
    container = packing_list.newContent(portal_type=self.container_portal_type)
Sebastien Robin's avatar
Sebastien Robin committed
493 494
    sequence.edit(container=container)

495 496 497 498 499 500 501 502 503
  def stepDefineNewPackingListContainer(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('new_packing_list')
    self.stepAddPackingListContainer(sequence=sequence,packing_list=packing_list)
    self.stepAddPackingListContainerLine(sequence=sequence)
    self.stepSetContainerLineFullQuantity(quantity=1,sequence=sequence)

Sebastien Robin's avatar
Sebastien Robin committed
504 505 506 507 508
  def stepAddPackingListContainerLine(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    container = sequence.get('container')
509
    container_line = container.newContent(portal_type=self.container_line_portal_type)
Sebastien Robin's avatar
Sebastien Robin committed
510 511
    sequence.edit(container_line=container_line)
    resource = sequence.get('resource')
512
    container_line.edit(resource_value=resource)
Sebastien Robin's avatar
Sebastien Robin committed
513 514 515 516 517 518 519 520

  def stepSetContainerLineSmallQuantity(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    container_line = sequence.get('container_line')
    container_line.edit(quantity=self.default_quantity-1)

521 522
  def stepSetContainerLineFullQuantity(self,sequence=None, sequence_list=None, 
                                       quantity=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
523 524 525 526
    """
      Check if simulation movement are disconnected
    """
    container_line = sequence.get('container_line')
527 528 529
    if quantity is None:
      quantity = sequence.get('line_quantity',self.default_quantity)
    container_line.edit(quantity=quantity)
530
    container_line.immediateReindexObject()
Sebastien Robin's avatar
Sebastien Robin committed
531

532 533 534 535 536 537 538 539 540 541 542 543 544 545
  def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None, 
                                       quantity=None,**kw):
    """
      Really fills the container
    """
    packing_list = sequence.get('packing_list')
    container = sequence.get('container')
    #empty container
    container.deleteContent(container.contentIds())
    for line in packing_list.objectValues(
        portal_type=self.packing_list_line_portal_type):
      resource = line.getResourceValue()
      tmp_kw={'movement.resource_uid':resource.getUid()}
      container_line = \
546
          container.newContent(portal_type=self.container_line_portal_type)
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564
      container_line.setResourceValue(resource)
      # without variation
      if not line.hasCellContent():
        quantity = line.getQuantity()
        container_line.edit(quantity=quantity)
        container_line.immediateReindexObject()
      # with variation
      elif line.hasCellContent():
        vcl = line.getVariationCategoryList()
        vcl.sort()
        base_id = 'movement'
        container_line.setVariationCategoryList(vcl)
        cell_key_list = list(line.getCellKeyList(base_id=base_id))
        cell_key_list.sort()
        for cell_key in cell_key_list:
          if line.hasCell(base_id=base_id, *cell_key):
            old_cell = line.getCell(base_id=base_id, *cell_key)
            cell = container_line.newCell(base_id=base_id,
565
                portal_type=self.container_cell_portal_type, *cell_key)
566 567 568 569 570 571 572
            cell.edit(mapped_value_property_list=['price', 'quantity'],
                price=old_cell.getPrice(),
                quantity=old_cell.getQuantity(),
                predicate_category_list=cell_key,
                variation_category_list=cell_key)
            cell.immediateReindexObject()

Sebastien Robin's avatar
Sebastien Robin committed
573 574 575 576 577 578
  def stepCheckPackingListIsNotPacked(self,sequence=None, sequence_list=None, **kw):
    """
      Check that the number of objects in containers are
      not equals to the quantity of the packing list
    """
    packing_list = sequence.get('packing_list')
579 580
    if packing_list.getPortalType() not in \
        self.packable_packing_list_portal_type_list: return
Sebastien Robin's avatar
Sebastien Robin committed
581
    self.assertEquals(0,packing_list.isPacked())
582
    self.assertEquals('missing',packing_list.getContainerState())
Sebastien Robin's avatar
Sebastien Robin committed
583

584 585
  def stepCheckPackingListIsPacked(self,sequence=None, sequence_list=None, 
                                   packing_list=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
586 587 588 589
    """
      Check that the number of objects in containers are
      equals to the quantity of the packing list
    """
590 591
    if packing_list is None:
      packing_list = sequence.get('packing_list')
592 593
    if packing_list.getPortalType() not in \
        self.packable_packing_list_portal_type_list: return
594
    get_transaction().commit()
Sebastien Robin's avatar
Sebastien Robin committed
595
    self.assertEquals(1,packing_list.isPacked())
596
    self.assertEquals('packed',packing_list.getContainerState())
Sebastien Robin's avatar
Sebastien Robin committed
597

598 599 600 601 602 603
  def stepCheckNewPackingListIsPacked(self,sequence=None, sequence_list=None, **kw):
    """
      Check that the number of objects in containers are
      equals to the quantity of the packing list
    """
    packing_list = sequence.get('new_packing_list')
604 605
    if packing_list.getPortalType() not in \
        self.packable_packing_list_portal_type_list: return
606 607 608
    self.stepCheckPackingListIsPacked(sequence=sequence,
                                      packing_list=packing_list)

609 610

class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
611

612
  run_all_test = 1
613 614 615
  quiet = 0

  def test_01_PackingListDecreaseQuantity(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
616 617 618
    """
      Change the quantity on an delivery line, then
      see if the packing list is divergent and then
619
      split and defer the packing list
Sebastien Robin's avatar
Sebastien Robin committed
620 621 622 623 624 625
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
626 627 628 629 630 631
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplitted \
Sebastien Robin's avatar
Sebastien Robin committed
632 633 634
                      '
    sequence_list.addSequenceString(sequence_string)

635
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
636

637
  def test_02_PackingListChangeDestination(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
638 639 640 641 642 643 644 645
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
646
                      stepChangePackingListDestination \
647 648
                      stepCheckPackingListIsCalculating \
                      stepAcceptDecisionPackingList \
649
                      stepTic \
650 651
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListIsNotDivergent \
652
                      stepCheckSimulationDestinationUpdated \
Sebastien Robin's avatar
Sebastien Robin committed
653 654 655
                      '
    sequence_list.addSequenceString(sequence_string)

656
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
657

658
  def test_03_PackingListChangeStartDate(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
659 660 661 662 663 664 665 666
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
667 668
                      stepChangePackingListStartDate \
                      stepCheckPackingListIsCalculating \
669
                      stepAcceptDecisionPackingList \
670 671 672 673
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckSimulationStartDateUpdated \
Sebastien Robin's avatar
Sebastien Robin committed
674 675 676
                      '
    sequence_list.addSequenceString(sequence_string)

677
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
678

679
  def test_04_PackingListDeleteLine(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
680 681 682 683 684 685 686 687
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
688 689 690 691 692
                      stepCheckSimulationConnected \
                      stepDeletePackingListLine \
                      stepCheckPackingListIsNotDivergent \
                      stepTic \
                      stepCheckSimulationDisconnected \
Sebastien Robin's avatar
Sebastien Robin committed
693 694 695
                      '
    sequence_list.addSequenceString(sequence_string)

696
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
697

698
  def test_05_SimulationChangeQuantity(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
699 700 701 702 703 704 705 706
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
707 708 709 710 711 712 713 714
                      stepModifySimulationLineQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevision \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithNewQuantityPrevision \
Sebastien Robin's avatar
Sebastien Robin committed
715 716 717
                      '
    sequence_list.addSequenceString(sequence_string)

718
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
719

720
  def test_06_SimulationChangeStartDate(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
721 722 723 724 725 726 727 728
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
729 730 731 732 733 734 735
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevision \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
Sebastien Robin's avatar
Sebastien Robin committed
736
                      '
737
    # XXX Check if there is a new packing list created
Sebastien Robin's avatar
Sebastien Robin committed
738 739
    sequence_list.addSequenceString(sequence_string)

740
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
741

742
  def test_07_SimulationChangeStartDateWithTwoOrderLine(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
743 744 745 746 747 748 749
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
750
    sequence_string = self.default_sequence_with_two_lines + '\
751 752 753 754 755 756 757 758 759
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepAdoptPrevision \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
Sebastien Robin's avatar
Sebastien Robin committed
760 761 762 763
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)

764
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
765

766
  def test_08_AddContainers(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
767 768 769 770 771 772 773 774
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
775 776 777 778 779 780 781
                      stepAddPackingListContainer \
                      stepAddPackingListContainerLine \
                      stepSetContainerLineSmallQuantity \
                      stepCheckPackingListIsNotPacked \
                      stepSetContainerFullQuantity \
                      stepTic \
                      stepCheckPackingListIsPacked \
Sebastien Robin's avatar
Sebastien Robin committed
782 783 784 785
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)

786
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
787

788
  def test_09_AddContainersWithVariatedResources(self, quiet=quiet, run=run_all_test):
789 790 791 792 793 794
    """
      Test generation of delivery list
    """
    if not run: return
    sequence_list = SequenceList()

795 796
    # Test with a order with cells
    sequence_string = self.variated_default_sequence + '\
797 798 799 800 801 802 803
                      stepAddPackingListContainer \
                      stepAddPackingListContainerLine \
                      stepSetContainerLineSmallQuantity \
                      stepCheckPackingListIsNotPacked \
                      stepSetContainerFullQuantity \
                      stepTic \
                      stepCheckPackingListIsPacked \
804 805 806
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)
807
    
808
    sequence_list.play(self, quiet=quiet)
809

810
  def test_10_PackingListIncreaseQuantity(self, quiet=quiet, run=run_all_test):
811
    """
812 813 814 815 816 817 818 819
    - Increase the quantity on an delivery line
    - check if the packing list is divergent
    - Apply the "split and defer" solver to the packing list
    - check that nothing was splitted and the packing list is still divergent
      (reset the delta before, as we don't expect a modification)

    Basically, when we apply "split and defer" to a packing list, we don't
    want it to modify lines which have been increased.
820 821 822 823 824 825
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
826 827 828 829
                      stepIncreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepSplitAndDeferPackingList \
                      stepTic \
830 831 832
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepCheckPackingListNotSolved \
833 834 835
                      '
    sequence_list.addSequenceString(sequence_string)

836
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
837

838 839
  def test_11_PackingListDecreaseTwoTimesQuantityAndUpdateDelivery(self,
                                               quiet=quiet, run=run_all_test):
840 841 842 843 844 845 846 847 848 849
    """
      Change the quantity on an delivery line, then
      see if the packing list is divergent and then
      split and defer the packing list
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplitted \
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckNewPackingListIsDivergent \
                      stepNewPackingListAdoptPrevision \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplittedTwoTimes \
865 866 867
                      '
    sequence_list.addSequenceString(sequence_string)

868
    sequence_list.play(self, quiet=quiet)
869

870
  def test_12_PackingListLineChangeResource(self, quiet=quiet, run=run_all_test):
871 872 873 874 875 876 877 878
    """
    Test if delivery diverged when we change the resource.
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
879 880 881 882 883
                      stepCreateNotVariatedResource \
                      stepChangePackingListLineResource \
                      stepCheckPackingListIsCalculating \
                      stepTic \
                      stepCheckPackingListIsDivergent \
884 885 886
                      '
    sequence_list.addSequenceString(sequence_string)

887
    sequence_list.play(self, quiet=quiet)
888

889
  def test_14_PackingListHavePriceCurrencyCategory(self, quiet=quiet,
890
                                                   run=run_all_test):
891 892 893 894
    """Deliveries must have a price currency category. #252
    """
    if not run:
      return
895 896 897 898
    pl = self.getPortal().getDefaultModule(self.packing_list_portal_type
               ).newContent(portal_type=self.packing_list_portal_type)
    self.failUnless(hasattr(pl, 'getPriceCurrency'))
    
899 900 901 902
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestPackingList))
  return suite
Sebastien Robin's avatar
Sebastien Robin committed
903