Commit 249277e3 authored by Yoshinori Okuji's avatar Yoshinori Okuji

Make OrderBuilder.searchMovementList more similar to...

Make OrderBuilder.searchMovementList more similar to DeliveryBuilder.searchMovementList (i.e. customizable). Move SelectMethodError and SelectMovementError from DeliveryBuilder to OrderBuilder, as SelectMethodError is now used in OrderBuilder as well, and it is easier to put them in OrderBuilder to prevent circular dependencies.

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@33334 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7328fa82
...@@ -28,12 +28,10 @@ ...@@ -28,12 +28,10 @@
from AccessControl import ClassSecurityInfo from AccessControl import ClassSecurityInfo
from Products.ERP5Type import Permissions, PropertySheet from Products.ERP5Type import Permissions, PropertySheet
from Products.ERP5.Document.OrderBuilder import OrderBuilder from Products.ERP5.Document.OrderBuilder import OrderBuilder, \
SelectMethodError, SelectMovementError
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
class SelectMethodError(Exception): pass
class SelectMovementError(Exception): pass
class DeliveryBuilder(OrderBuilder): class DeliveryBuilder(OrderBuilder):
""" """
Delivery Builder objects allow to gather multiple Simulation Movements Delivery Builder objects allow to gather multiple Simulation Movements
......
...@@ -42,6 +42,9 @@ class CollectError(Exception): pass ...@@ -42,6 +42,9 @@ class CollectError(Exception): pass
class MatrixError(Exception): pass class MatrixError(Exception): pass
class DuplicatedPropertyDictKeysError(Exception): pass class DuplicatedPropertyDictKeysError(Exception): pass
class SelectMethodError(Exception): pass
class SelectMovementError(Exception): pass
class OrderBuilder(XMLObject, Amount, Predicate): class OrderBuilder(XMLObject, Amount, Predicate):
""" """
Order Builder objects allow to gather multiple Simulation Movements Order Builder objects allow to gather multiple Simulation Movements
...@@ -152,16 +155,7 @@ class OrderBuilder(XMLObject, Amount, Predicate): ...@@ -152,16 +155,7 @@ class OrderBuilder(XMLObject, Amount, Predicate):
delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule()) delivery_module = getattr(self.getPortalObject(), self.getDeliveryModule())
getattr(delivery_module, delivery_module_before_building_script_id)() getattr(delivery_module, delivery_module_before_building_script_id)()
@UnrestrictedMethod def generateMovementListForStockOptimisation(self, **kw):
def searchMovementList(self, applied_rule_uid=None, **kw):
"""
Defines how to query all Simulation Movements which meet certain
criteria (including the above path path definition).
First, select movement matching to criteria define on
DeliveryBuilder.
Then, call script simulation_select_method to restrict
movement_list.
"""
from Products.ERP5Type.Document import newTempMovement from Products.ERP5Type.Document import newTempMovement
movement_list = [] movement_list = []
for attribute, method in [('node_uid', 'getDestinationUid'), for attribute, method in [('node_uid', 'getDestinationUid'),
...@@ -223,6 +217,36 @@ class OrderBuilder(XMLObject, Amount, Predicate): ...@@ -223,6 +217,36 @@ class OrderBuilder(XMLObject, Amount, Predicate):
movement_list.append(movement) movement_list.append(movement)
return movement_list return movement_list
@UnrestrictedMethod
def searchMovementList(self, applied_rule_uid=None, **kw):
"""
Returns a list of simulation movements (or something similar to
simulation movements) to construct a new delivery.
For compatibility, if a simulation select method id is not provided,
a list of movements for predicting future supplies is returned.
You should define a simulation select method id, then it will be used
to calculate the result.
"""
method_id = self.getSimulationSelectMethodId()
if not method_id:
# XXX compatibility
return self.generateMovementListForStockOptimisation(**kw)
select_method = getattr(self.getPortalObject(), method_id)
movement_list = select_method(**kw)
# Make sure that movements are not duplicated.
movement_set = set()
for movement in movement_list:
if movement in movement_set:
raise SelectMethodError('%s returned %s twice or more' % \
(method_id, movement.getRelativeUrl()))
else:
movement_set.add(movement)
return movement_list
def collectMovement(self, movement_list): def collectMovement(self, movement_list):
""" """
group movements in the way we want. Thanks to this method, we are able group movements in the way we want. Thanks to this method, we are able
......
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