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
No related merge requests found
......@@ -28,6 +28,7 @@
##############################################################################
import zope.interface
import re
from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, interfaces
......@@ -51,44 +52,34 @@ class SolverTool(TypeProvider):
security = ClassSecurityInfo()
# Declarative interfaces
zope.interface.implements(interfaces.IDeliverySolverFactory, )
zope.interface.implements(interfaces.IDeliverySolverFactory,)
# IDeliverySolverFactory implementation
def newDeliverySolver(self, class_name, movement_list):
def newDeliverySolver(self, portal_type, movement_list):
"""
"""
__import__('%s.%s' % (DeliverySolver.__name__, class_name))
solver_class = getattr(getattr(DeliverySolver, class_name), class_name)
return solver_class(movement_list)
Return a new instance of delivery solver of the given
portal_type and with appropriate parameters.
def getDeliverySolverClassNameList(self):
"""
"""
# XXX Hardcoded for now. We need a new registration system for
# delivery solvers.
return ['FIFO', 'LIFO', 'MinPrice',]
portal_type -- the portal type of the delivery solver.
def getDeliverySolverTranslatedItemList(self, class_name_list=None):
movement_list -- movements to initialise the instance with
"""
"""
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]))
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 getDeliverySolverTranslatedTitle(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).title)
def getDeliverySolverTranslatedDescription(self, class_name):
"""
"""
__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