Rule.py 22 KB
Newer Older
Łukasz Nowak's avatar
Łukasz Nowak committed
1
# -*- coding: utf-8 -*-
Jean-Paul Smets's avatar
Jean-Paul Smets committed
2 3
##############################################################################
#
Łukasz Nowak's avatar
Łukasz Nowak committed
4
# Copyright (c) 2002-2009 Nexedi SARL and Contributors. All Rights Reserved.
5
#                    Jean-Paul Smets-Solanes <jp@nexedi.com>
Łukasz Nowak's avatar
Łukasz Nowak committed
6
#                    Łukasz Nowak <luke@nexedi.com>
Jean-Paul Smets's avatar
Jean-Paul Smets committed
7 8
#
# WARNING: This program as such is intended to be used by professional
Łukasz Nowak's avatar
Łukasz Nowak committed
9
# programmers who take the whole responsibility of assessing all potential
Jean-Paul Smets's avatar
Jean-Paul Smets committed
10 11
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
Łukasz Nowak's avatar
Łukasz Nowak committed
12
# guarantees and support are strongly advised to contract a Free Software
Jean-Paul Smets's avatar
Jean-Paul Smets committed
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
# 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.
#
##############################################################################

31
import zope.interface
Jean-Paul Smets's avatar
Jean-Paul Smets committed
32
from AccessControl import ClassSecurityInfo
Łukasz Nowak's avatar
Łukasz Nowak committed
33
from Products.ERP5Type import Permissions, PropertySheet, interfaces
Jean-Paul Smets's avatar
Jean-Paul Smets committed
34 35
from Products.ERP5Type.XMLObject import XMLObject
from Products.ERP5.Document.Predicate import Predicate
Łukasz Nowak's avatar
Łukasz Nowak committed
36
from Acquisition import aq_base
Jean-Paul Smets's avatar
Jean-Paul Smets committed
37

38
class Rule(Predicate, XMLObject):
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72
  """
    Rule objects implement the simulation algorithm
    (expand, solve)

    Example of rules

    - Stock rule (checks stocks)

    - Order rule (copies movements from an order)

    - Capacity rule (makes sure stocks / sources are possible)

    - Transformation rule (expands transformations)

    - Template rule (creates submovements with a template system)
      used in Invoice rule, Paysheet rule, etc.

    Rules are called one by one at the global level (the rules folder)
    and at the local level (applied rules in the simulation folder)

    The simulation_tool includes rules which are parametrized by the sysadmin
    The simulation_tool does the logics of checking, calling, etc.

    simulation_tool is a subclass of Folder & Tool
  """

  # CMF Type Definition
  meta_type = 'ERP5 Rule'
  portal_type = 'Rule'
  add_permission = Permissions.AddPortalContent

  # Declarative security
  security = ClassSecurityInfo()
  security.declareObjectProtected(Permissions.AccessContentsInformation)
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
73

74
  zope.interface.implements( interfaces.IPredicate,
75
                     interfaces.IRule )
76 77 78 79 80 81

  # Default Properties
  property_sheets = ( PropertySheet.Base
                    , PropertySheet.XMLObject
                    , PropertySheet.CategoryCore
                    , PropertySheet.DublinCore
82
                    , PropertySheet.Task
83 84 85
                    , PropertySheet.Predicate
                    , PropertySheet.Reference
                    , PropertySheet.Version
86
                    , PropertySheet.Rule
87
                    )
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
88

89 90 91 92 93 94 95
  # Portal Type of created children
  movement_type = 'Simulation Movement'

  security.declareProtected(Permissions.AccessContentsInformation,
                            'isAccountable')
  def isAccountable(self, movement):
    """Tells wether generated movement needs to be accounted or not.
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
96

97 98
    Only account movements which are not associated to a delivery;
    Whenever delivery is there, delivery has priority
Jean-Paul Smets's avatar
Jean-Paul Smets committed
99
    """
100
    return movement.getDeliveryValue() is None
Jean-Paul Smets's avatar
Jean-Paul Smets committed
101

102 103
  security.declareProtected(Permissions.ModifyPortalContent,
                            'constructNewAppliedRule')
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
104
  def constructNewAppliedRule(self, context, id=None,
105 106 107 108 109 110 111 112 113 114 115 116 117 118
                              activate_kw=None, **kw):
    """
      Creates a new applied rule which points to self
    """
    # XXX Parameter **kw is useless, so, we should remove it
    if id is None:
      id = context.generateNewId()
    if getattr(aq_base(context), id, None) is None:
      context.newContent(id=id,
                         portal_type='Applied Rule',
                         specialise_value=self,
                         activate_kw=activate_kw)
    return context.get(id)

Łukasz Nowak's avatar
Łukasz Nowak committed
119 120 121 122
  def _isBPM(self):
    """Checks if rule is used in BPM"""
    return bool(self.getTradePhaseList())

123
  # Simulation workflow
124 125 126 127 128 129 130 131
  def test(self, *args, **kw):
    """
    If no test method is defined, return False, to prevent infinite loop
    """
    if not self.getTestMethodId():
      return False
    return Predicate.test(self, *args, **kw)

132
  def _expand(self, applied_rule, force=0, **kw):
Łukasz Nowak's avatar
Łukasz Nowak committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154
    """Generic expand with helpers.
    Do NOT overload, use helpers."""
    add_list, modify_dict, \
      delete_list = self._getCompensatedMovementList(applied_rule, **kw)

    # delete not needed movements
    for movement_id in delete_list:
      applied_rule._delObject(movement_id)

    # update existing
    for movement, property_dict in modify_dict.items():
      applied_rule[movement].edit(**property_dict)

    # add new ones
    for movement_dict in add_list:
      movement_id = applied_rule._get_id(movement_dict.pop('id', None))
      new_movement = applied_rule.newContent(id=movement_id,
          portal_type=self.movement_type, **movement_dict)

    for o in applied_rule.objectValues():
      o.expand(**kw)

155 156 157 158
  security.declareProtected(Permissions.ModifyPortalContent, 'expand')
  def expand(self, applied_rule, **kw):
    """
      Expands the current movement downward.
Jean-Paul Smets's avatar
Jean-Paul Smets committed
159

160 161 162
      An applied rule can be expanded only if its parent movement
      is expanded.
    """
Łukasz Nowak's avatar
Łukasz Nowak committed
163
    if self._isBPM():
164
      return self._expand(applied_rule, **kw)
165 166 167 168 169 170 171 172
    for o in applied_rule.objectValues():
      o.expand(**kw)

  security.declareProtected(Permissions.ModifyPortalContent, 'solve')
  def solve(self, applied_rule, solution_list):
    """
      Solve inconsistency according to a certain number of solutions
      templates. This updates the
Jean-Paul Smets's avatar
Jean-Paul Smets committed
173

174
      -> new status -> solved
Jean-Paul Smets's avatar
Jean-Paul Smets committed
175

176 177 178 179 180
      This applies a solution to an applied rule. Once
      the solution is applied, the parent movement is checked.
      If it does not diverge, the rule is reexpanded. If not,
      diverge is called on the parent movement.
    """
Jean-Paul Smets's avatar
Jean-Paul Smets committed
181

182 183
  security.declareProtected(Permissions.ModifyPortalContent, 'diverge')
  def diverge(self, applied_rule):
Jean-Paul Smets's avatar
Jean-Paul Smets committed
184
    """
185
      -> new status -> diverged
Jean-Paul Smets's avatar
Jean-Paul Smets committed
186

187 188 189 190
      This basically sets the rule to "diverged"
      and blocks expansion process
    """
    pass
Jean-Paul Smets's avatar
Jean-Paul Smets committed
191

192 193 194
  # Solvers
  security.declareProtected( Permissions.AccessContentsInformation,
                            'isDivergent')
195
  def isDivergent(self, sim_mvt, ignore_list=[]):
196 197 198 199
    """
    Returns true if the Simulation Movement is divergent comparing to
    the delivery value
    """
200
    delivery = sim_mvt.getDeliveryValue()
201 202
    if delivery is None:
      return 0
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
203

204 205 206
    if self.getDivergenceList(sim_mvt) == []:
      return 0
    else:
207
      return 1
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
208

209 210 211 212 213 214 215 216 217
  security.declareProtected(Permissions.View, 'getDivergenceList')
  def getDivergenceList(self, sim_mvt):
    """
    Return a list of messages that contains the divergences.
    """
    result_list = []
    for divergence_tester in self.contentValues(
               portal_type=self.getPortalDivergenceTesterTypeList()):
      result = divergence_tester.explain(sim_mvt)
218 219 220 221
      if isinstance(result, (list, tuple)): # for compatibility
        result_list.extend(result)
      elif result is not None:
        result_list.append(result)
222 223
    return result_list

224 225 226 227 228 229
  # Deliverability / orderability
  def isOrderable(self, movement):
    return 0

  def isDeliverable(self, movement):
    return 0
230

231 232 233 234 235 236 237 238 239 240 241 242
  def isStable(self, applied_rule, **kw):
    """
    - generate a list of previsions
    - compare the prevision with existing children
    - return 1 if they match, 0 else
    """
    list = self._getCompensatedMovementList(applied_rule, **kw)
    for e in list:
      if len(e) > 0:
        return 0
    return 1

Łukasz Nowak's avatar
Łukasz Nowak committed
243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
#### Helpers to overload
  def _getExpandablePropertyUpdateDict(self, applied_rule, movement,
      business_path, current_property_dict):
    """Rule specific dictionary used to update _getExpandablePropertyDict
    This method might be overloaded.
    """
    return {}

  def _getInputMovementList(self, applied_rule):
    """Return list of movements for applied rule.
    This method might be overloaded"""
    return [applied_rule.getParentValue()]

  def _generatePrevisionList(self, applied_rule, **kw):
    """
    Generate a list of dictionaries, that contain calculated content of
    current Simulation Movements in applied rule.
    based on its context (parent movement, delivery, configuration ...)

    These previsions are returned as dictionaries.
    """
    prevision_dict_list = []
    for input_movement, business_path in self \
        ._getInputMovementAndPathTupleList(applied_rule):
      prevision_dict_list.append(self._getExpandablePropertyDict(applied_rule,
          input_movement, business_path))
    return prevision_dict_list

#### Helpers NOT to overload
272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289
  def _getCurrentMovementList(self, applied_rule, **kw):
    """
    Returns the list of current children of the applied rule, sorted in 3
    groups : immutables/mutables/deletable

    If a movement is not frozen, and has no delivered child, it can be
    deleted.
    Else, if a movement is not frozen, and has some delivered child, it can
    be modified.
    Else, it cannot be modified.

    - is delivered
    - has delivered childs (including self)
    - is in reserved or current state
    - is frozen

    a movement is deletable if it has no delivered child, is not in current
    state, and not in delivery movements.
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
290
    a movement
291 292 293 294
    """
    immutable_movement_list = []
    mutable_movement_list = []
    deletable_movement_list = []
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
295

296 297 298 299
    for movement in applied_rule.contentValues(portal_type=self.movement_type):
      if movement.isFrozen():
        immutable_movement_list.append(movement)
      else:
300
        if movement._isTreeDelivered():
301 302 303 304 305 306 307
          mutable_movement_list.append(movement)
        else:
          deletable_movement_list.append(movement)

    return (immutable_movement_list, mutable_movement_list,
            deletable_movement_list)

Łukasz Nowak's avatar
Łukasz Nowak committed
308 309 310 311
  def _getInputMovementAndPathTupleList(self, applied_rule):
    """Returns list of tuples (movement, business_path)"""
    input_movement_list = self._getInputMovementList(applied_rule)
    business_process = applied_rule.getBusinessProcessValue()
312 313 314 315 316
    trade_phase_list = self.getTradePhaseList()

    # In non-BPM case, we have no business path.
    if business_process is None or len(trade_phase_list) == 0:
      return [(input_movement, None) for input_movement in input_movement_list]
Łukasz Nowak's avatar
Łukasz Nowak committed
317 318 319 320

    input_movement_and_path_list = []
    for input_movement in input_movement_list:
      for business_path in business_process.getPathValueList(
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
321
                          trade_phase_list,
Łukasz Nowak's avatar
Łukasz Nowak committed
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347
                          input_movement):
        input_movement_and_path_list.append((input_movement, business_path))

    return input_movement_and_path_list

  def _getCompensatedMovementListBPM(self, applied_rule, **kw):
    """Compute the difference between prevision and existing movements

    Immutable movements need compensation, mutable ones needs to be modified
    """
    add_list = [] # list of movements to be added
    modify_dict = {} # dict of movements to be modified
    delete_list = [] # list of movements to be deleted

    prevision_list = self._generatePrevisionList(applied_rule, **kw)
    immutable_movement_list, mutable_movement_list, \
        deletable_movement_list = self._getCurrentMovementList(applied_rule,
                                                               **kw)
    movement_list = immutable_movement_list + mutable_movement_list \
                    + deletable_movement_list
    non_matched_list = movement_list[:] # list of remaining movements

    for prevision in prevision_list:
      p_matched_list = []
      for movement in non_matched_list:
        for prop in self.getMatchingPropertyList():
348 349 350 351 352
          if movement.isPropertyRecorded(prop):
            movement_value = movement.getRecordedProperty(prop)
          else:
            movement_value = movement.getProperty(prop)
          if prevision.get(prop) != movement_value:
Łukasz Nowak's avatar
Łukasz Nowak committed
353 354 355 356 357 358 359 360 361
            break
        else:
          p_matched_list.append(movement)

      # Movements exist, we'll try to make them match the prevision
      if p_matched_list != []:
        # Check the quantity
        m_quantity = 0.0
        for movement in p_matched_list:
362 363 364 365
          if movement.isPropertyRecorded('quantity'):
            m_quantity += movement.getRecordedProperty('quantity')
          else:
            m_quantity += movement.getQuantity()
Łukasz Nowak's avatar
Łukasz Nowak committed
366 367
        if m_quantity != prevision.get('quantity'):
          # special case - quantity
368 369 370 371 372 373 374 375 376 377
          q_diff = prevision.get('quantity') - m_quantity
          # try to find a movement that can be edited
          for movement in p_matched_list:
            if movement in (mutable_movement_list \
                + deletable_movement_list):
              # mark as requiring modification
              prop_dict = modify_dict.setdefault(movement.getId(), {})
              prop_dict['quantity'] = movement.getQuantity() + \
                  q_diff
              break
Łukasz Nowak's avatar
Łukasz Nowak committed
378
          else:
379 380
            # no modifiable movement was found, need to compensate by quantity
            raise NotImplementedError('Need to generate quantity compensation')
Łukasz Nowak's avatar
Łukasz Nowak committed
381 382 383 384 385 386

        for movement in p_matched_list:
          if movement in (mutable_movement_list \
              + deletable_movement_list):
            prop_dict = modify_dict.setdefault(movement.getId(), {})
            for k, v in prevision.items():
387 388
              if movement.isPropertyRecorded(k):
                movement_value = movement.getRecordedProperty(k)
389 390
                if isinstance(movement_value, list) and not isinstance(v, list):
                  movement_value = movement_value[0]
391 392 393
              else:
                movement_value = movement.getProperty(k)
              if k not in ('quantity',) and v != movement_value:
Łukasz Nowak's avatar
Łukasz Nowak committed
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417
                prop_dict.setdefault(k, v)

        # update movement lists
        for movement in p_matched_list:
          non_matched_list.remove(movement)

      # No movement matched, we need to create one
      else:
        add_list.append(prevision)

    # delete non matched movements
    for movement in non_matched_list:
      if movement in deletable_movement_list:
        # delete movement
        delete_list.append(movement.getId())
      elif movement in mutable_movement_list:
        # set movement quantity to 0 to make it "void"
        prop_dict = modify_dict.setdefault(movement.getId(), {})
        prop_dict['quantity'] = 0.0
      else:
        # movement not modifiable, we can decide to create a compensation
        # with negative quantity
        raise NotImplementedError("Tried to delete immutable movement %s" % \
            movement.getRelativeUrl())
418

Łukasz Nowak's avatar
Łukasz Nowak committed
419 420
    return (add_list, modify_dict, delete_list)

421
  def _getCompensatedMovementList(self, applied_rule,
422
                                  matching_property_list=None, **kw):
423 424 425 426 427 428 429 430
    """
    Compute the difference between prevision and existing movements

    immutable movements need compensation, mutables needs to be modified

    XXX For now, this implementation is too simple. It could be improved by
    using MovementGroups
    """
Łukasz Nowak's avatar
Łukasz Nowak committed
431
    if self._isBPM():
432
      return self._getCompensatedMovementListBPM(applied_rule, **kw)
433 434 435
    add_list = [] # list of movements to be added
    modify_dict = {} # dict of movements to be modified
    delete_list = [] # list of movements to be deleted
Łukasz Nowak's avatar
Łukasz Nowak committed
436

437 438 439 440 441 442
    prevision_list = self._generatePrevisionList(applied_rule, **kw)
    immutable_movement_list, mutable_movement_list, \
        deletable_movement_list = self._getCurrentMovementList(applied_rule,
                                                               **kw)
    movement_list = immutable_movement_list + mutable_movement_list \
                    + deletable_movement_list
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
443
    non_matched_list = movement_list[:] # list of remaining movements
444

445 446 447
    if matching_property_list is None:
      matching_property_list = self.getMatchingPropertyList()

448 449 450 451
    for prevision in prevision_list:
      p_matched_list = []
      for movement in non_matched_list:
        for prop in matching_property_list:
452 453 454 455 456
          if movement.isPropertyRecorded(prop):
            movement_value = movement.getRecordedProperty(prop)
          else:
            movement_value = movement.getProperty(prop)
          if prevision.get(prop) != movement_value:
457 458 459 460 461
            break
        else:
          p_matched_list.append(movement)

      # XXX hardcoded ...
Kazuhiko Shiozaki's avatar
Kazuhiko Shiozaki committed
462
#       LOG("Rule, _getCompensatedMovementList", WARNING,
463
#           "Hardcoded properties check")
464 465 466 467 468
      # Movements exist, we'll try to make them match the prevision
      if p_matched_list != []:
        # Check the quantity
        m_quantity = 0.0
        for movement in p_matched_list:
469 470 471 472
          if movement.isPropertyRecorded('quantity'):
            m_quantity += movement.getRecordedProperty('quantity')
          else:
            m_quantity += movement.getQuantity()
473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488
        if m_quantity != prevision.get('quantity'):
          q_diff = prevision.get('quantity') - m_quantity
          # try to find a movement that can be edited
          for movement in p_matched_list:
            if movement in (mutable_movement_list \
                + deletable_movement_list):
              # mark as requiring modification
              prop_dict = modify_dict.setdefault(movement.getId(), {})
              #prop_dict['quantity'] = movement.getCorrectedQuantity() + \
              prop_dict['quantity'] = movement.getQuantity() + \
                  q_diff
              break
          # no modifiable movement was found, need to create one
          else:
            prevision['quantity'] = q_diff
            add_list.append(prevision)
489

490 491 492 493
        # Check the date
        for movement in p_matched_list:
          if movement in (mutable_movement_list \
              + deletable_movement_list):
494
            prop_dict = modify_dict.setdefault(movement.getId(), {})
495 496
            for prop in ('start_date', 'stop_date'):
              #XXX should be >= 15
497 498 499 500 501
              if movement.isPropertyRecorded(prop):
                movement_value = movement.getRecordedProperty(prop)
              else:
                movement_value = movement.getProperty(prop)
              if prevision.get(prop) != movement_value:
502 503
                prop_dict[prop] = prevision.get(prop)
                break
504 505

            for k, v in prevision.items():
506 507 508
              if k not in ('quantity', 'start_date', 'stop_date'):
                if movement.isPropertyRecorded(k):
                  movement_value = movement.getRecordedProperty(k)
509 510
                  if isinstance(movement_value, list) and not isinstance(v, list):
                    movement_value = movement_value[0]
511 512 513 514
                else:
                  movement_value = movement.getProperty(k)
                if v != movement_value:
                  prop_dict.setdefault(k, v)
515

516 517 518
        # update movement lists
        for movement in p_matched_list:
          non_matched_list.remove(movement)
519

520 521 522
      # No movement matched, we need to create one
      else:
        add_list.append(prevision)
523

524 525 526 527 528 529 530 531 532 533 534 535
    # delete non matched movements
    for movement in non_matched_list:
      if movement in deletable_movement_list:
        # delete movement
        delete_list.append(movement.getId())
      elif movement in mutable_movement_list:
        # set movement quantity to 0 to make it "void"
        prop_dict = modify_dict.setdefault(movement.getId(), {})
        prop_dict['quantity'] = 0.0
      else:
        # movement not modifiable, we can decide to create a compensation
        # with negative quantity
536 537 538
        raise NotImplementedError(
                "Can not create a compensation movement for %s" % \
                movement.getRelativeUrl())
539
    return (add_list, modify_dict, delete_list)
Łukasz Nowak's avatar
Łukasz Nowak committed
540

541
  def _getExpandablePropertyDict(self, applied_rule, movement, business_path=None,
Łukasz Nowak's avatar
Łukasz Nowak committed
542 543 544 545 546 547 548 549 550 551 552
      **kw):
    """
    Return a Dictionary with the Properties used to edit the simulation
    Do NOT overload this method, use _getExpandablePropertyUpdateDict instead
    """
    property_dict = {}

    default_property_list = self.getExpandablePropertyList()
    for prop in default_property_list:
      property_dict[prop] = movement.getProperty(prop)

553 554 555 556 557 558 559
    # rule specific
    property_dict.update(**self._getExpandablePropertyUpdateDict(applied_rule,
      movement, business_path, property_dict))

    if business_path is None:
      return property_dict

Łukasz Nowak's avatar
Łukasz Nowak committed
560 561
    # Arrow
    for base_category in \
562 563
        business_path.getSourceArrowBaseCategoryList() +\
        business_path.getDestinationArrowBaseCategoryList():
Łukasz Nowak's avatar
Łukasz Nowak committed
564 565 566 567 568
      # XXX: we need to use _list for categories *always*
      category_url = business_path.getDefaultAcquiredCategoryMembership(
          base_category, context=movement)
      if category_url not in ['', None]:
        property_dict['%s_list' % base_category] = [category_url]
569

Łukasz Nowak's avatar
Łukasz Nowak committed
570
    # Amount
571
    property_dict['quantity'] = business_path.getExpectedQuantity(movement)
Łukasz Nowak's avatar
Łukasz Nowak committed
572

573
    # Date
Łukasz Nowak's avatar
Łukasz Nowak committed
574 575 576 577
    if movement.getStartDate() == movement.getStopDate():
      property_dict['start_date'] = business_path.getExpectedStartDate(
          movement)
      property_dict['stop_date'] = business_path.getExpectedStopDate(movement)
578 579 580 581 582 583 584
      # in case of not fully working BPM get dates from movement
      # XXX: as soon as BPM will be fully operational this hack will not be
      #      needed anymore
      if property_dict['start_date'] is None:
        property_dict['start_date'] = movement.getStartDate()
      if property_dict['stop_date'] is None:
        property_dict['stop_date'] = movement.getStopDate()
Łukasz Nowak's avatar
Łukasz Nowak committed
585 586 587 588 589 590 591 592 593 594 595
    else: # XXX shall not be used, but business_path.getExpectedStart/StopDate
          # do not works on second path...
      property_dict['start_date'] = movement.getStartDate()
      property_dict['stop_date'] = movement.getStopDate()

    # save a relation to business path
    property_dict['causality_list'] = [business_path.getRelativeUrl()]

    return property_dict