business_process.py 16.4 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 40 41
class IBusinessPathProcess(Interface):
  """Business Path Process interface specification

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

42 43
  def getBusinessPathValueList(trade_phase=None, context=None,
                               predecessor=None, successor=None, **kw):
44 45 46
    """Returns the list of contained Business Path documents

    trade_phase -- filter by trade phase
47 48 49 50

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

51 52 53
    predecessor -- filter by trade state predecessor

    successor -- filter by trade state successor
54 55

    **kw -- same arguments as those passed to searchValues / contentValues
56 57 58 59 60 61 62 63 64 65 66 67
    """

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

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    business_path -- a Business Path document
    """

68 69 70 71 72 73 74 75 76 77
  def isBusinessPathPartiallyCompleted(explanation, business_path):
    """Returns True if given Business Path document
    is partially completed in the context of provided explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    business_path -- a Business Path document
    """

78 79
  def getExpectedBusinessPathCompletionDate(explanation, business_path, 
                                                       delay_mode=None):
80 81 82 83 84 85 86
    """Returns the expected completion date of given Business Path document
    in the context of provided explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    business_path -- a Business Path document
87 88 89

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

92 93
  def getExpectedBusinessPathStartAndStopDate(explanation, business_path,
                                                         delay_mode=None):
94 95 96 97 98 99 100
    """Returns the expected start and stop dates of given Business Path
    document in the context of provided explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    business_path -- a Business Path document
101 102 103

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
104 105 106 107 108 109 110 111
    """

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.
112
  """
113 114

  def getBuildableBusinessPathValueList(explanation):
115
    """Returns the list of Business Path which are buildable
116 117 118 119 120 121 122
    by taking into account trade state dependencies between
    Business Path.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

123 124 125 126 127 128 129 130 131
  def getPartiallyBuildableBusinessPathValueList(explanation):
    """Returns the list of Business Path which are partially buildable
    by taking into account trade state dependencies between
    Business Path.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

132 133 134 135 136 137 138 139 140 141 142 143 144 145 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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    business_path -- a Business Path document
    """

152 153 154 155 156 157 158 159 160 161
  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
    """

162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201
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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

  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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    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.
202

203 204 205 206
    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    trade_state -- a Trade State category
207 208
    """

209 210 211
  def getCompletedTradeStateList(explanation):
    """Returns the list of Trade States which are completed
    in the context of given explanation.
212

213 214
    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
215 216
    """

217 218 219
  def getPartiallyCompletedTradeStateList(explanation):
    """Returns the list of Trade States which are partially 
    completed in the context of given explanation.
220

221 222
    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
223 224
    """

225 226 227 228
  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.
229

230 231
    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
232 233
    """

234 235 236 237
  def getLatestPartiallyCompletedTradeState(explanation):
    """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.
238

239 240
    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
241 242
    """

243 244 245 246 247 248 249
  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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
250

251
    trade_state -- a Trade State category
252 253
    """

254 255 256 257 258 259 260
  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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
261

262
    trade_state -- a Trade State category
263
    """
264

265 266
  def getExpectedTradeStateCompletionDate(explanation, trade_state,
                                                         delay_mode=None):
267 268 269 270 271 272 273
    """Returns the date at which the give trade state is expected
    to be completed in the context of given explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    trade_state -- a Trade State category
274 275 276

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
    """

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.
  """

294
  def getTradePhaseList():
295
    """Returns list of all trade_phase of this Business Process
296 297 298 299 300 301 302 303 304 305 306 307 308 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
    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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

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

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

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

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    trade_phase -- a Trade Phase category
    """

336 337
  def getExpectedTradePhaseCompletionDate(explanation, trade_phase,
                                                       delay_mode=None):
338 339 340 341 342 343 344 345 346
    """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.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

    trade_phase -- a Trade Phase category
347 348 349

    delay_mode -- optional value to specify calculation mode ('min', 'max')
                  if no value specified use average delay
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381
    """

  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.
    """

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.
  """

382
  def isCompleted(explanation):
383 384 385 386 387 388 389
    """Returns True is all applicable Trade States and Trade Phases
    are completed in the context of given explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405
  def isBuildable(explanation):
    """Returns True is one Business Path of this Business Process
    is buildable in the context of given explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

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

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
    """

406
  def getExpectedCompletionDate(explanation, delay_mode=None):
407 408 409 410 411
    """Returns the expected date at which all applicable Trade States and
    Trade Phases are completed in the context of given explanation.

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree
412
    """
413 414 415 416 417 418 419 420 421 422 423

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

    explanation -- an Order, Order Line, Delivery or Delivery Line which
                   implicitely defines a simulation subtree

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