Commit 0ff785b7 authored by Jean-Paul Smets's avatar Jean-Paul Smets

Early revisions of interfaces - experimental

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@26596 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 93ff3f32
##############################################################################
#
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
# 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.
#
##############################################################################
from Interface import Interface
class IAmount(Interface):
"""
An amount represents a quantity of a given resource
in a given quantity unit. Optional efficiency
or (exclusive) profit/loss quantity can be specified
in order to represent a profit or loss ratio to take
into account in calculations.
The Amount interface is useful each time
we need to add or substract amounts of resources
independently of a movement. This is the case for example
for all Transformation related classes.
Equations:
net_quantity = quantity * efficiency
TODO:
consider how to make Interface compatible
with accessor generation (ex. getResource)
Addition:
target_quantity is obsolete, it is never defined.
"""
# Core API
def getQuantity():
"""
Returns the quantity of the resource
in the unit specified by the Amount
"""
def getResource():
"""
Returns the resource category relative URL
of the Amount
"""
def getQuantityUnit():
"""
Returns the quantity unit category relative URL
of the Amount
"""
def isCancellationAmount():
"""
A cancellation amount must be interpreted
reversely write to the sign of qauntity.
For example, a negative credit for a cancellation
amount is a negative credit, not a positive
debit.
A negative production quantity for a cancellation
amount is a cancelled production, not
a consumption
"""
# Net Quantity API
def getEfficiency():
"""
Returns a value which is rate affect to the net quantity
Only used for transformation for now.
"""
def getNetQuantity():
"""
Returns affected quantity by some optional effects.
"""
# Price API
def getPrice():
"""
Returns price
"""
def getTotalPrice():
"""
Returns total price for the number of items
"""
# Conversion API
def getConvertedQuantity():
"""
Returns the quantity converted by the resource
"""
def getNetConvertedQuantity():
"""
Returns the net quantity converted by the resource
"""
# Make it possible to add amounts
def __add__(value):
"""
Add
If the amount can understands argument as amount for addition,
returns calculated
"""
def __sub__(value):
"""
Substract
If the amount can understands argument as amount for substraction,
returns calculated
"""
def __mul__(value):
"""
Multiply
If the amount can understands argument as efficiency for multiplication,
returns calculated
"""
def __div__(value):
"""
Devide
If the amount can understands argument as efficiency for division,
returns calculated
"""
...@@ -29,33 +29,16 @@ ...@@ -29,33 +29,16 @@
from zope.interface import Interface from zope.interface import Interface
class IArrow(Interface): class IArrow(Interface):
""" """The Arrow lists the methods which are available to
The Arrow lists the methods which are available to
access all source and destination categories of access all source and destination categories of
a movement or of a delivery. a movement or of a delivery.
""" """
def getSourceArrowBaseCategoryList(): def getSourceArrowBaseCategoryList():
""" """Returns all categories which are used to define the source
Returns all categories which are used to define the source
of this Arrow of this Arrow
""" """
def getDestinationArrowBaseCategoryList(): def getDestinationArrowBaseCategoryList():
""" """Returns all categories which are used to define the destination
Returns all categories which are used to define the destination
of this Arrow of this Arrow
""" """
\ No newline at end of file
def _getSourceArrowList(spec=(), filter=None, portal_type=(), base=0,
keep_default=1, checked_permission=None):
"""
Returns all categories which define the source of the
document (ex. source, source_section, etc.)
"""
def _getDestinationArrowList(spec=(), filter=None, portal_type=(), base=0,
keep_default=1, checked_permission=None):
"""
Returns all categories which define the destination of the
document (ex. destination, destination_section, etc.)
"""
##############################################################################
#
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
# 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.
#
##############################################################################
from Interface import Interface
class IMovement(Interface):
"""
A movement represents amount of resource how are changed
on the path. The movement should be ables to provide how
amount is/was existed on node both source and destination.
Because of movement may be affected on path.
The movement interface can be represents any kind of delivery.
It is useful to represent changed of between nodes.
Equations:
destination_quantity = source_quantity * efficiency
(These values can be calculated by Amount)
Production/Consumption
(A -> B)
if source_quantity > 0 and destination_quantity > 0
production_quantity = destination_quantity
consumption_quantity = source_quantity
if source_quantity < 0 and destination_quantity < 0
production_quantity = - source_quantity
consumption_quantity = - destination_quantity
if source_quantity < 0 and destination_quantity > 0
or
source_quantity > 0 and destination_quantity < 0
raise
(A -> Nothing)
if source_quantity > 0
consumption_quantity = source_quantity
production_quantity = 0
if source_quantity < 0
consumption_quantity = 0
production_quantity = - source_quantity
(Nothing -> B)
if destination_quantity > 0
consumption_quantity = 0
production_quantity = destination_quantity
if destination_quantity < 0
consumption_quantity = - destination_quantity
production_quantity = 0
Credit/Debit
(A -> B)
if source_quantity > 0 and destination_quantity > 0
source_credit = - source_quantity
source_debit = source_quantity
destination_credit = destination_quantity
destination_debit = - destination_quantity
if source_quantity < 0 and destination_quantity < 0
source_credit = source_quantity
source_debit = - source_quantity
destination_credit = - destination_quantity
destination_debit = destination_quantity
if source_quantity < 0 and destination_quantity > 0
or
source_quantity > 0 and destination_quantity < 0
raise
(A -> Nothing)
if source_quantity > 0
source_credit = source_quantity
source_debit = - source_quantity
destination_credit = 0
destination_debit = 0
if source_quantity < 0
source_credit = - source_quantity
source_debit = source_quantity
destination_credit = 0
destination_debit = 0
(Nothing -> B)
if destination_quantity > 0
source_credit = 0
source_debit = 0
destination_credit = destination_quantity
destination_debit = - destination_quantity
if destination_quantity < 0
source_credit = 0
source_debit = 0
destination_credit = - destination_quantity
destination_debit = destination_quantity
source_asset_price = price
destination_asset_price = price
"""
# Conversion API for cataloging
def getConvertedSourceQuantity():
"""
Returns the quantity how are removed
from source by the movement
"""
def getConvertedDestinationQuantity():
"""
Returns the quantity how are reached
to destination by the movement
"""
# Helper methods for Production
def getConsumptionQuantity():
"""
Returns the quantity how are consumed
on the path by the movement
"""
def getProductionQuantity():
"""
Returns the quantity how are produced
on the path by the movement
"""
# Helper methods for Accounting
def getSourceDebit():
"""
Returns the quantity how are debited
from source node by the movement
"""
def getSourceCredit():
"""
Returns the quantity how are credited
from source node by the movement
"""
def getDestinationDebit():
"""
Returns the quantity how are debited
to destination node by the movement
"""
def getDestinationCredit():
"""
Returns the quantity how are credited
to destination node by the movement
"""
def getSourceAssetPrice():
"""
Returns the price how are taken
from source by the movement
"""
def getSourceInventoriatedTotalAssetPrice():
"""
Returns a price which can be used
to calculate stock value (asset)
"""
def getSourceInventoriatedTotalAssetDebit():
"""
Returns the debit part of inventoriated
source total asset price.
"""
def getSourceInventoriatedTotalAssetCredit():
"""
Returns the credit part of inventoriated
source total asset price.
"""
def getSourceAssetDebit():
"""
Return the debit part of the source total
asset price.
"""
def getSourceAssetCredit():
"""
Return the credit part of the source total
asset price.
"""
def getDestinationAssetPrice():
"""
Returns the price how are given
to destination by the movement
"""
def getDestinationInventoriatedTotalAssetPrice():
"""
Returns a price which can be used
to calculate stock value (asset)
"""
def getDestinationInventoriatedTotalAssetDebit():
"""
Returns the debit part of inventoriated
destination total asset price.
"""
def getDestinationInventoriatedTotalAssetCredit():
"""
Returns the credit part of inventoriated
destination total asset price.
"""
def getDestinationAssetDebit():
"""
Return the debit part of the destination total
asset price.
"""
def getDestinationAssetCredit():
"""
Return the credit part of the destination total
asset price.
"""
##############################################################################
#
# Copyright (c) 2009 Nexedi SARL and Contributors. All Rights Reserved.
# 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.
#
##############################################################################
from Interface import Interface
class ISimulationMovement(Interface):
"""
The SimulationMovement interface
introduces the possibility to define
quantity errors between the simulation
and the reality.
In short: parent applied rules use the Movement
API to define quantity.
Child applied rules use the Delivered API
to use appropriate values which include
the delivery_error.
DeliverySolver either solve divergence by
setting the delivery_error (then no target
solver needed, at least for quantity) or
by changing the quantity (then TargetSolver
is needed to backtrack the quantity).
quantity(SM) + delivery_error (SM) =
quantity(DL) * delivery_ratio(SM)
"""
# Delivery API
def getDeliveryRatio():
"""
Returns ratio to apply on the quantity
property of the corresponding delivery
to obtain the current quantity
"""
def getDeliveryError():
"""
Returns correction to make the match
between delivery quantity and simulation
quantity consistent
"""
def getDeliveryQuantity():
"""
Returns quantity which was actually
shipped, taking into account the errors
of the simulation fixed by the delivery
quantity + delivery_error
"""
def getDeliveryConvertedQuantity():
"""
Returns delivery quantity converted by the resource
"""
# Divergence API
def isConvergent():
"""
Returns the simulation movement is convergent
or not, with related the delivery
"""
def isDivergent():
"""
Returns the simulation movement is divergent
or not, to related the delivery
"""
def getDivergenceList():
"""
Returns listed divergences which is made by tester
of parent applied rule
Each divergence has why the delivery was judged
"""
def isFrozen():
"""
Returns status of the simulation movement, it is
frozen or not, once it is frozen, all operations
can not change anything of the simulation movement
"""
def isSimulated():
"""
Returns the simulation movement is simulated or not
When the simulation movement is simulated, all operations
can not remove it, but can update, because related delivery
to be orphan, if can remove it
"""
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment