testPackingList.py 62.9 KB
Newer Older
Sebastien Robin's avatar
Sebastien Robin committed
1 2
##############################################################################
#
3
# Copyright (c) 2004-2008 Nexedi SA and Contributors. All Rights Reserved.
Sebastien Robin's avatar
Sebastien Robin committed
4 5 6
#          Sebastien Robin <seb@nexedi.com>
#
# WARNING: This program as such is intended to be used by professional
7
# programmers who take the whole responsibility of assessing all potential
Sebastien Robin's avatar
Sebastien Robin committed
8 9
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
10
# guarantees and support are strongly adviced to contract a Free Software
Sebastien Robin's avatar
Sebastien Robin committed
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
# 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
30 31
import transaction

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

38
class TestPackingListMixin(TestOrderMixin):
Sebastien Robin's avatar
Sebastien Robin committed
39
  """
40
    Test business template erp5_trade
Sebastien Robin's avatar
Sebastien Robin committed
41
  """
42 43 44
  container_portal_type = 'Container'
  container_line_portal_type = 'Container Line'
  container_cell_portal_type = 'Container Cell'
45 46
  default_order_sequence = '\
                      stepCreateOrganisation1 \
47 48
                      stepCreateOrganisation2 \
                      stepCreateOrganisation3 \
49 50
                      stepCreateProject1 \
                      stepCreateProject2 \
51
                      stepCreateOrder \
52 53
                      stepCreateCurrency \
                      stepSetOrderPriceCurrency \
54 55 56
                      stepSetOrderProfile '

  default_sequence = default_order_sequence + '\
57 58 59 60 61 62 63 64 65 66 67
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
68 69
                      stepCheckPackingListIsNotDivergent \
                      stepCheckOrderPackingList '
70

71 72 73 74 75 76 77 78 79 80 81
  confirmed_order_without_packing_list = default_order_sequence + '\
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic '

82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
  default_sequence_with_duplicated_lines = default_order_sequence + '\
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckOrderPackingList '

  default_sequence_with_two_lines = default_order_sequence + '\
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepCreateNotVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
118 119
                      stepCheckPackingListIsNotDivergent \
                      stepCheckOrderPackingList'
120

121
  variated_default_sequence = default_order_sequence + '\
122 123 124 125 126 127 128 129 130 131 132 133 134
                      stepCreateVariatedResource \
                      stepTic \
                      stepCreateOrderLine \
                      stepSetOrderLineResource \
                      stepSetOrderLineDefaultValues \
                      stepSetOrderLineFullVCL \
                      stepCompleteOrderLineMatrix \
                      stepOrderOrder \
                      stepTic \
                      stepConfirmOrder \
                      stepTic \
                      stepCheckOrderSimulation \
                      stepCheckDeliveryBuilding \
135 136
                      stepCheckPackingListIsNotDivergent \
                      stepCheckOrderPackingList'
137

Sebastien Robin's avatar
Sebastien Robin committed
138 139 140 141 142
  def getTitle(self):
    return "Packing List"

  def enableLightInstall(self):
    """
143
    You can override this.
Sebastien Robin's avatar
Sebastien Robin committed
144 145 146 147 148 149 150 151 152 153 154
    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

155 156 157 158 159 160 161 162 163 164
  def stepCheckOrderPackingList(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is matching order
    """
    packing_list = sequence.get('packing_list')
    order = sequence.get('order')
    self.assertEquals(packing_list.getCausalityValue(), order)
    self.assertEquals(packing_list.getSource(), order.getSource())
    self.assertEquals(packing_list.getDestination(), order.getDestination())
    self.assertEquals(packing_list.getDestinationSection(), \
Jérome Perrin's avatar
Jérome Perrin committed
165
                                       order.getDestinationSection())
166 167 168 169 170 171 172 173
    self.assertEquals(packing_list.getSourceSection(), \
                                       order.getSourceSection())
    self.assertEquals(packing_list.getSourceDecision(), \
                                       order.getSourceDecision())
    self.assertEquals(packing_list.getDestinationAdministration(), \
                                       order.getDestinationAdministration())
    self.assertEquals(packing_list.getSourceAdministration(), \
                                       order.getSourceAdministration())
174 175
    self.assertEquals(packing_list.getPriceCurrency(), \
                                       order.getPriceCurrency())
176 177 178 179
    self.assertEquals(packing_list.getDestinationProject(), \
                                       order.getDestinationProject())
    self.assertEquals(packing_list.getSourceProject(), \
                                       order.getSourceProject())
180

181
  def stepCheckPackingListIsDivergent(self, sequence=None, sequence_list=None,
182
                                      packing_list=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
183 184 185
    """
      Test if packing list is divergent
    """
186 187
    if packing_list is None:
      packing_list = sequence.get('packing_list')
188 189
    self.failIf('Site Error' in packing_list.view())
    self.assertTrue(packing_list.isDivergent())
190 191 192 193 194 195

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

199 200
  def stepCheckPackingListIsCalculating(self, sequence=None, sequence_list=None, **kw):
    """
201
      Test if packing list is calculating
202 203 204 205 206 207
    """
    packing_list = sequence.get('packing_list')
    self.assertEquals('calculating',packing_list.getCausalityState())

  def stepCheckPackingListIsSolved(self, sequence=None, sequence_list=None, **kw):
    """
208
      Test if packing list is solved
209 210 211 212 213 214 215 216 217
    """
    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')
218
    self.assertEquals('diverged', packing_list.getCausalityState())
219

Sebastien Robin's avatar
Sebastien Robin committed
220 221 222 223 224
  def stepCheckPackingListIsNotDivergent(self, sequence=None, sequence_list=None, **kw):
    """
      Test if packing list is not divergent
    """
    packing_list = sequence.get('packing_list')
225
    self.assertFalse(packing_list.isDivergent())
Sebastien Robin's avatar
Sebastien Robin committed
226

227
  def stepChangePackingListLineResource(self, sequence=None,
228 229 230 231 232 233 234 235 236 237
                                        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)

238 239
  def stepDecreasePackingListLineQuantity(self, sequence=None,
      sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
240
    """
241
    Set a decreased quantity on packing list lines
Sebastien Robin's avatar
Sebastien Robin committed
242 243
    """
    packing_list = sequence.get('packing_list')
244
    quantity = sequence.get('line_quantity',default=self.default_quantity)
245
    quantity = quantity - 1
246
    sequence.edit(line_quantity=quantity)
Sebastien Robin's avatar
Sebastien Robin committed
247
    for packing_list_line in packing_list.objectValues(
248
        portal_type=self.packing_list_line_portal_type):
249
      packing_list_line.edit(quantity=quantity)
250
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) - 1.0)
Sebastien Robin's avatar
Sebastien Robin committed
251

252 253
  def stepIncreasePackingListLineQuantity(self, sequence=None,
      sequence_list=None, **kw):
254
    """
255
    Set a increased quantity on packing list lines
256 257
    """
    packing_list = sequence.get('packing_list')
258 259 260
    quantity = sequence.get('line_quantity',default=self.default_quantity)
    quantity = quantity + 1
    sequence.edit(line_quantity=quantity)
261
    for packing_list_line in packing_list.objectValues(
262
        portal_type=self.packing_list_line_portal_type):
263 264
      packing_list_line.edit(quantity=quantity)
    sequence.edit(last_delta = sequence.get('last_delta', 0.0) + 1.0)
265

Sebastien Robin's avatar
Sebastien Robin committed
266 267 268 269 270
  def stepSplitAndDeferPackingList(self, sequence=None, sequence_list=None, **kw):
    """
      Do the split and defer action
    """
    packing_list = sequence.get('packing_list')
271 272 273 274 275 276 277 278 279 280
    kw = {'listbox':[
      {'listbox_key':line.getRelativeUrl(),
       'choice':'SplitAndDefer'} for line in packing_list.getMovementList() \
      if line.isDivergent()]}
    self.portal.portal_workflow.doActionFor(
      packing_list,
      'split_and_defer_action',
      start_date=self.datetime + 15,
      stop_date=self.datetime + 25,
      **kw)
Sebastien Robin's avatar
Sebastien Robin committed
281

282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297
  def stepSplitAndDeferDoNothingPackingList(self, sequence=None, sequence_list=None, **kw):
    """
      Do the split and defer action, but choose "do nothing" for divergences
    """
    packing_list = sequence.get('packing_list')
    kw = {'listbox':[
      {'listbox_key':line.getRelativeUrl(),
       'choice':'ignore'} for line in packing_list.getMovementList() \
      if line.isDivergent()]}
    self.portal.portal_workflow.doActionFor(
      packing_list,
      'split_and_defer_action',
      start_date=self.datetime + 15,
      stop_date=self.datetime + 25,
      **kw)

Sebastien Robin's avatar
Sebastien Robin committed
298 299
  def stepCheckPackingListSplitted(self, sequence=None, sequence_list=None, **kw):
    """
300
      Test if packing list was splitted
Sebastien Robin's avatar
Sebastien Robin committed
301 302 303 304 305 306 307 308 309 310 311 312
    """
    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
313
    sequence.edit(new_packing_list=packing_list2)
Sebastien Robin's avatar
Sebastien Robin committed
314 315 316 317 318 319 320
    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())

321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
  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())

343 344 345 346 347 348 349 350 351
  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')
352
    last_delta = sequence.get('last_delta', 0.0)
353 354
    for line in packing_list1.objectValues(
          portal_type= self.packing_list_line_portal_type):
355 356
      self.assertEquals(self.default_quantity + last_delta,
          line.getQuantity())
357 358 359 360
      simulation_list = line.getDeliveryRelatedValueList(
                            portal_type='Simulation Movement')
      self.assertEquals(len(simulation_list),1)
      simulation_movement = simulation_list[0]
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386
      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())
387

388
  def stepChangePackingListDestination(self, sequence=None,
389
                                       sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
390 391 392 393 394
    """
      Test if packing list is divergent
    """
    organisation3 = sequence.get('organisation3')
    packing_list = sequence.get('packing_list')
395
    packing_list.edit(destination_value=organisation3)
Sebastien Robin's avatar
Sebastien Robin committed
396 397 398 399 400 401 402 403 404 405 406 407

  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
408
      Test if the destination of the simulation movement was changed
Sebastien Robin's avatar
Sebastien Robin committed
409 410 411 412 413 414 415 416 417 418
    """
    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
419
      Change the start_date of the packing_list.
Sebastien Robin's avatar
Sebastien Robin committed
420 421
    """
    packing_list = sequence.get('packing_list')
422
    packing_list.edit(start_date=self.datetime + 15)
Sebastien Robin's avatar
Sebastien Robin committed
423 424 425

  def stepCheckSimulationStartDateUpdated(self,sequence=None, sequence_list=None, **kw):
    """
Alexandre Boeglin's avatar
Alexandre Boeglin committed
426
      Test if the start_date of the simulation movement was changed
Sebastien Robin's avatar
Sebastien Robin committed
427 428 429 430 431 432 433
    """
    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)

434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457
  def stepCheckSimulationQuantityUpdated(self,sequence=None, sequence_list=None, **kw):
    """
      Test if the quantity of the simulation movement was changed
    """
    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.getQuantity() + \
                        simulation_line.getDeliveryError(),
                        self.default_quantity)

  def stepCheckSimulationQuantityUpdatedForMergedLine(self,sequence=None, sequence_list=None, **kw):
    """
      Test if the quantity of the simulation movement was changed
    """
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self.assertEquals(len(simulation_line_list),2)
    for simulation_line in simulation_line_list:
      self.assertEquals(simulation_line.getQuantity() + \
                        simulation_line.getDeliveryError(),
                        self.default_quantity)

458 459 460 461 462 463 464
  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
465 466
  def stepDeletePackingListLine(self,sequence=None, sequence_list=None, **kw):
    """
467
      Deletes a Packing List Line
Sebastien Robin's avatar
Sebastien Robin committed
468 469 470 471 472
    """
    packing_list = sequence.get('packing_list')
    packing_list_line_id = sequence.get('packing_list_line').getId()
    packing_list.manage_delObjects([packing_list_line_id])

473 474 475 476 477 478 479 480 481 482 483 484 485
  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
486 487
  def stepCheckSimulationConnected(self,sequence=None, sequence_list=None, **kw):
    """
488
      Check if simulation movement are connected
Sebastien Robin's avatar
Sebastien Robin committed
489 490 491 492 493 494 495 496
    """
    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)
497
      self.assertEquals(packing_list_line.getCausalityValue(),
498
                        simulation_line.getOrderValue())
Sebastien Robin's avatar
Sebastien Robin committed
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515

  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()
516
#    self.assertEquals(len(simulation_line_list),1)
Sebastien Robin's avatar
Sebastien Robin committed
517
    for simulation_line in simulation_line_list:
518
      simulation_line.edit(quantity=self.default_quantity-1)
519
      simulation_line.getOrderValue().edit(quantity=self.default_quantity-1)
Sebastien Robin's avatar
Sebastien Robin committed
520

521 522 523 524 525 526 527 528 529
  def stepModifySimulationLineQuantityForMergedLine(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),2)
    for simulation_line in simulation_line_list:
      simulation_line.edit(quantity=self.default_quantity-1)
530
      simulation_line.getOrderValue().edit(quantity=self.default_quantity-1)
531

Sebastien Robin's avatar
Sebastien Robin committed
532 533 534 535 536 537
  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()
538
    resource_list = sequence.get('resource_list')
Sebastien Robin's avatar
Sebastien Robin committed
539
    for simulation_line in simulation_line_list:
540
      simulation_line.edit(start_date=self.datetime+15)
541
      simulation_line.getOrderValue().edit(start_date=self.datetime+15)
Sebastien Robin's avatar
Sebastien Robin committed
542

543
  def stepModifyOneSimulationLineStartDate(self,sequence=None, sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
544 545 546
    """
      Check if simulation movement are disconnected
    """
547 548 549 550 551
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    resource_list = sequence.get('resource_list')
    self.assertEquals(len(simulation_line_list),len(resource_list))
    simulation_line_list[-1].edit(start_date=self.datetime+15)
552
    simulation_line_list[-1].getOrderValue().edit(start_date=self.datetime+15)
553 554 555 556 557 558 559 560 561 562

  def stepModifySimulationLineResource(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()
    resource_list = sequence.get('resource_list')
    for simulation_line in simulation_line_list:
      simulation_line.edit(resource_value=resource_list[-1])
563
      simulation_line.getOrderValue().edit(resource_value=resource_list[-1])
564 565 566 567 568 569 570 571 572

  def stepModifyOneSimulationLineResource(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()
    resource_list = sequence.get('resource_list')
    simulation_line_list[-1].edit(resource_value=resource_list[-1])
573
    simulation_line_list[-1].getOrderValue().edit(resource_value=resource_list[-1])
Sebastien Robin's avatar
Sebastien Robin committed
574

575
  def stepNewPackingListAdoptPrevisionQuantity(self,sequence=None, sequence_list=None, **kw):
576 577 578 579
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('new_packing_list')
580 581 582 583 584 585 586 587 588
    self._solveDivergence(packing_list, 'quantity', 'adopt')

  def stepUnifyDestinationWithDecision(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('packing_list')
    self._solveDeliveryGroupDivergence(packing_list, 'destination',
                                       packing_list.getRelativeUrl())
589

590
  def stepUnifyStartDateWithDecision(self,sequence=None, sequence_list=None, **kw):
591 592 593 594
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('packing_list')
595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
    self._solveDeliveryGroupDivergence(packing_list, 'start_date',
                                  packing_list.getRelativeUrl())

  def stepUnifyStartDateWithPrevision(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    packing_list = sequence.get('packing_list')
    applied_rule = sequence.get('applied_rule')
    simulation_line_list = applied_rule.objectValues()
    self._solveDeliveryGroupDivergence(packing_list, 'start_date',
                                  simulation_line_list[-1].getRelativeUrl())

  def _solveDeliveryGroupDivergence(self, obj, property, target_url):
    kw = {'delivery_group_listbox':
          {property:{'choice':target_url}}}
    self.portal.portal_workflow.doActionFor(
      obj,
      'solve_divergence_action',
      **kw)

  def stepAcceptDecisionResource(self,sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self._solveDivergence(packing_list, 'resource', 'accept')

  def stepAcceptDecisionQuantity(self,sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self._solveDivergence(packing_list, 'quantity', 'accept')

  def stepAdoptPrevisionResource(self,sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self._solveDivergence(packing_list, 'resource', 'adopt')

  def stepAdoptPrevisionQuantity(self,sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('packing_list')
    self._solveDivergence(packing_list, 'quantity', 'adopt')

  def _solveDivergence(self, obj, property, decision, group='line'):
    """
Jérome Perrin's avatar
Jérome Perrin committed
634 635
      Solve divergences for a given property by taking decision.
      FIXME: Only "line" level divergence are supported
636 637 638 639 640 641 642 643 644 645 646 647
    """
    kw = {'%s_group_listbox' % group:{}}
    for divergence in obj.getDivergenceList():
      if divergence.getProperty('tested_property') != property:
        continue
      sm_url = divergence.getProperty('simulation_movement').getRelativeUrl()
      kw['line_group_listbox']['%s&%s' % (sm_url, property)] = {
        'choice':decision}
    self.portal.portal_workflow.doActionFor(
      obj,
      'solve_divergence_action',
      **kw)
648

Sebastien Robin's avatar
Sebastien Robin committed
649 650 651 652 653 654 655
  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)

656 657 658 659 660 661 662
  def stepCheckPackingListLineWithNewQuantityPrevisionForMergedLine(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)*2)

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 689 690 691 692 693 694 695 696 697 698
  def stepCheckPackingListLineWithDifferentResource(self,sequence=None, sequence_list=None, **kw):
    """
      Look if the packing list has new previsions
    """
    packing_list_line = sequence.get('packing_list_line')
    new_resource = sequence.get('resource')
    self.assertEquals(packing_list_line.getQuantity(), self.default_quantity)
    self.assertNotEquals(packing_list_line.getResourceValue(), new_resource)
    simulation_line_list = packing_list_line.getDeliveryRelatedValueList()
    order_line_list = [x.getOrder() for x in simulation_line_list]
    self.assertEquals(sorted(packing_list_line.getCausalityList()),
                      sorted(order_line_list))
    new_packing_list_line = packing_list_line.aq_parent[str(int(packing_list_line.getId())+1)]
    self.assertEquals(new_packing_list_line.getQuantity(), self.default_quantity)
    self.assertEquals(new_packing_list_line.getResourceValue(), new_resource)
    simulation_line_list = new_packing_list_line.getDeliveryRelatedValueList()
    order_line_list = [x.getOrder() for x in simulation_line_list]
    self.assertEquals(sorted(new_packing_list_line.getCausalityList()),
                      sorted(order_line_list))

  def stepCheckPackingListLineWithSameResource(self,sequence=None, sequence_list=None, **kw):
    """
      Look if the packing list has new previsions
    """
    old_packing_list_line = sequence.get('packing_list_line')
    packing_list_line = old_packing_list_line.aq_parent[str(int(old_packing_list_line.getId())-1)]
    resource = sequence.get('resource')
    self.assertEquals(old_packing_list_line.getQuantity(), 0)
    self.assertNotEquals(old_packing_list_line.getResourceValue(), resource)
    self.assertEquals(packing_list_line.getQuantity(), self.default_quantity * 2)
    self.assertEquals(packing_list_line.getResourceValue(), resource)
    simulation_line_list = packing_list_line.getDeliveryRelatedValueList()
    order_line_list = [x.getOrder() for x in simulation_line_list]
    self.assertEquals(sorted(packing_list_line.getCausalityList()),
                      sorted(order_line_list))

Sebastien Robin's avatar
Sebastien Robin committed
699 700 701 702 703 704
  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')
705 706 707
    packing_list = sequence.get('packing_list')
    LOG('CheckNewPackingList, self.datetime+15',0,self.datetime+15)
    LOG('CheckNewPackingList, packing_list.getStartDate',0,packing_list.getStartDate())
708 709
    self.assertEquals(packing_list_line.getQuantity(),self.default_quantity)
    self.assertEquals(packing_list.getStartDate(),self.datetime+15)
Sebastien Robin's avatar
Sebastien Robin committed
710
    simulation_line_list = applied_rule.objectValues()
711 712 713
    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
714
    for simulation_line in simulation_line_list:
715
#      self.assertNotEquals(simulation_line.getDeliveryValue(),None)
716
      delivery_value = simulation_line.getDeliveryValue()
717 718 719
      if delivery_value not in delivery_value_list:
        delivery_value_list.append(delivery_value_list)
#      new_packing_list = delivery_value.getParent()
720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747
#      self.assertNotEquals(new_packing_list.getUid(),packing_list.getUid())
    self.assertEquals(len(delivery_value_list),len(resource_list))

  def stepCheckNewSplitPackingListAfterStartDateAdopt(self,sequence=None, sequence_list=None, **kw):
    """
      Check if simulation movement are disconnected
    """
    applied_rule = sequence.get('applied_rule')
    packing_list = sequence.get('packing_list')
    packing_list_line = [x for x in packing_list.getMovementList() \
                         if x.getQuantity()][0]
    new_packing_list = self.portal.sale_packing_list_module[str(int(packing_list.getId())-1)]
    new_packing_list_line = [x for x in new_packing_list.getMovementList() \
                             if x.getQuantity()][0]
    self.assertEquals(packing_list_line.getQuantity(),self.default_quantity)
    self.assertEquals(packing_list.getStartDate(),self.datetime+10)
    self.assertEquals(new_packing_list_line.getQuantity(),self.default_quantity)
    self.assertEquals(new_packing_list.getStartDate(),self.datetime+15)
    simulation_line_list = applied_rule.objectValues()
    resource_list = sequence.get('resource_list')
    self.assertEquals(len(simulation_line_list),len(resource_list))
    delivery_value_list = []
    for simulation_line in simulation_line_list:
#      self.assertNotEquals(simulation_line.getDeliveryValue(),None)
      delivery_value = simulation_line.getDeliveryValue()
      if delivery_value not in delivery_value_list:
        delivery_value_list.append(delivery_value_list)
#      new_packing_list = delivery_value.getParent()
748 749
#      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
750

751
  def stepAddPackingListContainer(self,sequence=None,
752
                                  packing_list=None,sequence_list=None, **kw):
Sebastien Robin's avatar
Sebastien Robin committed
753 754 755
    """
      Check if simulation movement are disconnected
    """
756 757
    if packing_list is None:
      packing_list = sequence.get('packing_list')
758
    container = packing_list.newContent(portal_type=self.container_portal_type)
Sebastien Robin's avatar
Sebastien Robin committed
759 760
    sequence.edit(container=container)

761 762 763 764 765 766 767 768 769
  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
770 771
  def stepAddPackingListContainerLine(self,sequence=None, sequence_list=None, **kw):
    """
Jérome Perrin's avatar
Jérome Perrin committed
772
      Add a container line in the packing list
Sebastien Robin's avatar
Sebastien Robin committed
773 774
    """
    container = sequence.get('container')
775
    container_line = container.newContent(portal_type=self.container_line_portal_type)
Sebastien Robin's avatar
Sebastien Robin committed
776 777
    sequence.edit(container_line=container_line)
    resource = sequence.get('resource')
778
    container_line.edit(resource_value=resource)
Sebastien Robin's avatar
Sebastien Robin committed
779 780 781

  def stepSetContainerLineSmallQuantity(self,sequence=None, sequence_list=None, **kw):
    """
Jérome Perrin's avatar
Jérome Perrin committed
782 783
      Set a small quantity on the container line, it should not be enough for
      the packing list to be packed.
Sebastien Robin's avatar
Sebastien Robin committed
784 785 786 787
    """
    container_line = sequence.get('container_line')
    container_line.edit(quantity=self.default_quantity-1)

788 789 790 791 792 793 794 795 796 797
  def stepCheckContainerLineSmallQuantity(self, sequence=None,
      sequence_list=None, **kw):
    """
      Checks that quantity is set correctly on the container_line.
    """
    container_line = sequence.get('container_line')
    self.assertEquals(self.default_quantity - 1, container_line.getQuantity())
    self.assertEquals(self.default_quantity - 1,
                      container_line.getTotalQuantity())

798
  def stepSetContainerLineFullQuantity(self,sequence=None, sequence_list=None,
799
                                       quantity=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
800
    """
Jérome Perrin's avatar
Jérome Perrin committed
801
      Set the full quantity
Sebastien Robin's avatar
Sebastien Robin committed
802 803
    """
    container_line = sequence.get('container_line')
804 805 806
    if quantity is None:
      quantity = sequence.get('line_quantity',self.default_quantity)
    container_line.edit(quantity=quantity)
807
    container_line.immediateReindexObject()
Sebastien Robin's avatar
Sebastien Robin committed
808

809
  def stepSetContainerFullQuantity(self,sequence=None, sequence_list=None,
810 811 812 813 814 815 816 817 818 819 820 821 822
                                       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 = \
823
          container.newContent(portal_type=self.container_line_portal_type)
824 825 826 827 828 829
      container_line.setResourceValue(resource)
      # without variation
      if not line.hasCellContent():
        quantity = line.getQuantity()
        container_line.edit(quantity=quantity)
        container_line.immediateReindexObject()
830 831
        self.assertEquals(quantity, container_line.getQuantity())
        self.assertEquals(quantity, container_line.getTotalQuantity())
832 833 834 835 836 837 838 839 840 841 842 843
      # 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,
844
                portal_type=self.container_cell_portal_type, *cell_key)
845 846 847 848 849 850
            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()
851 852 853 854 855 856 857 858 859
          self.assertEquals(old_cell.getQuantity(), cell.getQuantity())
          self.assertEquals(old_cell.getTotalQuantity(), cell.getTotalQuantity())

        self.assertEquals(line.getQuantity(), container_line.getQuantity())
        self.assertEquals(line.getTotalQuantity(), container_line.getTotalQuantity())

    # quantity is 1 on the container itself
    self.assertEquals(1, container.getQuantity())
    self.assertEquals(1, container.getTotalQuantity())
860

Sebastien Robin's avatar
Sebastien Robin committed
861 862 863 864 865 866 867
  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')
    self.assertEquals(0,packing_list.isPacked())
868
    self.assertEquals('missing',packing_list.getContainerState())
Sebastien Robin's avatar
Sebastien Robin committed
869

870
  def stepCheckPackingListIsPacked(self,sequence=None, sequence_list=None,
871
                                   packing_list=None,**kw):
Sebastien Robin's avatar
Sebastien Robin committed
872 873 874 875
    """
      Check that the number of objects in containers are
      equals to the quantity of the packing list
    """
876 877
    if packing_list is None:
      packing_list = sequence.get('packing_list')
878
    transaction.commit()
Sebastien Robin's avatar
Sebastien Robin committed
879
    self.assertEquals(1,packing_list.isPacked())
880
    self.assertEquals('packed',packing_list.getContainerState())
Sebastien Robin's avatar
Sebastien Robin committed
881

882 883 884 885 886 887 888 889 890
  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')
    self.stepCheckPackingListIsPacked(sequence=sequence,
                                      packing_list=packing_list)

891 892 893
  def stepCreateCurrency(self, sequence, **kw) :
    """Create a default currency. """
    currency_module = self.getCurrencyModule()
894
    if currency_module._getOb('EUR', None) is None:
895 896 897 898 899 900
      currency = self.getCurrencyModule().newContent(
          portal_type='Currency',
          id="EUR",
          base_unit_quantity=0.01,
          )
    else:
901
      currency = currency_module._getOb('EUR')
902
    sequence.edit(currency=currency)
903

904 905 906 907 908 909 910 911 912 913 914
  def stepSetOrderPriceCurrency(self, sequence, **kw) :
    """Set the price currency of the order.

    This step is not necessary.
    TODO : - include a test without this step.
           - include a test with this step late.
    """
    currency = sequence.get('currency')
    order = sequence.get('order')
    order.setPriceCurrency(currency.getRelativeUrl())

915

916

917
class TestPackingList(TestPackingListMixin, ERP5TypeTestCase) :
918

919
  run_all_test = 1
920 921 922
  quiet = 0

  def test_01_PackingListDecreaseQuantity(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
923 924 925
    """
      Change the quantity on an delivery line, then
      see if the packing list is divergent and then
926
      split and defer the packing list
Sebastien Robin's avatar
Sebastien Robin committed
927 928 929 930 931 932
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
933 934
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
935 936
                      stepTic \
                      stepCheckPackingListIsDiverged \
937 938 939 940
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplitted \
Sebastien Robin's avatar
Sebastien Robin committed
941 942 943
                      '
    sequence_list.addSequenceString(sequence_string)

944
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
945

946
  def test_02_PackingListChangeDestination(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
947 948 949 950 951
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
952
                      stepChangePackingListDestination \
953
                      stepCheckPackingListIsCalculating \
954 955
                      stepTic \
                      stepCheckPackingListIsDiverged \
956
                      stepUnifyDestinationWithDecision \
957
                      stepTic \
958 959
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListIsNotDivergent \
960
                      stepCheckSimulationDestinationUpdated \
Sebastien Robin's avatar
Sebastien Robin committed
961 962 963
                      '
    sequence_list.addSequenceString(sequence_string)

964
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
965

966
  def test_03_PackingListChangeStartDate(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
967 968 969 970 971
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
972 973
                      stepChangePackingListStartDate \
                      stepCheckPackingListIsCalculating \
974 975
                      stepTic \
                      stepCheckPackingListIsDiverged \
976
                      stepUnifyStartDateWithDecision \
977 978 979 980
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckSimulationStartDateUpdated \
Sebastien Robin's avatar
Sebastien Robin committed
981 982 983
                      '
    sequence_list.addSequenceString(sequence_string)

984
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
985

986
  def test_04_PackingListDeleteLine(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
987 988 989 990 991
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
992 993 994 995 996
                      stepCheckSimulationConnected \
                      stepDeletePackingListLine \
                      stepCheckPackingListIsNotDivergent \
                      stepTic \
                      stepCheckSimulationDisconnected \
Sebastien Robin's avatar
Sebastien Robin committed
997 998 999
                      '
    sequence_list.addSequenceString(sequence_string)

1000
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1001

1002
  def test_05_SimulationChangeQuantity(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
1003 1004 1005 1006 1007
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
1008 1009 1010
                      stepModifySimulationLineQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
1011
                      stepAdoptPrevisionQuantity \
1012 1013 1014 1015
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithNewQuantityPrevision \
Sebastien Robin's avatar
Sebastien Robin committed
1016 1017 1018
                      '
    sequence_list.addSequenceString(sequence_string)

1019
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1020

1021 1022 1023 1024 1025 1026 1027 1028 1029
  def test_05a_SimulationChangeQuantityAndAcceptDecision(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
                      stepModifySimulationLineQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
1030
                      stepAcceptDecisionQuantity \
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckSimulationQuantityUpdated \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_05b_SimulationChangeQuantityForMergedLine(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_duplicated_lines + '\
                      stepModifySimulationLineQuantityForMergedLine \
                      stepTic \
                      stepCheckPackingListIsDiverged \
1049
                      stepAdoptPrevisionQuantity \
1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithNewQuantityPrevisionForMergedLine \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_05c_SimulationChangeQuantityAndAcceptDecisionForMergedLine(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_duplicated_lines + '\
                      stepModifySimulationLineQuantityForMergedLine \
                      stepTic \
                      stepCheckPackingListIsDiverged \
1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135
                      stepAcceptDecisionQuantity \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckSimulationQuantityUpdatedForMergedLine \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_05d_SimulationChangeResourceOnOneSimulationMovementForMergedLine(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_duplicated_lines + '\
                      stepCreateNotVariatedResource \
                      stepModifyOneSimulationLineResource \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevisionResource \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithDifferentResource \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_05e_SimulationUnifyResourceOnSimulationMovementsForNonMergedLines(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_two_lines + '\
                      stepModifySimulationLineResource \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAdoptPrevisionResource \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListLineWithSameResource \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_05f_SimulationChangeAndPartialAcceptDecision(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_duplicated_lines + '\
                      stepCreateNotVariatedResource \
                      stepModifySimulationLineQuantityForMergedLine \
                      stepModifyOneSimulationLineResource \
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAcceptDecisionQuantity \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepAcceptDecisionResource \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepUnifyStartDateWithDecision \
1136 1137 1138 1139 1140 1141 1142 1143 1144
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckSimulationQuantityUpdatedForMergedLine \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

1145
  def test_06_SimulationChangeStartDate(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
1146 1147 1148 1149 1150
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
1151 1152 1153
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
1154
                      stepUnifyStartDateWithPrevision \
1155 1156 1157
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
Sebastien Robin's avatar
Sebastien Robin committed
1158
                      '
1159
    # XXX Check if there is a new packing list created
Sebastien Robin's avatar
Sebastien Robin committed
1160 1161
    sequence_list.addSequenceString(sequence_string)

1162
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1163

1164
  def test_07_SimulationChangeStartDateWithTwoOrderLine(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
1165 1166 1167 1168
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
1169
    sequence_string = self.default_sequence_with_two_lines + '\
1170 1171 1172 1173
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195
                      stepUnifyStartDateWithPrevision \
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)

  def test_07a_SimulationChangeStartDateWithTwoOrderLine(self, quiet=quiet, run=run_all_test):
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence_with_two_lines + '\
                      stepModifyOneSimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepUnifyStartDateWithPrevision \
1196 1197 1198 1199
                      stepTic \
                      stepCheckPackingListIsNotDivergent \
                      stepCheckPackingListIsSolved \
                      stepCheckNewPackingListAfterStartDateAdopt \
Sebastien Robin's avatar
Sebastien Robin committed
1200 1201 1202 1203
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)

1204
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1205

1206
  def test_08_AddContainers(self, quiet=quiet, run=run_all_test):
Sebastien Robin's avatar
Sebastien Robin committed
1207 1208 1209 1210 1211
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
1212 1213 1214
                      stepAddPackingListContainer \
                      stepAddPackingListContainerLine \
                      stepSetContainerLineSmallQuantity \
1215
                      stepCheckContainerLineSmallQuantity \
1216 1217 1218 1219
                      stepCheckPackingListIsNotPacked \
                      stepSetContainerFullQuantity \
                      stepTic \
                      stepCheckPackingListIsPacked \
Sebastien Robin's avatar
Sebastien Robin committed
1220 1221 1222 1223
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)

1224
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1225

1226
  def test_09_AddContainersWithVariatedResources(self, quiet=quiet, run=run_all_test):
1227 1228 1229
    if not run: return
    sequence_list = SequenceList()

1230 1231
    # Test with a order with cells
    sequence_string = self.variated_default_sequence + '\
1232 1233 1234
                      stepAddPackingListContainer \
                      stepAddPackingListContainerLine \
                      stepSetContainerLineSmallQuantity \
1235
                      stepCheckContainerLineSmallQuantity \
1236 1237 1238 1239
                      stepCheckPackingListIsNotPacked \
                      stepSetContainerFullQuantity \
                      stepTic \
                      stepCheckPackingListIsPacked \
1240 1241 1242 1243 1244 1245
                      stepModifySimulationLineStartDate \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepUnifyStartDateWithPrevision \
                      stepTic \
1246 1247 1248
                      '
    # XXX Check if there is a new packing list created
    sequence_list.addSequenceString(sequence_string)
1249

1250
    sequence_list.play(self, quiet=quiet)
1251

1252
  def test_10_PackingListIncreaseQuantity(self, quiet=quiet, run=run_all_test):
1253
    """
1254 1255 1256 1257 1258 1259 1260 1261
    - 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.
1262 1263 1264 1265 1266 1267
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
1268 1269
                      stepIncreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
1270 1271
                      stepTic \
                      stepCheckPackingListIsDiverged \
1272 1273
                      stepSplitAndDeferPackingList \
                      stepTic \
1274 1275 1276
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepCheckPackingListNotSolved \
1277 1278 1279
                      '
    sequence_list.addSequenceString(sequence_string)

1280
    sequence_list.play(self, quiet=quiet)
Sebastien Robin's avatar
Sebastien Robin committed
1281

1282 1283
  def test_11_PackingListDecreaseTwoTimesQuantityAndUpdateDelivery(self,
                                               quiet=quiet, run=run_all_test):
1284 1285 1286 1287 1288 1289 1290 1291 1292 1293
    """
      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 + '\
1294 1295
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
1296 1297
                      stepTic \
                      stepCheckPackingListIsDiverged \
1298 1299 1300 1301 1302 1303
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplitted \
                      stepDecreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
1304 1305
                      stepTic \
                      stepCheckPackingListIsDiverged \
1306 1307 1308
                      stepSplitAndDeferPackingList \
                      stepTic \
                      stepCheckNewPackingListIsDivergent \
1309
                      stepNewPackingListAdoptPrevisionQuantity \
1310 1311 1312
                      stepTic \
                      stepCheckPackingListIsSolved \
                      stepCheckPackingListSplittedTwoTimes \
1313 1314 1315
                      '
    sequence_list.addSequenceString(sequence_string)

1316
    sequence_list.play(self, quiet=quiet)
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
  def test_SplitAndDeferDoNothing(self, quiet=quiet, run=run_all_test):
    """
    Use split & defer to solve a divergence, but choose do nothing for all
    lines.
    """
    if not run: return
    sequence_list = SequenceList()

    # Test with a simply order without cell
    sequence_string = self.default_sequence + '\
                      stepIncreasePackingListLineQuantity \
                      stepCheckPackingListIsCalculating \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepSplitAndDeferDoNothingPackingList \
                      stepTic \
                      stepCheckPackingListIsDiverged \
                      stepCheckPackingListIsDivergent \
                      stepCheckPackingListNotSolved \
                      '
    sequence_list.addSequenceString(sequence_string)

    sequence_list.play(self, quiet=quiet)


1343
  def test_12_PackingListLineChangeResource(self, quiet=quiet, run=run_all_test):
1344 1345 1346 1347 1348 1349 1350 1351
    """
    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 + '\
1352 1353 1354 1355 1356
                      stepCreateNotVariatedResource \
                      stepChangePackingListLineResource \
                      stepCheckPackingListIsCalculating \
                      stepTic \
                      stepCheckPackingListIsDivergent \
1357 1358 1359
                      '
    sequence_list.addSequenceString(sequence_string)

1360
    sequence_list.play(self, quiet=quiet)
1361

1362
  def test_14_PackingListHavePriceCurrencyCategory(self, quiet=quiet,
1363
                                                   run=run_all_test):
1364 1365 1366 1367
    """Deliveries must have a price currency category. #252
    """
    if not run:
      return
1368 1369 1370
    pl = self.getPortal().getDefaultModule(self.packing_list_portal_type
               ).newContent(portal_type=self.packing_list_portal_type)
    self.failUnless(hasattr(pl, 'getPriceCurrency'))
1371

Jérome Perrin's avatar
Jérome Perrin committed
1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388
  def test_PackingList_viewAsODT(self):
    # tests packing list printout
    resource = self.portal.getDefaultModule(
        self.resource_portal_type).newContent(
                    portal_type=self.resource_portal_type,
                    title='Resource',)
    client = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Client')
    vendor = self.portal.organisation_module.newContent(
                              portal_type='Organisation', title='Vendor')
    packing_list = self.portal.getDefaultModule(self.packing_list_portal_type).newContent(
                              portal_type=self.packing_list_portal_type,
                              title='Packing List',
                              source_value=vendor,
                              source_section_value=vendor,
                              destination_value=client,
                              destination_section_value=client)
1389 1390
    line = packing_list.newContent(
                            portal_type=self.packing_list_line_portal_type,
Jérome Perrin's avatar
Jérome Perrin committed
1391 1392 1393 1394
                            resource_value=resource,
                            quantity=10,
                            price=3)
    packing_list.confirm()
1395
    transaction.commit()
Jérome Perrin's avatar
Jérome Perrin committed
1396
    self.tic()
1397

Jérome Perrin's avatar
Jérome Perrin committed
1398 1399 1400 1401 1402 1403
    odt = packing_list.PackingList_viewAsODT()
    from Products.ERP5OOo.tests.utils import Validator
    odf_validator = Validator()
    err_list = odf_validator.validate(odt)
    if err_list:
      self.fail(''.join(err_list))
1404

Fabien Morin's avatar
typo  
Fabien Morin committed
1405
  def test_15_CheckBuilderCanBeCalledTwiceSafely(self):
1406 1407 1408 1409 1410
    """
    Builder design should allows to call the build method as many times as we 
    want. Make sure that we will not have duplicated packing list if build is 
    called several times.
    """
Fabien Morin's avatar
typo  
Fabien Morin committed
1411
    delivery_builder = getattr(self.getPortalObject().portal_deliveries,
1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435
                               self.delivery_builder_id)
 
    def doNothing(self, *args, **kw):
      pass
    original_delivery_builder_build =  delivery_builder.__class__.build

    try:
      # We patch the delivery builder to make sure that it will not be
      # called by activities
      delivery_builder.__class__.build = doNothing
      sequence_list = SequenceList()

      # Test with a simply order without cell
      sequence_string = self.confirmed_order_without_packing_list
      sequence_list.addSequenceString(sequence_string)
      sequence_list.play(self)

      # Now restore the build method and make sure first call returns document
      delivery_builder.__class__.build = original_delivery_builder_build
      self.assertTrue(len(delivery_builder.build()) > 0)
      # The second call should returns empty result even if tic not called
      self.assertTrue(len(delivery_builder.build()) ==  0)
    finally:
      delivery_builder.build = original_delivery_builder_build
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
  def test_16_simulation_reindexation_on_cancel(self):
    self.organisation_portal_type = 'Organisation'
    self.resource_portal_type = 'Product'

    packing_list_module = self.portal.getDefaultModule(
        portal_type=self.packing_list_portal_type)
    organisation_module = self.portal.getDefaultModule(
        portal_type=self.organisation_portal_type)
    resource_module = self.portal.getDefaultModule(
        portal_type=self.resource_portal_type)
    source = organisation_module.newContent(
        portal_type=self.organisation_portal_type)
    destination = organisation_module.newContent(
        portal_type=self.organisation_portal_type)
    resource = resource_module.newContent(
        portal_type=self.resource_portal_type)

    packing_list = packing_list_module.newContent(
        portal_type=self.packing_list_portal_type,
        source_value=source,
        destination_value=destination,
        start_date=DateTime())
    packing_list_line = packing_list.newContent(
        portal_type=self.packing_list_line_portal_type,
        resource_value=resource,
        quantity=1)
    packing_list.confirm()
    transaction.commit()
    self.tic()
    self.assertEqual('confirmed', packing_list.getSimulationState())
    simulation_movement = packing_list_line.getDeliveryRelatedValue(
        portal_type='Simulation Movement')
    self.assertEqual('confirmed', simulation_movement.getSimulationState())
    packing_list.cancel()
    transaction.commit()
    self.tic()
    self.assertEqual('cancelled', packing_list.getSimulationState())
    self.assertEqual('cancelled', simulation_movement.getSimulationState())

1476

1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489
class TestPurchasePackingListMixin(TestPackingListMixin):
  """Mixing class with steps to test purchase packing lists.
  """
  order_portal_type = 'Purchase Order'
  order_line_portal_type = 'Purchase Order Line'
  order_cell_portal_type = 'Purchase Order Cell'
  packing_list_portal_type = 'Purchase Packing List'
  packing_list_line_portal_type = 'Purchase Packing List Line'
  packing_list_cell_portal_type = 'Purchase Packing List Cell'
  delivery_builder_id = 'purchase_packing_list_builder'
  container_portal_type = None
  container_line_portal_type = None
  container_cell_portal_type = None
1490

1491 1492 1493 1494 1495 1496 1497
  # all steps related to packing and container does not apply on purchase
  def ignored_step(self, **kw):
    return
  stepAddPackingListContainer = ignored_step
  stepDefineNewPackingListContainer = ignored_step
  stepAddPackingListContainerLine = ignored_step
  stepSetContainerLineSmallQuantity = ignored_step
1498
  stepCheckContainerLineSmallQuantity = ignored_step
1499 1500 1501 1502 1503 1504 1505 1506 1507 1508
  stepSetContainerLineFullQuantity = ignored_step
  stepSetContainerFullQuantity = ignored_step
  stepCheckPackingListIsNotPacked = ignored_step
  stepCheckPackingListIsPacked = ignored_step
  stepCheckNewPackingListIsPacked = ignored_step


class TestPurchasePackingList(TestPurchasePackingListMixin, TestPackingList):
  """Tests for purchase packing list.
  """
1509 1510 1511
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestPackingList))
1512
  suite.addTest(unittest.makeSuite(TestPurchasePackingList))
1513
  return suite