diff --git a/product/ERP5/Tool/SolverTool.py b/product/ERP5/Tool/SolverTool.py index b68e02251e56c24bed7f903423ad6a7ae32cc414..069f3aa74679fa938b1b780aa795f209d13f2c16 100644 --- a/product/ERP5/Tool/SolverTool.py +++ b/product/ERP5/Tool/SolverTool.py @@ -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): """ diff --git a/product/ERP5/interfaces/delivery_solver_factory.py b/product/ERP5/interfaces/delivery_solver_factory.py index 1ea16fb19ddb961235641494bbf9fb789d0f0b50..2d3f5c7ca03512fdf577e8a1d40e3dbc2bb6ade9 100644 --- a/product/ERP5/interfaces/delivery_solver_factory.py +++ b/product/ERP5/interfaces/delivery_solver_factory.py @@ -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 """