business_process.py 19.1 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
class ITradeModelPathProcess(Interface):
36 37 38 39 40
  """Trade Model Path Process interface specification

  ITradeModelPathProcess defines Business Process APIs related
  to Trade Model Path access and to the evaluation of start_date,
  stop date, quantity shares and arrows of an Amount.
41 42
  """

43 44 45 46 47 48 49 50 51 52
  def getTradeModelPathValueList(trade_phase=None, context=None, **kw):
    """Returns all Trade Model Path of the current Business Process which
    are matching the given trade_phase and the optional context.

    trade_phase -- filter by trade phase

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

    **kw -- same arguments as those passed to searchValues / contentValues
53 54
    """

55 56 57
  def getExpectedTradeModelPathStartAndStopDate(explanation, trade_model_path,
                                                delay_mode=None):
    """Returns the expected start and stop dates of given Trade Model Path
58 59 60 61 62
    document in the context of provided explanation.

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

63
    trade_model_path -- a Trade Model Path document
64 65 66 67

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

69 70 71 72 73
class IBusinessLinkProcess(Interface):
  """Business Link Process interface specification

  IBusinessLinkProcess defines Business Process APIs related
  to Business Link completion status and expected completion dates.
74

Jean-Paul Smets's avatar
Jean-Paul Smets committed
75 76 77 78 79 80 81 82 83
  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
     

84 85 86 87
  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
88
  - Is there a reason why trade_phase should be a list in
89
    getBusinessLinkValueList ? (for rules ?)
90 91
  """

92
  def getBusinessLinkValueList(trade_phase=None, context=None,
93
                               predecessor=None, successor=None, **kw):
94 95
    """Returns all Business Links of the current BusinessProcess which
    are matching the given trade_phase and the optional context.
96 97

    trade_phase -- filter by trade phase
98

99 100
    context -- a context to test each Business Link on
               and filter out Business Link which do not match
101

102 103 104
    predecessor -- filter by trade state predecessor

    successor -- filter by trade state successor
105 106

    **kw -- same arguments as those passed to searchValues / contentValues
107 108
    """

109 110
  def isBusinessLinkCompleted(explanation, business_link):
    """Returns True if given Business Link document
111 112
    is completed 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_link -- a Business Link document
117 118
    """

119 120
  def isBusinessLinkPartiallyCompleted(explanation, business_link):
    """Returns True if given Business Link document
121 122
    is partially completed in the context of provided explanation.

123 124
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
125

126
    business_link -- a Business Link document
127 128
    """

129 130
class IBuildableBusinessLinkProcess(Interface):
  """Buildable Business Link Process interface specification
131

132
  IBuildableBusinessLinkProcess defines an API to build
133
  simulation movements related to business link in the context
134
  of a given explanation.
135
  """
136

137 138
  def getBuildableBusinessLinkValueList(explanation):
    """Returns the list of Business Link which are buildable
139
    by taking into account trade state dependencies between
140
    Business Link.
141

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

146 147
  def getPartiallyBuildableBusinessLinkValueList(explanation):
    """Returns the list of Business Link which are partially buildable
148
    by taking into account trade state dependencies between
149
    Business Link.
150

151 152
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
153 154
    """

155
  def isBusinessLinkBuildable(explanation, business_link):
156 157 158
    """Returns True if any of the related Simulation Movement
    is buildable and if the predecessor trade state is completed.

159 160
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
161

162
    business_link -- a Business Link document
163 164
    """

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

169 170
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
171

172
    business_link -- a Business Link document
173 174
    """

175 176
  def isBuildable(explanation):
    """Returns True is this business process has at least one
177
    Business Link which is buildable
178 179 180 181
    """

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

185 186 187 188 189 190
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
191
  links to provide completion status and expected completion dates.
192 193 194

  For example, a complete trade state is a trade state for
  which all predecessor trade states are completed and for
195
  which all business links applicable to the given explanation
196 197 198 199 200 201
  are also completed.
  """

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

204 205
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
206 207
    """

208 209
  def isInitialTradeState(trade_state):
    """Returns True if given 'trade_state' has no successor related
210
    Business Link.
211 212 213 214 215 216

    trade_state -- a Trade State category
    """

  def isFinalTradeState(trade_state):
    """Returns True if given 'trade_state' has no predecessor related
217
    Business Link.
218 219 220 221

    trade_state -- a Trade State category
    """

222 223 224
  def getSuccessorTradeStateList(explanation, trade_state):
    """Returns the list of successor states in the 
    context of given explanation. This list is built by looking
225
    at all successor of business link involved in given explanation
226 227
    and which predecessor is the given trade_phase.

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

    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
237
    at all predecessor of business link involved in given explanation
238
    and which sucessor is the given trade_phase.
239

240 241
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
242 243

    trade_state -- a Trade State category
244 245
    """

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

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

254 255 256
  def getPartiallyCompletedTradeStateList(explanation):
    """Returns the list of Trade States which are partially 
    completed in the context of given explanation.
257

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

262 263 264 265
  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.
266

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

271
  def getLatestPartiallyCompletedTradeStateList(explanation):
272 273 274
    """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.
275

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

280 281 282 283 284
  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.

285 286
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
287

288
    trade_state -- a Trade State category
289 290
    """

291 292 293 294 295
  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.

296 297
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
298

299
    trade_state -- a Trade State category
300
    """
301

302 303 304 305 306 307 308
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
309
  business link.
310 311

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

317
  def getTradePhaseList():
318
    """Returns list of all trade_phase of this Business Process
319
    by looking at trade_phase values of contained Business Link.
320 321 322 323 324 325
    """

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

326 327
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
328 329 330 331 332 333
    """

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

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

  def isTradePhaseCompleted(explanation, trade_phase):
Jean-Paul Smets's avatar
typo  
Jean-Paul Smets committed
339
    """Returns True if all business link with given trade_phase
340 341
    applicable to given explanation are completed.

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

    trade_phase -- a Trade Phase category
    """

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

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

    trade_phase -- a Trade Phase category
    """

359
  def getRemainingTradePhaseList(business_link):
360 361
    """Returns the list of remaining trade phases which to be achieved
    as part of a business process. This list is calculated by analysing 
362 363
    the graph of business link and trade states, starting from a given
    business link. The result if filtered by a list of trade phases. This
364 365 366
    method is useful mostly for production and MRP to manage a distributed
    supply and production chain.

367
    business_link -- a Business Link document
368 369 370

    NOTE: explanation is not involved here because we consider here that
    self is the result of asUnionBusinessProcess and thus only contains
371
    applicable Business Link to a given simulation subtree. Since the list
372 373 374 375 376
    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.
    """

377 378
  def getTradePhaseMovementList(explanation, amount, trade_phase=None, delay_mode=None):
    """Returns a list of movement with appropriate arrow and dates,
379
    based on the Business Link definitions, provided 'amount' and optional
380 381 382
    trade phases. If no trade_phase is provided, the trade_phase defined
    on the Amount is used instead.
    
383 384
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
385 386 387 388 389 390 391 392 393

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

394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
class ISimulationMovementProcess(Interface):
  """Simulation Movemnt Process interface specification

  ISimulationMovementProcess provides help methods to 
  access simulation movements of an explanation and
  gather statistics about them. It is useful to find
  out min dates or max dates related to a business link,
  to a trade phase, to a trade model path, to a 
  trade_model_line, etc.
  """

  def getSimulationMovementList(explanation, trade_phase=None,
     business_link=None, trade_model_path=None, trade_model_line=None, **kw):

    """Returns a list of movement part of the simulation subtrees
    defined by explanation and which match provided parameters. This
    method can be useful for example to list all simulation movements
    related to a phase such as payment, and inspect them.
    
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree

    trade_phase -- optional Trade Phase category

    business_link -- optional Business Link document

    trade_model_path -- optional Trade Model Path document

    trade_model_line --optional Trade Model Line document

    **kw -- other optional parameters which are passed to Catalog API
    """

  def getSimulationMovementStat(explanation, trade_phase=None,
     business_link=None, trade_model_path=None, trade_model_line=None, **kw):

    """Returns statistics for movements part of the simulation subtrees
    defined by explanation and which match provided parameters. This
    method can be useful for example to find the max date of simulation movements
    related to a phase such as payment.
    
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree

    trade_phase -- optional Trade Phase category

    business_link -- optional Business Link document

    trade_model_path -- optional Trade Model Path document

    trade_model_line --optional Trade Model Line document

    **kw -- other optional parameters which are passed to Catalog API
    """

449
class IBusinessProcess(ITradeModelPathProcess, IBusinessLinkProcess, IBuildableBusinessLinkProcess,
450
                       ITradeStateProcess, ITradePhaseProcess, ISimulationMovementProcess):
451 452 453 454 455 456 457
  """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.
  """

458
  def isCompleted(explanation):
459 460 461
    """Returns True is all applicable Trade States and Trade Phases
    are completed in the context of given explanation.

462 463
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
464 465
    """

466
  def isBuildable(explanation):
467
    """Returns True is one Business Link of this Business Process
468 469
    is buildable in the context of given explanation.

470 471
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
472 473 474
    """

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

478 479
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
480 481 482 483 484
    """

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

485 486
    explanation -- an Order, Order Line, Delivery or Delivery Line or
                   Applied Rule which implicitely defines a simulation subtree
487 488

    include_partially_buildable -- if set to True, also build partially
489 490
                                   buildable business link. Else
                                   only build strictly buildable link.
491
    """