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

33
from zope.interface import Interface
34

35 36 37 38 39
class IBusinessPathProcess(Interface):
  """Business Path Process interface specification

  IBusinessPathProcess defines Business Process APIs related
  to Business Path completion status and expected completion dates.
40

Jean-Paul Smets's avatar
Jean-Paul Smets committed
41 42 43 44 45 46 47 48 49
  IMPORTANT:
  - explanation implicitely defines a subtree of the simulation
    Order, Order Line, Delivery or Delivery Line are simple cases
    which consider all children of delivery related movements
    + all parent simulation movement
    Applied rule is another form of explanation, which defines
    implicitely all children + all parent simulation movements
     

50 51 52 53
  TODO:
  - find a way in getTradePhaseMovementList to narrow down
    parameters to be copied (this used to be done through rule 
    parameter in provivate method)
Jean-Paul Smets's avatar
Jean-Paul Smets committed
54 55
  - Is there a reason why trade_phase should be a list in
    getBusinessPathValueList ? (for rules ?)
56 57
  """

58 59
  def getBusinessPathValueList(trade_phase=None, context=None,
                               predecessor=None, successor=None, **kw):
60 61 62
    """Returns the list of contained Business Path documents

    trade_phase -- filter by trade phase
63 64 65 66

    context -- a context to test each Business Path on
               and filter out Business Path which do not match

67 68 69
    predecessor -- filter by trade state predecessor

    successor -- filter by trade state successor
70 71

    **kw -- same arguments as those passed to searchValues / contentValues
72 73 74 75 76 77
    """

  def isBusinessPathCompleted(explanation, business_path):
    """Returns True if given Business Path document
    is completed in the context of provided explanation.

78 79
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
80 81 82 83

    business_path -- a Business Path document
    """

84 85 86 87
  def isBusinessPathPartiallyCompleted(explanation, business_path):
    """Returns True if given Business Path document
    is partially completed in the context of provided explanation.

88 89
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
90 91 92 93

    business_path -- a Business Path document
    """

94 95
  def getExpectedBusinessPathCompletionDate(explanation, business_path, 
                                                       delay_mode=None):
96 97 98
    """Returns the expected completion date of given Business Path document
    in the context of provided explanation.

99 100
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
101 102

    business_path -- a Business Path document
103 104 105

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
106 107
    """

108
  def getExpectedBusinessPathStartAndStopDate(explanation, business_path,
Jean-Paul Smets's avatar
Jean-Paul Smets committed
109
                                              delay_mode=None):
110 111 112
    """Returns the expected start and stop dates of given Business Path
    document in the context of provided explanation.

113 114
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
115 116

    business_path -- a Business Path document
117 118 119

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
120 121 122 123 124 125 126 127
    """

class IBuildableBusinessPathProcess(Interface):
  """Buildable Business Path Process interface specification

  IBuildableBusinessPathProcess defines an API to build
  simulation movements related to business pathj in the context
  of a given explanation.
128
  """
129 130

  def getBuildableBusinessPathValueList(explanation):
131
    """Returns the list of Business Path which are buildable
132 133 134
    by taking into account trade state dependencies between
    Business Path.

135 136
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
137 138
    """

139 140 141 142 143
  def getPartiallyBuildableBusinessPathValueList(explanation):
    """Returns the list of Business Path which are partially buildable
    by taking into account trade state dependencies between
    Business Path.

144 145
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
146 147
    """

148 149 150 151
  def isBusinessPathBuildable(explanation, business_path):
    """Returns True if any of the related Simulation Movement
    is buildable and if the predecessor trade state is completed.

152 153
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
154 155 156 157 158 159 160 161

    business_path -- a Business Path document
    """

  def isBusinessPatPartiallyBuildable(explanation, business_path):
    """Returns True if any of the related Simulation Movement
    is buildable and if the predecessor trade state is partially completed.

162 163
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
164 165 166 167

    business_path -- a Business Path document
    """

168 169 170 171 172 173 174 175 176 177
  def isBuildable(explanation):
    """Returns True is this business process has at least one
    Business Path which is buildable
    """

  def isPartiallyBuildable(explanation):
    """Returns True is this business process has at least one
    Business Path which is partially buildable
    """

178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196
class ITradeStateProcess(Interface):
  """Trade State Process interface specification

  ITradeStateProcess defines Business Process APIs related
  to Trade State completion status and expected completion dates.
  ITradeStateProcess APIs recursively browse trade states and business
  path to provide completion status and expected completion dates.

  For example, a complete trade state is a trade state for
  which all predecessor trade states are completed and for
  which all business path applicable to the given explanation
  are also completed.
  """

  def getTradeStateList():
    """Returns list of all trade_state of this Business Process
    by looking at successor and predecessor values of contained
    Business Path.

197 198
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
199 200
    """

201 202 203 204 205 206 207 208 209 210 211 212 213 214
  def isInitialTradeState(trade_state):
    """Returns True if given 'trade_state' has no successor related
    Business Path.

    trade_state -- a Trade State category
    """

  def isFinalTradeState(trade_state):
    """Returns True if given 'trade_state' has no predecessor related
    Business Path.

    trade_state -- a Trade State category
    """

215 216 217 218 219 220
  def getSuccessorTradeStateList(explanation, trade_state):
    """Returns the list of successor states in the 
    context of given explanation. This list is built by looking
    at all successor of business path involved in given explanation
    and which predecessor is the given trade_phase.

221 222
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
223 224 225 226 227 228 229 230 231

    trade_state -- a Trade State category
    """

  def getPredecessorTradeStateList(explanation, trade_state):
    """Returns the list of predecessor states in the 
    context of given explanation. This list is built by looking
    at all predecessor of business path involved in given explanation
    and which sucessor is the given trade_phase.
232

233 234
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
235 236

    trade_state -- a Trade State category
237 238
    """

239 240 241
  def getCompletedTradeStateList(explanation):
    """Returns the list of Trade States which are completed
    in the context of given explanation.
242

243 244
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
245 246
    """

247 248 249
  def getPartiallyCompletedTradeStateList(explanation):
    """Returns the list of Trade States which are partially 
    completed in the context of given explanation.
250

251 252
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
253 254
    """

255 256 257 258
  def getLatestCompletedTradeStateList(explanation):
    """Returns the list of completed trade states which predecessor
    states are completed and for which no successor state 
    is completed in the context of given explanation.
259

260 261
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
262 263
    """

264
  def getLatestPartiallyCompletedTradeStateList(explanation):
265 266 267
    """Returns the list of completed trade states which predecessor
    states are completed and for which no successor state 
    is partially completed in the context of given explanation.
268

269 270
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
271 272
    """

273 274 275 276 277
  def isTradeStateCompleted(explanation, trade_state):
    """Returns True if all predecessor trade states are
    completed and if no successor trade state is completed
    in the context of given explanation.

278 279
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
280

281
    trade_state -- a Trade State category
282 283
    """

284 285 286 287 288
  def isTradeStatePartiallyCompleted(explanation, trade_state):
    """Returns True if all predecessor trade states are
    completed and if no successor trade state is partially completed
    in the context of given explanation.

289 290
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
291

292
    trade_state -- a Trade State category
293
    """
294

295 296
  def getExpectedTradeStateCompletionDate(explanation, trade_state,
                                                         delay_mode=None):
297 298 299
    """Returns the date at which the give trade state is expected
    to be completed in the context of given explanation.

300 301
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
302 303

    trade_state -- a Trade State category
304 305 306

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323
    """

class ITradePhaseProcess(Interface):
  """Trade Phase Process interface specification

  ITradePhaseProcess defines Business Process APIs related
  to Trade Phase completion status and expected completion dates.
  Unlike ITradeStateProcess, ITradePhaseProcess APIs related to completion
  do not take into account relations between trade states and
  business path.

  For example, a completed trade phase is a trade phase for which all
  business path applicable to the given explanation are completed. 
  It does not matter whether the predecessor trade state of related
  business path is completed or not.
  """

324
  def getTradePhaseList():
325
    """Returns list of all trade_phase of this Business Process
326 327 328 329 330 331 332
    by looking at trade_phase values of contained Business Path.
    """

  def getCompletedTradePhaseList(explanation):
    """Returns the list of Trade Phases which are completed
    in the context of given explanation.

333 334
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
335 336 337 338 339 340
    """

  def getPartiallyCompletedTradePhaseList(explanation):
    """Returns the list of Trade Phases which are partially completed
    in the context of given explanation. 

341 342
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
343 344 345 346 347 348
    """

  def isTradePhaseCompleted(explanation, trade_phase):
    """Returns True all business path with given trade_phase
    applicable to given explanation are completed.

349 350
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
351 352 353 354 355 356 357 358 359

    trade_phase -- a Trade Phase category
    """

  def isTradePhasePartiallyCompleted(explanation, trade_phase):
    """Returns True at least one business path with given trade_phase
    applicable to given explanation is partially completed
    or completed.

360 361
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
362 363 364 365

    trade_phase -- a Trade Phase category
    """

366 367
  def getExpectedTradePhaseCompletionDate(explanation, trade_phase,
                                                       delay_mode=None):
368 369 370 371 372
    """Returns the date at which the give trade phase is expected
    to be completed in the context of given explanation, taking
    into account the graph of date constraints defined by business path
    and business states.

373 374
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
375 376

    trade_phase -- a Trade Phase category
377 378 379

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402
    """

  def getRemainingTradePhaseList(business_path, trade_phase_list=None):
    """Returns the list of remaining trade phases which to be achieved
    as part of a business process. This list is calculated by analysing 
    the graph of business path and trade states, starting from a given
    business path. The result if filtered by a list of trade phases. This
    method is useful mostly for production and MRP to manage a distributed
    supply and production chain.

    business_path -- a Business Path document

    trade_phase_list -- if provided, the result is filtered by it after
                        being collected - ???? useful ? XXX-JPS ?

    NOTE: explanation is not involved here because we consider here that
    self is the result of asUnionBusinessProcess and thus only contains
    applicable Business Path to a given simulation subtree. Since the list
    of remaining trade phases does not depend on exact values in the
    simulation, we did not include the explanation. However, this makes the
    API less uniform.
    """

403 404 405 406 407 408
  def getTradePhaseMovementList(explanation, amount, trade_phase=None, delay_mode=None):
    """Returns a list of movement with appropriate arrow and dates,
    based on the Business Path definitions, provided 'amount' and optional
    trade phases. If no trade_phase is provided, the trade_phase defined
    on the Amount is used instead.
    
409 410
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
411 412 413 414 415 416 417 418 419

    amount -- Amount (quantity, resource)

    trade_phase -- optional Trade Phase category

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
    """

420 421 422 423 424 425 426 427 428
class IBusinessProcess(IBusinessPathProcess, IBuildableBusinessPathProcess,
                       ITradeStateProcess, ITradePhaseProcess, ):
  """Business Process interface specification.

  Business Process APIs are used to manage the completion status,
  the completion dates, the start date and stop date, and trigger 
  build process of a complex simulation process in ERP5.
  """

429
  def isCompleted(explanation):
430 431 432
    """Returns True is all applicable Trade States and Trade Phases
    are completed in the context of given explanation.

433 434
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
435 436
    """

437 438 439 440
  def isBuildable(explanation):
    """Returns True is one Business Path of this Business Process
    is buildable in the context of given explanation.

441 442
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
443 444 445 446 447 448
    """

  def isPartiallyBuildable(explanation):
    """Returns True is one Business Path of this Business Process
    is partially buildable in the context of given explanation.

449 450
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
451 452
    """

453
  def getExpectedCompletionDate(explanation, delay_mode=None):
454 455 456
    """Returns the expected date at which all applicable Trade States and
    Trade Phases are completed in the context of given explanation.

457 458
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
459
    """
460 461 462 463

  def build(explanation, include_partially_buildable=False):
    """Build whatever is buildable in the context of given explanation.

464 465
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
466 467 468 469 470

    include_partially_buildable -- if set to True, also build partially
                                   buildable business path. Else
                                   only build strictly buildable path.
    """