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

import unittest

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from zLOG import LOG
from Products.ERP5Type.tests.Sequence import SequenceList
from Products.CMFCore.utils import getToolByName
from testProductionOrder import TestProductionOrderMixin
from testPackingList import TestPackingListMixin

39
class TestProductionPackingReportListMixin(TestProductionOrderMixin, TestPackingListMixin, \
40 41 42 43 44 45 46 47 48 49
                          ERP5TypeTestCase):
  """Mixin for testing Production Packing Lists and Production Reports"""

  def modifyPackingListState(self, transition_name,
                             sequence,packing_list=None):
    """ calls the workflow for the packing list """
    if packing_list is None:
      packing_list = sequence.get('packing_list')
    packing_list.portal_workflow.doActionFor(packing_list, transition_name)

50 51 52 53 54 55 56 57 58
  def stepSetReadyProducedDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_delivery_packing_list')
    self.modifyPackingListState('set_ready_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'ready')

  def stepStartProducedDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_delivery_packing_list')
    self.modifyPackingListState('start_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'started')
59

60 61 62 63 64 65 66 67 68 69 70 71 72
  def stepStopProducedDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_delivery_packing_list')
    self.modifyPackingListState('stop_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'stopped')

  def stepDeliverProducedDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_delivery_packing_list')
    self.modifyPackingListState('deliver_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'delivered')

  def stepSetReadySupplyDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')
    self.modifyPackingListState('set_ready_action', sequence=sequence, packing_list=packing_list)
73 74
    self.assertEquals(packing_list.getSimulationState(), 'ready')

75 76 77
  def stepStartSupplyDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')
    self.modifyPackingListState('start_action', sequence=sequence, packing_list=packing_list)
78 79
    self.assertEquals(packing_list.getSimulationState(), 'started')

80 81 82
  def stepStopSupplyDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')
    self.modifyPackingListState('stop_action', sequence=sequence, packing_list=packing_list)
83 84
    self.assertEquals(packing_list.getSimulationState(), 'stopped')

85 86 87
  def stepDeliverSupplyDeliveryPackingList(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')
    self.modifyPackingListState('deliver_action', sequence=sequence, packing_list=packing_list)
88 89
    self.assertEquals(packing_list.getSimulationState(), 'delivered')

90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131
  def stepSetReadyProducedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')
    self.modifyPackingListState('set_ready_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'ready')

  def stepStartProducedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')
    self.modifyPackingListState('start_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'started')

  def stepStopProducedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')
    self.modifyPackingListState('stop_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'stopped')

  def stepDeliverProducedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')
    self.modifyPackingListState('deliver_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'delivered')

  def stepSetReadyConsumedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')
    self.modifyPackingListState('set_ready_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'ready')

  def stepStartConsumedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')
    self.modifyPackingListState('start_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'started')

  def stepStopConsumedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')
    self.modifyPackingListState('stop_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'stopped')

  def stepDeliverConsumedReport(self, sequence=None, sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')
    self.modifyPackingListState('deliver_action', sequence=sequence, packing_list=packing_list)
    self.assertEquals(packing_list.getSimulationState(), 'delivered')

  def stepCheckSourcingDeliverySimulation(self, sequence=None, \
                                    sequence_list=None, **kw):
132
    """
133
      Hardcoded delivery checks
134
    """
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157
    self.stepCheckSourcingSimulation(sequence,sequence_list,**kw)

    produced_movement = sequence.get('produced_movement')
    operation_movement = sequence.get('operation_movement')
    component_movement = sequence.get('component_movement')
    supply_movement = sequence.get('supply_movement')
    produced_delivery_movement = sequence.get('produced_delivery_movement')

    produced_delivery_packing_list = produced_delivery_movement.getDeliveryValue().getParentValue()
    supply_delivery_packing_list = supply_movement.getDeliveryValue().getParentValue()

    produced_report = produced_movement.getDeliveryValue().getParentValue()

    operation_report = operation_movement.getDeliveryValue().getParentValue()
    component_report = component_movement.getDeliveryValue().getParentValue()
    self.assertEquals(operation_report, component_report)
    consumed_report = operation_report

    # checks that simulations are same
    # TODO: resources, quantities, dates, ...
    self.assertEquals(
      produced_delivery_movement.getSimulationState(),
      produced_delivery_packing_list.getSimulationState()
158 159
    )

160 161 162 163 164 165 166 167 168 169 170 171 172 173
    self.assertEquals(
      supply_movement.getSimulationState(),
      supply_delivery_packing_list.getSimulationState()
    )
    
    self.assertEquals(
      produced_movement.getSimulationState(),
      produced_report.getSimulationState()
    )

    self.assertEquals(
      component_movement.getSimulationState(),
      consumed_report.getSimulationState()
    )
174

175 176 177 178 179 180 181 182 183 184 185 186 187
    self.assertEquals(
      operation_movement.getSimulationState(),
      consumed_report.getSimulationState()
    )

    sequence.edit(
      produced_delivery_packing_list = produced_delivery_packing_list,
      supply_delivery_packing_list = supply_delivery_packing_list,
      produced_report = produced_report,
      consumed_report = consumed_report,
    )

  def stepCheckProducedDeliveryPackingListConfirmed(self, sequence=None, \
188
                                    sequence_list=None, **kw):
189 190 191 192 193 194
    packing_list = sequence.get('produced_delivery_packing_list')

    self.assertEquals(
      'confirmed',
      packing_list.getSimulationState()
    )
195

196
  def stepCheckProducedDeliveryPackingListDelivered(self, sequence=None, \
197
                                    sequence_list=None, **kw):
198
    packing_list = sequence.get('produced_delivery_packing_list')
199

200 201 202 203
    self.assertEquals(
      'delivered',
      packing_list.getSimulationState()
    )
204

205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239
  def stepCheckSupplyDeliveryPackingListDelivered(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')

    self.assertEquals(
      'delivered',
      packing_list.getSimulationState()
    )

  def stepCheckProducedReportDelivered(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')

    self.assertEquals(
      'delivered',
      packing_list.getSimulationState()
    )

  def stepCheckConsumedReportDelivered(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')

    self.assertEquals(
      'delivered',
      packing_list.getSimulationState()
    )

  def stepCheckProducedDeliveryPackingListSolved(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('produced_delivery_packing_list')

    self.assertEquals(
      'solved',
      packing_list.getCausalityState()
    )
240

241 242 243
  def stepCheckSupplyDeliveryPackingListConfirmed(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')
244

245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279
    self.assertEquals(
      'confirmed',
      packing_list.getSimulationState()
    )

  def stepCheckSupplyDeliveryPackingListSolved(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('supply_delivery_packing_list')

    self.assertEquals(
      'solved',
      packing_list.getCausalityState()
    )

  def stepCheckProducedReportConfirmed(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')

    self.assertEquals(
      'confirmed',
      packing_list.getSimulationState()
    )

  def stepCheckProducedReportSolved(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('produced_report')

    self.assertEquals(
      'solved',
      packing_list.getCausalityState()
    )

  def stepCheckConsumedReportConfirmed(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')
280

281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301
    self.assertEquals(
      'confirmed',
      packing_list.getSimulationState()
    )

  def stepCheckConsumedReportSolved(self, sequence=None, \
                                    sequence_list=None, **kw):
    packing_list = sequence.get('consumed_report')

    self.assertEquals(
      'solved',
      packing_list.getCausalityState()
    )

class TestProductionDelivery(TestProductionPackingReportListMixin):
  """Test Production Packing Lists and Reports, mostly based on Production Orders"""

  run_all_test = 1

  def test_01_sourcingDelivery(self, quiet=0, 
                                          run=run_all_test):
302
    """
303
    Test for sourcing type of delivery (Production Report and Production Packing Lists).
304 305 306
    """
    if not run: return
    sequence_list = SequenceList()
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
    # Check states of deliveries, just after order confirmation
    sequence_string = self.SOURCING_ORDER_SEQUENCE + '\
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListConfirmed \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListConfirmed \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportConfirmed \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportConfirmed \
                      CheckConsumedReportSolved\
                      \
                      '
324 325
    sequence_list.addSequenceString(sequence_string)

326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426
    # Test when packing list are delivered one by one
    # Note: I (Luke) know, that below sequence is long
    #       but I wanted to be sure, that full production
    #       process is doable.
    sequence_string = self.SOURCING_ORDER_SEQUENCE + '\
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListConfirmed \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListConfirmed \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportConfirmed \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportConfirmed \
                      CheckConsumedReportSolved\
                      \
                      SetReadyProducedDeliveryPackingList \
                      StartProducedDeliveryPackingList \
                      StopProducedDeliveryPackingList \
                      DeliverProducedDeliveryPackingList \
                      Tic \
                      \
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListDelivered \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListConfirmed \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportConfirmed \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportConfirmed \
                      CheckConsumedReportSolved\
                      \
                      SetReadySupplyDeliveryPackingList \
                      StartSupplyDeliveryPackingList \
                      StopSupplyDeliveryPackingList \
                      DeliverSupplyDeliveryPackingList \
                      Tic \
                      \
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListDelivered \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListDelivered \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportConfirmed \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportConfirmed \
                      CheckConsumedReportSolved\
                      \
                      SetReadyProducedReport \
                      StartProducedReport \
                      StopProducedReport \
                      DeliverProducedReport \
                      Tic \
                      \
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListDelivered \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListDelivered \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportDelivered \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportConfirmed \
                      CheckConsumedReportSolved\
                      \
                      SetReadyConsumedReport \
                      StartConsumedReport \
                      StopConsumedReport \
                      DeliverConsumedReport \
                      Tic \
                      \
                      CheckSourcingDeliverySimulation \
                      \
                      CheckProducedDeliveryPackingListDelivered \
                      CheckProducedDeliveryPackingListSolved\
                      \
                      CheckSupplyDeliveryPackingListDelivered \
                      CheckSupplyDeliveryPackingListSolved\
                      \
                      CheckProducedReportDelivered \
                      CheckProducedReportSolved\
                      \
                      CheckConsumedReportDelivered \
                      CheckConsumedReportSolved\
                      \
                      '
    sequence_list.addSequenceString(sequence_string)
427

428 429
    # TODO: check case of solving divergence on every delivery
    sequence_list.play(self)
430 431 432

def test_suite():
  suite = unittest.TestSuite()
433
  suite.addTest(unittest.makeSuite(TestProductionDelivery))
434
  return suite