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 @@ ...@@ -28,6 +28,7 @@
############################################################################## ##############################################################################
import zope.interface import zope.interface
import re
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, interfaces from Products.ERP5Type import Permissions, interfaces
...@@ -51,44 +52,34 @@ class SolverTool(TypeProvider): ...@@ -51,44 +52,34 @@ class SolverTool(TypeProvider):
security = ClassSecurityInfo() security = ClassSecurityInfo()
# Declarative interfaces # Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolverFactory, ) zope.interface.implements(interfaces.IDeliverySolverFactory,)
# IDeliverySolverFactory implementation # IDeliverySolverFactory implementation
def newDeliverySolver(self, class_name, movement_list): def newDeliverySolver(self, portal_type, movement_list):
""" """
""" Return a new instance of delivery solver of the given
__import__('%s.%s' % (DeliverySolver.__name__, class_name)) portal_type and with appropriate parameters.
solver_class = getattr(getattr(DeliverySolver, class_name), class_name)
return solver_class(movement_list)
def getDeliverySolverClassNameList(self): portal_type -- the portal type of the delivery solver.
"""
"""
# XXX Hardcoded for now. We need a new registration system for
# delivery solvers.
return ['FIFO', 'LIFO', 'MinPrice',]
def getDeliverySolverTranslatedItemList(self, class_name_list=None): movement_list -- movements to initialise the instance with
""" """
""" solver_type = self._getOb(portal_type)
return sorted([(self.getDeliverySolverTranslatedTitle(x), x) \ solver_class = re.sub('^add', 'newTemp',
for x in self.getDeliverySolverClassNameList() \ solver_type.getTypeFactoryMethodId())
if class_name_list is None or x in class_name_list], module = __import__('Products.ERP5Type.Document', globals(), locals(),
key=lambda x:str(x[0])) [solver_class])
tmp_solver = getattr(module, solver_class)(self, 'delivery_solver')
tmp_solver.setDeliveryValueList(movement_list)
return tmp_solver
def getDeliverySolverTranslatedTitle(self, class_name): def getDeliverySolverTranslatedItemList(self, portal_type_list=None):
""" """
""" """
__import__('%s.%s' % (DeliverySolver.__name__, class_name)) return sorted([(translateString(x), 'portal_solvers/%s' % x) \
return translateString( for x in self.getPortalDeliverySolverTypeList() \
getattr(getattr(DeliverySolver, class_name), class_name).title) if portal_type_list is None or x in portal_type_list],
key=lambda x:str(x[0]))
def getDeliverySolverTranslatedDescription(self, class_name):
"""
"""
__import__('%s.%s' % (DeliverySolver.__name__, class_name))
return translateString(
getattr(getattr(DeliverySolver, class_name), class_name).__doc__)
def getSolverProcessValueList(self, delivery_or_movement=None, validation_state=None): def getSolverProcessValueList(self, delivery_or_movement=None, validation_state=None):
""" """
......
...@@ -35,51 +35,24 @@ class IDeliverySolverFactory(Interface): ...@@ -35,51 +35,24 @@ class IDeliverySolverFactory(Interface):
IDeliverySolverFactory provides methods to create delivery IDeliverySolverFactory provides methods to create delivery
solver instances and retrieve metadata related to delivery solver instances and retrieve metadata related to delivery
solvers. 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 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 movement_list -- movements to initialise the instance with
""" """
def getDeliverySolverClassNameList(): def getDeliverySolverTranslatedItemList(portal_type_list=None):
"""
Return the list of class names of available delivery solvers.
"""
def getDeliverySolverTranslatedItemList(class_name_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 delivery solvers. Use this method to fill listfields in user interface
forms. forms.
class_name_list -- optional parameter to filter results only portal_type_list -- optional parameter to filter results only
with provided class names with provided portal types
"""
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
""" """
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