testBPMCore.py 46.7 KB
Newer Older
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
1
# -*- coding: utf-8 -*-
2 3 4
##############################################################################
# Copyright (c) 2009 Nexedi SA and Contributors. All Rights Reserved.
#          Łukasz Nowak <luke@nexedi.com>
5
#          Yusuke Muraoka <yusuke@nexedi.com>
6
#          Fabien Morin <fabien@nexedi.com>
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
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################

import unittest
import transaction

from Products.ERP5Type.tests.ERP5TypeTestCase import ERP5TypeTestCase
from DateTime import DateTime
36
from Products.ERP5Type.tests.utils import createZODBPythonScript, reindex
37
from Products.ERP5.tests.utils import newSimulationExpectedFailure
38 39

class TestBPMMixin(ERP5TypeTestCase):
40
  """Skeletons for tests which depend on BPM"""
41 42

  def getBusinessTemplateList(self):
43 44 45
    return ('erp5_base', 'erp5_pdm', 'erp5_simulation', 'erp5_trade',
            'erp5_accounting', 'erp5_invoicing', 'erp5_simplified_invoicing',
            'erp5_simulation_test')
46 47

  business_process_portal_type = 'Business Process'
48
  business_link_portal_type = 'Business Link'
49
  trade_model_path_portal_type = 'Trade Model Path'
50 51
  default_business_process = \
    'business_process_module/erp5_default_business_process'
52

53 54 55
  normal_resource_use_category_list = ['normal']
  invoicing_resource_use_category_list = ['discount', 'tax']

56 57
  def createCategoriesInCategory(self, category, category_id_list):
    for category_id in category_id_list:
58
      if not category.hasObject(category_id):
59 60
        category.newContent(category_id,
          title=category_id.replace('_', ' ').title())
61 62 63

  @reindex
  def createCategories(self):
64
    category_tool = self.portal.portal_categories
65
    self.createCategoriesInCategory(category_tool.base_amount, ['discount',
66
      'tax', 'total_tax', 'total_discount', 'total'])
67 68 69 70
    self.createCategoriesInCategory(category_tool.use,
        self.normal_resource_use_category_list + \
            self.invoicing_resource_use_category_list)
    self.createCategoriesInCategory(category_tool.trade_phase, ['default',])
71 72
    self.createCategoriesInCategory(category_tool.trade_phase.default,
        ['accounting', 'delivery', 'invoicing', 'discount', 'tax', 'payment'])
73
    self.createCategoriesInCategory(category_tool.trade_state,
74
        ['ordered', 'invoiced', 'delivered', 'taxed',
75
         'state_a', 'state_b', 'state_c', 'state_d', 'state_e'])
76 77 78 79
    self.createCategoriesInCategory(category_tool, ('tax_range', 'tax_share'))
    self.createCategoriesInCategory(category_tool.tax_range,
                                    ('0_200', '200_inf'))
    self.createCategoriesInCategory(category_tool.tax_share, 'AB')
80 81

  @reindex
82
  def createBusinessProcess(self, **kw):
83
    module = self.portal.getDefaultModule(
84
        portal_type=self.business_process_portal_type,)
85
    business_process =  module.newContent(
86
      portal_type=self.business_process_portal_type,
87
      specialise=self.default_business_process)
88
    self.business_process = business_process
89
    business_process._edit(**kw)
90 91
    self.createTradeModelPath(business_process,
      reference='default_path',
92
      trade_phase_value_list=('default/discount', 'default/tax'),
93
      trade_date='trade_phase/default/invoicing')
94 95 96 97
    # A trade model path already exist for root simulation movements
    # (Accounting Transaction Root Simulation Rule).
    # The ones we are creating are for Invoice Transaction Simulation Rule
    # so we add a test on the portal type of the input movement.
98 99
    kw = dict(business_process=business_process,
              trade_phase='default/accounting',
100
              trade_date='trade_phase/default/invoicing',
101 102
              membership_criterion_base_category='resource_use',
              criterion_property_dict={'portal_type': 'Simulation Movement'})
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 132 133 134 135 136 137 138 139
    self.createTradeModelPath(reference='acounting_tax1',
      efficiency=-1,
      source_value=self.receivable_account,
      destination_value=self.payable_account,
      membership_criterion_category='resource_use/use/tax',
      **kw)
    self.createTradeModelPath(reference='acounting_tax2',
      efficiency=1,
      source_value=self.collected_tax_account,
      destination_value=self.refundable_tax_account,
      membership_criterion_category='resource_use/use/tax',
      **kw)
    self.createTradeModelPath(reference='acounting_discount1',
      efficiency=-1,
      source_value=self.receivable_account,
      destination_value=self.payable_account,
      membership_criterion_category='resource_use/use/discount',
      **kw)
    self.createTradeModelPath(reference='acounting_discount2',
      efficiency=1,
      source_value=self.income_account,
      destination_value=self.expense_account,
      membership_criterion_category='resource_use/use/discount',
      **kw)
    self.createTradeModelPath(reference='acounting_normal1',
      efficiency=-1,
      source_value=self.receivable_account,
      destination_value=self.payable_account,
      membership_criterion_category='resource_use/use/normal',
      **kw)
    self.createTradeModelPath(reference='acounting_normal2',
      efficiency=1,
      source_value=self.income_account,
      destination_value=self.expense_account,
      membership_criterion_category='resource_use/use/normal',
      **kw)
    return business_process
140 141

  @reindex
142
  def createBusinessLink(self, business_process=None, **kw):
143
    if business_process is None:
144
      business_process = self.createBusinessProcess()
145 146 147
    business_link = business_process.newContent(
      portal_type=self.business_link_portal_type, **kw)
    return business_link
148

149 150
  def createTradeModelPath(self, business_process=None,
                           criterion_property_dict={}, **kw):
151 152
    if business_process is None:
      business_process = self.createBusinessProcess()
153
    trade_model_path = business_process.newContent(
154
      portal_type=self.trade_model_path_portal_type, **kw)
155 156 157 158 159
    if criterion_property_dict:
      trade_model_path._setCriterionPropertyList(tuple(criterion_property_dict))
      for property, identity in criterion_property_dict.iteritems():
        trade_model_path.setCriterion(property, identity)
    return trade_model_path
160

161 162 163 164 165 166
  def createMovement(self):
    # returns a movement for testing
    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule')
    return applied_rule.newContent(portal_type='Simulation Movement')

167 168 169 170 171 172 173
  def createAndValidateAccount(self, account_id, account_type):
    account_module = self.portal.account_module
    account = account_module.newContent(portal_type='Account',
          title=account_id,
          account_type=account_type)
    self.assertNotEqual(None, account.getAccountTypeValue())
    account.validate()
174
    return account
175

176
  def createAndValidateAccounts(self):
177 178 179 180 181 182 183 184 185 186 187 188
    self.receivable_account = self.createAndValidateAccount('receivable',
        'asset/receivable')
    self.payable_account = self.createAndValidateAccount('payable',
        'liability/payable')
    self.income_account = self.createAndValidateAccount('income', 'income')
    self.expense_account = self.createAndValidateAccount('expense', 'expense')
    self.collected_tax_account = self.createAndValidateAccount(
        'collected_tax', 'liability/payable/collected_vat')
    self.refundable_tax_account = self.createAndValidateAccount(
        'refundable_tax',
        'asset/receivable/refundable_vat')

189
  def afterSetUp(self):
190
    self.validateRules()
191
    self.createCategories()
192
    self.createAndValidateAccounts()
193
    self.stepTic()
194

195

196 197
class TestBPMImplementation(TestBPMMixin):
  """Business Process implementation tests"""
198
  def test_BusinessProcess_getBusinessLinkValueList(self):
199 200
    business_process = self.createBusinessProcess()

201 202
    accounting_business_link = business_process.newContent(
        portal_type=self.business_link_portal_type,
203 204
        trade_phase='default/accounting')

205 206
    delivery_business_link = business_process.newContent(
        portal_type=self.business_link_portal_type,
207 208
        trade_phase='default/delivery')

209 210
    accounting_delivery_business_link = business_process.newContent(
        portal_type=self.business_link_portal_type,
211 212 213 214 215
        trade_phase=('default/accounting', 'default/delivery'))

    self.stepTic()

    self.assertSameSet(
216
      (accounting_business_link, accounting_delivery_business_link),
217
      business_process.getBusinessLinkValueList(trade_phase='default/accounting')
218 219 220
    )

    self.assertSameSet(
221
      (delivery_business_link, accounting_delivery_business_link),
222
      business_process.getBusinessLinkValueList(trade_phase='default/delivery')
223 224 225
    )

    self.assertSameSet(
226 227
      (accounting_delivery_business_link, delivery_business_link,
        accounting_business_link),
228
      business_process.getBusinessLinkValueList(trade_phase=('default/delivery',
229 230 231
        'default/accounting'))
    )

232
  def test_BusinessLinkStandardCategoryAccessProvider(self):
233 234 235
    source_node = self.portal.organisation_module.newContent(
                    portal_type='Organisation')
    source_section_node = self.portal.organisation_module.newContent(
236
                    portal_type='Organisation')
237 238 239 240 241
    business_link = self.createBusinessLink()
    business_link.setSourceValue(source_node)
    business_link.setSourceSectionValue(source_section_node)
    self.assertEquals([source_node], business_link.getSourceValueList())
    self.assertEquals([source_node.getRelativeUrl()], business_link.getSourceList())
242
    self.assertEquals(source_node.getRelativeUrl(),
243
        business_link.getSource(default='something'))
244

245 246 247 248
  def test_EmptyBusinessLinkStandardCategoryAccessProvider(self):
    business_link = self.createBusinessLink()
    self.assertEquals(None, business_link.getSourceValue())
    self.assertEquals(None, business_link.getSource())
249
    self.assertEquals('something',
250
        business_link.getSource(default='something'))
251

Sebastien Robin's avatar
Sebastien Robin committed
252
  def test_BusinessPathDynamicCategoryAccessProvider(self):
253 254 255
    source_node = self.portal.organisation_module.newContent(
                    portal_type='Organisation')
    source_section_node = self.portal.organisation_module.newContent(
256
                    portal_type='Organisation')
Sebastien Robin's avatar
Sebastien Robin committed
257 258
    business_path = self.createTradeModelPath()
    business_path.setSourceMethodId('TradeModelPath_getDefaultSourceList')
259 260

    context_movement = self.createMovement()
261 262
    context_movement.setSourceValue(source_node)
    context_movement.setSourceSectionValue(source_section_node)
Sebastien Robin's avatar
Sebastien Robin committed
263
    self.assertEquals(None, business_path.getSourceValue())
264
    self.assertEquals([source_node],
Sebastien Robin's avatar
Sebastien Robin committed
265
                      business_path.getSourceValueList(context=context_movement))
266
    self.assertEquals([source_node.getRelativeUrl()],
Sebastien Robin's avatar
Sebastien Robin committed
267
                      business_path.getSourceList(context=context_movement))
Łukasz Nowak's avatar
Łukasz Nowak committed
268
    self.assertEquals(source_node.getRelativeUrl(),
Sebastien Robin's avatar
Sebastien Robin committed
269
      business_path.getSource(context=context_movement, default='something'))
270

Sebastien Robin's avatar
Sebastien Robin committed
271
  def test_BusinessPathDynamicCategoryAccessProviderBusinessLinkPrecedence(self):
272 273 274 275
    movement_node = self.portal.organisation_module.newContent(
                    portal_type='Organisation')
    path_node = self.portal.organisation_module.newContent(
                    portal_type='Organisation')
Sebastien Robin's avatar
Sebastien Robin committed
276 277 278
    business_path = self.createTradeModelPath()
    business_path.setSourceMethodId('TradeModelPath_getDefaultSourceList')
    business_path.setSourceValue(path_node)
279 280 281

    context_movement = self.createMovement()
    context_movement.setSourceValue(movement_node)
Sebastien Robin's avatar
Sebastien Robin committed
282
    self.assertEquals(path_node, business_path.getSourceValue())
283
    self.assertEquals(path_node,
Sebastien Robin's avatar
Sebastien Robin committed
284
                      business_path.getSourceValue(context=context_movement))
285
    self.assertEquals([path_node],
Sebastien Robin's avatar
Sebastien Robin committed
286
                      business_path.getSourceValueList(context=context_movement))
287

Sebastien Robin's avatar
Sebastien Robin committed
288 289 290
  def test_BusinessPathDynamicCategoryAccessProviderEmptyMovement(self):
    business_path = self.createTradeModelPath()
    business_path.setSourceMethodId('TradeModelPath_getDefaultSourceList')
291 292

    context_movement = self.createMovement()
Sebastien Robin's avatar
Sebastien Robin committed
293
    self.assertEquals(None, business_path.getSourceValue())
294
    self.assertEquals(None,
Sebastien Robin's avatar
Sebastien Robin committed
295
                      business_path.getSourceValue(context=context_movement))
296
    self.assertEquals(None,
Sebastien Robin's avatar
Sebastien Robin committed
297
                      business_path.getSource(context=context_movement))
298
    self.assertEquals('something',
Sebastien Robin's avatar
Sebastien Robin committed
299
      business_path.getSource(context=context_movement, default='something'))
300

301 302
  def test_BusinessState_getRemainingTradePhaseList(self):
    """
303 304
    This test case is described for what trade_phase is remaining after the
    given business link.
305 306
    """
    # define business process
307
    category_tool = self.getCategoryTool()
308
    business_process = self.createBusinessProcess()
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336
    business_link_order = self.createBusinessLink(business_process,
                                 title='order', id='order',
                                 trade_phase='default/order')
    business_link_deliver = self.createBusinessLink(business_process,
                                 title='deliver', id='deliver',
                                 trade_phase='default/delivery')
    business_link_invoice = self.createBusinessLink(business_process,
                                 title='invoice', id='invoice',
                                 trade_phase='default/invoicing')
    trade_state = category_tool.trade_state
    business_link_order.setSuccessorValue(trade_state.ordered)
    business_link_deliver.setPredecessorValue(trade_state.ordered)
    business_link_deliver.setSuccessorValue(trade_state.delivered)
    business_link_invoice.setPredecessorValue(trade_state.delivered)
    business_link_invoice.setSuccessorValue(trade_state.invoiced)

    trade_phase = category_tool.trade_phase.default

    self.assertEquals([trade_phase.delivery,
                       trade_phase.invoicing],
                      business_process.getRemainingTradePhaseList(
                       business_process.order))
    self.assertEquals([trade_phase.invoicing],
                      business_process.getRemainingTradePhaseList(
                       business_process.deliver))
    self.assertEquals([],
                      business_process.getRemainingTradePhaseList(
                       business_process.invoice))
337

338
  @newSimulationExpectedFailure
339
  def test_BusinessLink_calculateExpectedDate(self):
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
    """
    This test case is described for what start/stop date is expected on
    each path by explanation.
    In this case, root explanation is path of between "b" and "d", and
    lead time and wait time is set on each path.
    ("l" is lead time, "w" is wait_time)

    Each path must calculate most early day from getting most longest
    path in the simulation.

    "referential_date" represents for which date have to get of explanation from reality.

                  (root_explanation)
        l:2, w:1         l:3, w:1       l:4, w:2
    a ------------ b -------------- d -------------- e
                    \             /
                     \           /
             l:2, w:1 \         / l:3, w:0
                       \       /
                        \     /
                         \   /
                          \ /
                           c
    """
    # define business process
365
    category_tool = self.getCategoryTool()
366
    business_process = self.createBusinessProcess()
367 368 369 370 371
    business_link_a_b = self.createBusinessLink(business_process)
    business_link_b_c = self.createBusinessLink(business_process)
    business_link_b_d = self.createBusinessLink(business_process)
    business_link_c_d = self.createBusinessLink(business_process)
    business_link_d_e = self.createBusinessLink(business_process)
372 373 374 375 376
    business_state_a = category_tool.trade_state.state_a
    business_state_b = category_tool.trade_state.state_b
    business_state_c = category_tool.trade_state.state_c
    business_state_d = category_tool.trade_state.state_d
    business_state_e = category_tool.trade_state.state_e
377 378 379 380 381 382 383 384 385 386
    business_link_a_b.setPredecessorValue(business_state_a)
    business_link_b_c.setPredecessorValue(business_state_b)
    business_link_b_d.setPredecessorValue(business_state_b)
    business_link_c_d.setPredecessorValue(business_state_c)
    business_link_d_e.setPredecessorValue(business_state_d)
    business_link_a_b.setSuccessorValue(business_state_b)
    business_link_b_c.setSuccessorValue(business_state_c)
    business_link_b_d.setSuccessorValue(business_state_d)
    business_link_c_d.setSuccessorValue(business_state_d)
    business_link_d_e.setSuccessorValue(business_state_e)
387 388

    business_process.edit(referential_date='stop_date')
389 390 391 392 393
    business_link_a_b.edit(title='a_b', lead_time=2, wait_time=1)
    business_link_b_c.edit(title='b_c', lead_time=2, wait_time=1)
    business_link_b_d.edit(title='b_d', lead_time=3, wait_time=1)
    business_link_c_d.edit(title='c_d', lead_time=3, wait_time=0)
    business_link_d_e.edit(title='d_e', lead_time=4, wait_time=2)
394 395

    # root explanation
396
    business_link_b_d.edit(deliverable=True)
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413
    self.stepTic()

    """
    Basic test, lead time of reality and simulation are consistent.
    """
    class Mock:
      def __init__(self, date):
        self.date = date
      def getStartDate(self):
        return self.date
      def getStopDate(self):
        return self.date + 3 # lead time of reality

    base_date = DateTime('2009/04/01 GMT+9')
    mock = Mock(base_date)

    # root explanation.
414 415
    self.assertEquals(business_link_b_d.getExpectedStartDate(mock), DateTime('2009/04/01 GMT+9'))
    self.assertEquals(business_link_b_d.getExpectedStopDate(mock), DateTime('2009/04/04 GMT+9'))
416 417

    # assertion for each path without root explanation.
418 419 420 421 422 423 424 425
    self.assertEquals(business_link_a_b.getExpectedStartDate(mock), DateTime('2009/03/27 GMT+9'))
    self.assertEquals(business_link_a_b.getExpectedStopDate(mock), DateTime('2009/03/29 GMT+9'))
    self.assertEquals(business_link_b_c.getExpectedStartDate(mock), DateTime('2009/03/30 GMT+9'))
    self.assertEquals(business_link_b_c.getExpectedStopDate(mock), DateTime('2009/04/01 GMT+9'))
    self.assertEquals(business_link_c_d.getExpectedStartDate(mock), DateTime('2009/04/01 GMT+9'))
    self.assertEquals(business_link_c_d.getExpectedStopDate(mock), DateTime('2009/04/04 GMT+9'))
    self.assertEquals(business_link_d_e.getExpectedStartDate(mock), DateTime('2009/04/06 GMT+9'))
    self.assertEquals(business_link_d_e.getExpectedStopDate(mock), DateTime('2009/04/10 GMT+9'))
426 427 428 429 430 431 432 433

    """
    Test of illegal case, lead time of reality and simulation are inconsistent,
    always reality is taken, but it depends on which date(e.g. start_date and stop_date) is referential.

    How we know which is referential, currently implementation of it can be known by
    BusinessProcess.isStartDateReferential and BusinessProcess.isStopDateReferential.

434
    In this test case, stop_date on business_link_b_d is referential, because business_link_b_d is
435 436 437
    root explanation and business_process refer to stop_date as referential.

    calculation example(when referential date is 2009/04/06 GMT+9):
438
    start_date of business_link_b_d = referential_date - 3(lead_time of business_link_b_d)
439 440 441 442 443 444 445 446 447 448 449 450 451 452
                                    = 2009/04/06 GMT+9 - 3
                                    = 2009/04/03 GMT+9
    """
    class Mock:
      def __init__(self, date):
        self.date = date
      def getStartDate(self):
        return self.date
      def getStopDate(self):
        return self.date + 5 # changed

    base_date = DateTime('2009/04/01 GMT+9')
    mock = Mock(base_date)

453
    self.assertEquals(business_link_b_d.getExpectedStartDate(mock), DateTime('2009/04/03 GMT+9'))
454
    # This is base in this context, because referential_date is 'stop_date'
455
    self.assertEquals(business_link_b_d.getExpectedStopDate(mock), DateTime('2009/04/06 GMT+9'))
456 457

    # assertion for each path without root explanation.
458 459 460 461 462 463 464 465
    self.assertEquals(business_link_a_b.getExpectedStartDate(mock), DateTime('2009/03/29 GMT+9'))
    self.assertEquals(business_link_a_b.getExpectedStopDate(mock), DateTime('2009/03/31 GMT+9'))
    self.assertEquals(business_link_b_c.getExpectedStartDate(mock), DateTime('2009/04/01 GMT+9'))
    self.assertEquals(business_link_b_c.getExpectedStopDate(mock), DateTime('2009/04/03 GMT+9'))
    self.assertEquals(business_link_c_d.getExpectedStartDate(mock), DateTime('2009/04/03 GMT+9'))
    self.assertEquals(business_link_c_d.getExpectedStopDate(mock), DateTime('2009/04/06 GMT+9'))
    self.assertEquals(business_link_d_e.getExpectedStartDate(mock), DateTime('2009/04/08 GMT+9'))
    self.assertEquals(business_link_d_e.getExpectedStopDate(mock), DateTime('2009/04/12 GMT+9'))
466

467
class TestBPMDummyDeliveryMovementMixin(TestBPMMixin):
468 469 470 471 472 473 474
  def _createDelivery(self, **kw):
    return self.folder.newContent(portal_type='Dummy Delivery', **kw)

  def _createMovement(self, delivery, **kw):
    return delivery.newContent(portal_type='Dummy Movement', **kw)

  def getBusinessTemplateList(self):
475 476
    return super(TestBPMDummyDeliveryMovementMixin, self)\
        .getBusinessTemplateList() \
Łukasz Nowak's avatar
Łukasz Nowak committed
477
        + ('erp5_dummy_movement', )
478 479

  def afterSetUp(self):
480
    super(TestBPMDummyDeliveryMovementMixin, self).afterSetUp()
481 482 483 484 485 486 487
    if not hasattr(self.portal, 'testing_folder'):
      self.portal.newContent(portal_type='Folder',
                            id='testing_folder')
    self.folder = self.portal.testing_folder
    self.stepTic()

  def beforeTearDown(self):
488
    super(TestBPMDummyDeliveryMovementMixin, self).beforeTearDown()
489 490
    self.portal.deleteContent(id='testing_folder')
    self.stepTic()
Łukasz Nowak's avatar
Łukasz Nowak committed
491

492 493
  completed_state = 'delivered'
  frozen_state = 'confirmed'
494 495 496

  completed_state_list = [completed_state, frozen_state]
  frozen_state_list = [frozen_state]
497

498
  def _createOrderedDeliveredInvoicedBusinessProcess(self):
499 500
    # simple business process preparation
    business_process = self.createBusinessProcess()
501 502 503 504
    category_tool = self.getCategoryTool()
    ordered = category_tool.trade_state.ordered
    delivered = category_tool.trade_state.delivered
    invoiced = category_tool.trade_state.invoiced
505 506 507

    # path which is completed, as soon as related simulation movements are in
    # proper state
508
    self.order_link = self.createBusinessLink(business_process,
509 510 511 512 513
        successor_value = ordered,
        trade_phase='default/order',
        completed_state_list = self.completed_state_list,
        frozen_state_list = self.frozen_state_list)

514
    self.delivery_link = self.createBusinessLink(business_process,
515
        predecessor_value = ordered, successor_value = delivered,
516 517 518
        trade_phase='default/delivery',
        completed_state_list = self.completed_state_list,
        frozen_state_list = self.frozen_state_list)
519

520
    self.invoice_link = self.createBusinessLink(business_process,
521
        predecessor_value = delivered, successor_value = invoiced,
522
        trade_phase='default/invoicing')
523 524 525 526
    self.stepTic()

  def _createOrderedInvoicedDeliveredBusinessProcess(self):
    business_process = self.createBusinessProcess()
527 528 529 530
    category_tool = self.getCategoryTool()
    ordered = category_tool.trade_state.ordered
    delivered = category_tool.trade_state.delivered
    invoiced = category_tool.trade_state.invoiced
531

532
    self.order_link = self.createBusinessLink(business_process,
533 534 535 536 537
        successor_value = ordered,
        trade_phase='default/order',
        completed_state_list = self.completed_state_list,
        frozen_state_list = self.frozen_state_list)

538
    self.invoice_path = self.createBusinessLink(business_process,
539
        predecessor_value = ordered, successor_value = invoiced,
540 541 542
        trade_phase='default/invoicing',
        completed_state_list = self.completed_state_list,
        frozen_state_list = self.frozen_state_list)
543

544
    self.delivery_link = self.createBusinessLink(business_process,
545 546 547
        predecessor_value = invoiced, successor_value = delivered,
        trade_phase='default/delivery')
    self.stepTic()
548

549
class TestBPMisBuildableImplementation(TestBPMDummyDeliveryMovementMixin):
550 551

  def test_isBuildable(self):
552 553 554 555 556 557 558 559
    """Test isBuildable for ordered, delivered and invoiced sequence

    Here Business Process sequence corresponds simulation tree.

    delivery_path is related to root applied rule, and invoice_path is related
    to rule below, and invoice_path is after delivery_path
    """
    self._createOrderedDeliveredInvoicedBusinessProcess()
560
    # create order and order line to have starting point for business process
561 562
    order = self._createDelivery()
    order_line = self._createMovement(order)
563

Sebastien Robin's avatar
Sebastien Robin committed
564

565 566 567 568
    # first level rule with simulation movement
    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule', causality_value=order)

Sebastien Robin's avatar
Sebastien Robin committed
569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588
    def setTestClassProperty(prefix, property_name, document):
      if prefix:
        property_name = "%s_%s" % (prefix, property_name)
      setattr(self, property_name, document)
      return document

    def constructSimulationTree(applied_rule, prefix=None):
      document = setTestClassProperty(prefix, 'simulation_movement',
        applied_rule.newContent(
        portal_type = 'Simulation Movement',
        delivery_value = order_line,
        causality_value = self.order_link
        ))

      # second level rule with simulation movement
      document = setTestClassProperty(prefix, 'delivery_rule',
        document.newContent(
        portal_type='Applied Rule'))
      document = setTestClassProperty(prefix, 'delivery_simulation_movement',
        document.newContent(
589
        portal_type='Simulation Movement',
Sebastien Robin's avatar
Sebastien Robin committed
590
        causality_value = self.delivery_link))
591

Sebastien Robin's avatar
Sebastien Robin committed
592 593 594 595 596 597 598 599
      # third level rule with simulation movement
      document = setTestClassProperty(prefix, 'invoicing_rule',
          document.newContent(
          portal_type='Applied Rule'))
      document = setTestClassProperty(prefix, 'invoicing_simulation_movement',
          document.newContent(
          portal_type='Simulation Movement',
          causality_value = self.invoice_link))
600

Sebastien Robin's avatar
Sebastien Robin committed
601 602
    constructSimulationTree(applied_rule)
    constructSimulationTree(applied_rule, prefix='split')
603

604
    order.setSimulationState(self.completed_state)
605 606
    self.stepTic()

Sebastien Robin's avatar
Sebastien Robin committed
607 608 609 610
    def checkIsBusinessLinkBuildable(explanation, business_link, value):
      self.assertEquals(self.business_process.isBusinessLinkBuildable(
       explanation, business_link), value)

611
    # in the beginning only order related movements shall be buildable
Sebastien Robin's avatar
Sebastien Robin committed
612 613 614 615 616 617 618
    checkIsBusinessLinkBuildable(order, self.delivery_link, True)
    self.assertEquals(self.delivery_simulation_movement.isBuildable(), True)
    self.assertEquals(self.split_delivery_simulation_movement.isBuildable(), True)

    checkIsBusinessLinkBuildable(order, self.invoice_link, False)
    self.assertEquals(self.invoicing_simulation_movement.isBuildable(), False)
    self.assertEquals(self.split_invoicing_simulation_movement.isBuildable(),
619 620 621
        False)

    # add delivery
622 623
    delivery = self._createDelivery(causality_value = order)
    delivery_line = self._createMovement(delivery)
624 625

    # relate not split movement with delivery (deliver it)
Sebastien Robin's avatar
Sebastien Robin committed
626
    self.delivery_simulation_movement.edit(delivery_value = delivery_line)
627 628 629

    self.stepTic()

630
    # delivery_link (for order) is still buildable, as split movement is not
631 632
    # delivered yet
    #
633
    # invoice_link is not yet buildable, delivery is in inproper simulation
Łukasz Nowak's avatar
Łukasz Nowak committed
634
    # state
635
    #
636
    # delivery_link (for delivery) is not buildable - delivery is already
637
    # built for those movements
Sebastien Robin's avatar
Sebastien Robin committed
638 639 640 641 642 643 644 645 646
    checkIsBusinessLinkBuildable(order, self.delivery_link, True)
    self.assertEquals(self.split_delivery_simulation_movement.isBuildable(), True)

    checkIsBusinessLinkBuildable(delivery, self.delivery_link, False)
    checkIsBusinessLinkBuildable(delivery, self.invoice_link, False)
    self.assertEquals(self.delivery_simulation_movement.isBuildable(), False)
    self.assertEquals(self.invoicing_simulation_movement.isBuildable(), False)
    checkIsBusinessLinkBuildable(order, self.invoice_link, False)
    self.assertEquals(self.split_invoicing_simulation_movement.isBuildable(), False)
647 648 649

    # put delivery in simulation state configured on path (and this state is
    # available directly on movements)
650

651
    delivery.setSimulationState(self.completed_state)
652

653
    self.assertEqual(self.completed_state, delivery.getSimulationState())
654 655 656

    self.stepTic()

657
    # delivery_link (for order) is still buildable, as split movement is not
658 659
    # delivered yet
    #
660 661 662 663
    # invoice_link is not buildable in case of order because delivery_link
    # is not completed yet.
    #
    # invoice link is buildable for delivery because part of tree is buildable
664 665 666
    #
    # split movement for invoicing is not buildable - no proper delivery
    # related for previous path
Sebastien Robin's avatar
Sebastien Robin committed
667 668 669 670 671 672 673 674 675
    checkIsBusinessLinkBuildable(order, self.delivery_link, True)
    self.assertEquals(self.invoicing_simulation_movement.isBuildable(), True)
    checkIsBusinessLinkBuildable(delivery, self.invoice_link, True)

    checkIsBusinessLinkBuildable(order, self.invoice_link, False)
    checkIsBusinessLinkBuildable(delivery, self.invoice_link, True)
    checkIsBusinessLinkBuildable(delivery, self.delivery_link, False)
    self.assertEquals(self.delivery_simulation_movement.isBuildable(), False)
    self.assertEquals(self.split_invoicing_simulation_movement.isBuildable(),
676 677
        False)

678
class TestBPMisCompletedImplementation(TestBPMDummyDeliveryMovementMixin):
679
  @newSimulationExpectedFailure
680 681 682 683 684 685 686 687 688 689 690 691 692 693
  def test_isCompleted_OrderedDeliveredInvoiced(self):
    """Test isCompleted for ordered, delivered and invoiced sequence"""
    self._createOrderedDeliveredInvoicedBusinessProcess()

    # create order and order line to have starting point for business process
    order = self._createDelivery()
    order_line = self._createMovement(order)

    # first level rule with simulation movement
    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule', causality_value=order)

    simulation_movement = applied_rule.newContent(
      portal_type = 'Simulation Movement',
694
      delivery_value = order_line,
695
      causality_value = self.order_link
696 697 698
    )

    # second level rule with simulation movement
699 700 701 702 703 704 705 706
    delivery_rule = simulation_movement.newContent(
        portal_type='Applied Rule')
    delivery_simulation_movement = delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    # third level rule with simulation movement
    invoicing_rule = delivery_simulation_movement.newContent(
707 708 709 710 711 712 713
        portal_type='Applied Rule')
    invoicing_simulation_movement = invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    # split simulation movement for first level applied rule
    split_simulation_movement = applied_rule.newContent(
714
      portal_type = 'Simulation Movement', delivery_value = order_line,
715
      causality_value = self.order_link)
716 717

    # second level rule with simulation movement for split parent movement
718 719 720 721 722 723 724 725
    split_delivery_rule = split_simulation_movement.newContent(
        portal_type='Applied Rule')
    split_delivery_simulation_movement = split_delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    # third level rule with simulation movement for split parent movement
    split_invoicing_rule = split_delivery_simulation_movement.newContent(
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743
        portal_type='Applied Rule')
    split_invoicing_simulation_movement = split_invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), False)

    # add delivery
    delivery = self._createDelivery(causality_value = order)
    delivery_line = self._createMovement(delivery)

    # relate not split movement with delivery (deliver it)
744
    delivery_simulation_movement.edit(delivery_value = delivery_line)
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782

    self.stepTic()

    # nothing changes
    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), False)

    # from delivery point of view everything is same
    self.assertEqual(self.delivery_path.isCompleted(delivery), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(delivery), False)

    self.assertEqual(self.invoice_path.isCompleted(delivery), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(delivery), False)

    # put delivery in simulation state configured on path (and this state is
    # available directly on movements)

    delivery.setSimulationState(self.completed_state)

    self.assertEqual(self.completed_state, delivery.getSimulationState())

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), True)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.delivery_path.isCompleted(delivery), True)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(delivery), True)

    self.assertEqual(self.invoice_path.isCompleted(delivery), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(delivery), False)

783
  @newSimulationExpectedFailure
784 785 786 787 788 789 790 791 792 793 794 795
  def test_isCompleted_OrderedInvoicedDelivered(self):
    """Test isCompleted for ordered, invoiced and invoiced sequence"""
    self._createOrderedInvoicedDeliveredBusinessProcess()

    order = self._createDelivery()
    order_line = self._createMovement(order)

    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule', causality_value=order)

    simulation_movement = applied_rule.newContent(
      portal_type = 'Simulation Movement',
796
      delivery_value = order_line,
797 798 799
      causality_value = self.delivery_path
    )

800 801 802 803 804 805 806
    delivery_rule = simulation_movement.newContent(
        portal_type='Applied Rule')
    delivery_simulation_movement = delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    invoicing_rule = delivery_simulation_movement.newContent(
807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861
        portal_type='Applied Rule')
    invoicing_simulation_movement = invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), False)

    delivery = self._createDelivery(causality_value = order)
    delivery_line = self._createMovement(delivery)

    invoicing_simulation_movement.edit(delivery_value = delivery_line)

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.delivery_path.isCompleted(delivery), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(delivery), False)

    self.assertEqual(self.invoice_path.isCompleted(delivery), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(delivery), False)

    # put delivery in simulation state configured on path (and this state is
    # available directly on movements)

    delivery.setSimulationState(self.completed_state)

    self.assertEqual(self.completed_state, delivery.getSimulationState())

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), True)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), True)

    self.assertEqual(self.delivery_path.isCompleted(delivery), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(delivery), False)

    self.assertEqual(self.invoice_path.isCompleted(delivery), True)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(delivery), True)

    # now simulate compensation

862
    compensated_simulation_movement = delivery_rule.newContent(
863
      portal_type = 'Simulation Movement',
864
      delivery_value = order_line,
865 866 867 868 869 870 871 872 873 874 875 876 877 878 879
      causality_value = self.delivery_path
    )

    compensated_invoicing_rule = compensated_simulation_movement.newContent(
        portal_type='Applied Rule')

    compensated_invoicing_simulation_movement = compensated_invoicing_rule \
        .newContent(portal_type='Simulation Movement',
            causality_value = self.invoice_path)

    # and delivery some part of tree

    another_delivery = self._createDelivery(causality_value = delivery)
    another_delivery_line = self._createMovement(another_delivery)

880
    delivery_simulation_movement.edit(delivery_value=another_delivery_line)
881 882 883 884 885 886 887 888 889 890 891 892 893 894 895

    self.stepTic()

    self.assertEqual(self.delivery_path.isCompleted(order), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(order), False)

    self.assertEqual(self.invoice_path.isCompleted(order), False)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(order), True)

    self.assertEqual(self.delivery_path.isCompleted(delivery), False)
    self.assertEqual(self.delivery_path.isPartiallyCompleted(delivery), False)

    self.assertEqual(self.invoice_path.isCompleted(delivery), True)
    self.assertEqual(self.invoice_path.isPartiallyCompleted(delivery), True)

896
class TestBPMisFrozenImplementation(TestBPMDummyDeliveryMovementMixin):
897
  @newSimulationExpectedFailure
898 899 900 901 902 903 904 905 906 907 908 909 910 911
  def test_isFrozen_OrderedDeliveredInvoiced(self):
    """Test isFrozen for ordered, delivered and invoiced sequence"""
    self._createOrderedDeliveredInvoicedBusinessProcess()

    # create order and order line to have starting point for business process
    order = self._createDelivery()
    order_line = self._createMovement(order)

    # first level rule with simulation movement
    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule', causality_value=order)

    simulation_movement = applied_rule.newContent(
      portal_type = 'Simulation Movement',
912
      delivery_value = order_line,
913 914 915 916
      causality_value = self.delivery_path
    )

    # second level rule with simulation movement
917 918 919 920 921 922 923 924
    delivery_rule = simulation_movement.newContent(
        portal_type='Applied Rule')
    delivery_simulation_movement = delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    # third level rule with simulation movement
    invoicing_rule = delivery_simulation_movement.newContent(
925 926 927 928 929 930 931
        portal_type='Applied Rule')
    invoicing_simulation_movement = invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    # split simulation movement for first level applied rule
    split_simulation_movement = applied_rule.newContent(
932
      portal_type = 'Simulation Movement', delivery_value = order_line,
933
      causality_value = self.order_link)
934 935

    # second level rule with simulation movement for split parent movement
936 937 938 939 940 941 942 943
    split_delivery_rule = split_simulation_movement.newContent(
        portal_type='Applied Rule')
    split_delivery_simulation_movement = split_delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    # third level rule with simulation movement for split parent movement
    split_invoicing_rule = split_delivery_simulation_movement.newContent(
944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963
        portal_type='Applied Rule')
    split_invoicing_simulation_movement = split_invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), False)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), False)
    self.assertEqual(split_simulation_movement.isFrozen(), False)
    self.assertEqual(split_invoicing_simulation_movement.isFrozen(), False)

    # add delivery
    delivery = self._createDelivery(causality_value = order)
    delivery_line = self._createMovement(delivery)

    # relate not split movement with delivery (deliver it)
964
    delivery_simulation_movement.edit(delivery_value = delivery_line)
965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991

    self.stepTic()

    # nothing changes
    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), False)

    # from delivery point of view everything is same
    self.assertEqual(self.delivery_path.isFrozen(delivery), False)
    self.assertEqual(self.invoice_path.isFrozen(delivery), False)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), False)
    self.assertEqual(split_simulation_movement.isFrozen(), False)
    self.assertEqual(split_invoicing_simulation_movement.isFrozen(), False)

    # put delivery in simulation state configured on path (and this state is
    # available directly on movements)

    delivery.setSimulationState(self.frozen_state)

    self.assertEqual(self.frozen_state, delivery.getSimulationState())

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), False)
992
    self.assertEqual(self.delivery_path.isFrozen(delivery), False)
993 994
    self.assertEqual(self.invoice_path.isFrozen(delivery), False)

995
    self.assertEqual(delivery_simulation_movement.isFrozen(), True)
996 997 998 999
    self.assertEqual(invoicing_simulation_movement.isFrozen(), False)
    self.assertEqual(split_simulation_movement.isFrozen(), False)
    self.assertEqual(split_invoicing_simulation_movement.isFrozen(), False)

1000
  @newSimulationExpectedFailure
1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012
  def test_isFrozen_OrderedInvoicedDelivered(self):
    """Test isFrozen for ordered, invoiced and invoiced sequence"""
    self._createOrderedInvoicedDeliveredBusinessProcess()

    order = self._createDelivery()
    order_line = self._createMovement(order)

    applied_rule = self.portal.portal_simulation.newContent(
        portal_type='Applied Rule', causality_value=order)

    simulation_movement = applied_rule.newContent(
      portal_type = 'Simulation Movement',
1013
      delivery_value = order_line,
1014 1015 1016
      causality_value = self.delivery_path
    )

1017 1018 1019 1020 1021 1022 1023
    delivery_rule = simulation_movement.newContent(
        portal_type='Applied Rule')
    delivery_simulation_movement = delivery_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.delivery_path)

    invoicing_rule = delivery_simulation_movement.newContent(
1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070
        portal_type='Applied Rule')
    invoicing_simulation_movement = invoicing_rule.newContent(
        portal_type='Simulation Movement',
        causality_value = self.invoice_path)

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), False)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), False)

    delivery = self._createDelivery(causality_value = order)
    delivery_line = self._createMovement(delivery)

    invoicing_simulation_movement.edit(delivery_value = delivery_line)

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), False)
    self.assertEqual(self.delivery_path.isFrozen(delivery), False)
    self.assertEqual(self.invoice_path.isFrozen(delivery), False)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), False)

    # put delivery in simulation state configured on path (and this state is
    # available directly on movements)

    delivery.setSimulationState(self.frozen_state)

    self.assertEqual(self.frozen_state, delivery.getSimulationState())

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)
    self.assertEqual(self.invoice_path.isFrozen(order), True)
    self.assertEqual(self.delivery_path.isFrozen(delivery), False)
    self.assertEqual(self.invoice_path.isFrozen(delivery), True)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), True)

    # now simulate compensation

1071
    compensated_simulation_movement = delivery_rule.newContent(
1072
      portal_type = 'Simulation Movement',
1073
      delivery_value = order_line,
1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088
      causality_value = self.delivery_path
    )

    compensated_invoicing_rule = compensated_simulation_movement.newContent(
        portal_type='Applied Rule')

    compensated_invoicing_simulation_movement = compensated_invoicing_rule \
        .newContent(portal_type='Simulation Movement',
            causality_value = self.invoice_path)

    # and delivery some part of tree

    another_delivery = self._createDelivery(causality_value = delivery)
    another_delivery_line = self._createMovement(another_delivery)

1089
    delivery_simulation_movement.edit(delivery_value=another_delivery_line)
1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107

    self.stepTic()

    self.assertEqual(self.delivery_path.isFrozen(order), False)

    self.assertEqual(self.invoice_path.isFrozen(order), False)

    self.assertEqual(self.delivery_path.isFrozen(delivery), False)

    self.assertEqual(self.invoice_path.isFrozen(delivery), True)

    self.assertEqual(simulation_movement.isFrozen(), False)
    self.assertEqual(invoicing_simulation_movement.isFrozen(), True)

    self.assertEqual(compensated_simulation_movement.isFrozen(), False)
    self.assertEqual(compensated_invoicing_simulation_movement.isFrozen(),
        False)

1108 1109 1110
def test_suite():
  suite = unittest.TestSuite()
  suite.addTest(unittest.makeSuite(TestBPMImplementation))
1111
  suite.addTest(unittest.makeSuite(TestBPMisBuildableImplementation))
1112
  suite.addTest(unittest.makeSuite(TestBPMisCompletedImplementation))
1113
  suite.addTest(unittest.makeSuite(TestBPMisFrozenImplementation))
1114
  return suite