Commit b83d679d authored by Kazuhiko Shiozaki's avatar Kazuhiko Shiozaki

clean up IDeliverySolverFactory and its implementation.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@36868 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 208e9123
......@@ -28,6 +28,7 @@
##############################################################################
import zope.interface
import re
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, interfaces
......@@ -49,46 +50,36 @@ class SolverTool(TypeProvider):
# Declarative Security
security = ClassSecurityInfo()
# Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolverFactory, )
zope.interface.implements(interfaces.IDeliverySolverFactory,)
# IDeliverySolverFactory implementation
def newDeliverySolver(self, class_name, movement_list):
"""
"""
__import__('%s.%s' % (DeliverySolver.__name__, class_name))
solver_class = getattr(getattr(DeliverySolver, class_name), class_name)
return solver_class(movement_list)
def getDeliverySolverClassNameList(self):
"""
def newDeliverySolver(self, portal_type, movement_list):
"""
# XXX Hardcoded for now. We need a new registration system for
# delivery solvers.
return ['FIFO', 'LIFO', 'MinPrice',]
Return a new instance of delivery solver of the given
portal_type and with appropriate parameters.
def getDeliverySolverTranslatedItemList(self, class_name_list=None):
"""
"""
return sorted([(self.getDeliverySolverTranslatedTitle(x), x) \
for x in self.getDeliverySolverClassNameList() \
if class_name_list is None or x in class_name_list],
key=lambda x:str(x[0]))
portal_type -- the portal type of the delivery solver.
def getDeliverySolverTranslatedTitle(self, class_name):
movement_list -- movements to initialise the instance with
"""
"""
__import__('%s.%s' % (DeliverySolver.__name__, class_name))
return translateString(
getattr(getattr(DeliverySolver, class_name), class_name).title)
solver_type = self._getOb(portal_type)
solver_class = re.sub('^add', 'newTemp',
solver_type.getTypeFactoryMethodId())
module = __import__('Products.ERP5Type.Document', globals(), locals(),
[solver_class])
tmp_solver = getattr(module, solver_class)(self, 'delivery_solver')
tmp_solver.setDeliveryValueList(movement_list)
return tmp_solver
def getDeliverySolverTranslatedDescription(self, class_name):
def getDeliverySolverTranslatedItemList(self, portal_type_list=None):
"""
"""
__import__('%s.%s' % (DeliverySolver.__name__, class_name))
return translateString(
getattr(getattr(DeliverySolver, class_name), class_name).__doc__)
return sorted([(translateString(x), 'portal_solvers/%s' % x) \
for x in self.getPortalDeliverySolverTypeList() \
if portal_type_list is None or x in portal_type_list],
key=lambda x:str(x[0]))
def getSolverProcessValueList(self, delivery_or_movement=None, validation_state=None):
"""
......
......@@ -35,51 +35,24 @@ class IDeliverySolverFactory(Interface):
IDeliverySolverFactory provides methods to create delivery
solver instances and retrieve metadata related to delivery
solvers.
NOTE:
- wouldn't it be better to use ERP5 document
classes for delivery solvers.
(only meaningful reason: use activities to
setTotalQuantity on 10,000+ movements)
"""
def newDeliverySolver(class_name, movement_list):
def newDeliverySolver(portal_type, movement_list):
"""
Return a new instance of delivery solver of the given
class_name and with appropriate parameters.
portal_type and with appropriate parameters.
class_name -- the class name of the delivery solver.
portal_type -- the portal_type of the delivery solver.
movement_list -- movements to initialise the instance with
"""
def getDeliverySolverClassNameList():
"""
Return the list of class names of available delivery solvers.
"""
def getDeliverySolverTranslatedItemList(class_name_list=None):
def getDeliverySolverTranslatedItemList(portal_type_list=None):
"""
Return the list of translated titles and class names of available
Return the list of translated titles and portal types of available
delivery solvers. Use this method to fill listfields in user interface
forms.
class_name_list -- optional parameter to filter results only
with provided class names
"""
def getDeliverySolverTranslatedTitle(class_name):
"""
Return the title to be used in the user interface for the
delivery solver with given class_name
class_name -- the class name of a delivery solver
"""
def getDeliverySolverTranslatedDescription(class_name):
"""
Return the description to be used in the user interface for the
delivery solver with given class_name
class_name -- the class name of a delivery solver
portal_type_list -- optional parameter to filter results only
with provided portal types
"""
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