Commit 0eb6d3dd authored by Romain Courteaud's avatar Romain Courteaud

Add parameter delivery_relative_url_list to buildDeliveryList.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@3216 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent c14fa82b
...@@ -96,7 +96,8 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -96,7 +96,8 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
) )
security.declareProtected(Permissions.ModifyPortalContent, 'build') security.declareProtected(Permissions.ModifyPortalContent, 'build')
def build(self, applied_rule_uid=None, movement_relative_url_list=[]): def build(self, applied_rule_uid=None, movement_relative_url_list=[],
delivery_relative_url_list=[]):
""" """
Build deliveries from a list of movements Build deliveries from a list of movements
...@@ -115,7 +116,9 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -115,7 +116,9 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
root_group = self.collectMovement(movement_list) root_group = self.collectMovement(movement_list)
# Build # Build
delivery_list = self.buildDeliveryList(root_group) delivery_list = self.buildDeliveryList(
root_group,
delivery_relative_url_list=delivery_relative_url_list)
delivery_after_generation_script_id =\ delivery_after_generation_script_id =\
self.getDeliveryAfterGenerationScriptId() self.getDeliveryAfterGenerationScriptId()
...@@ -204,15 +207,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -204,15 +207,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
Test object properties. Test object properties.
""" """
result = 1 result = 1
LOG("DeliveryBuilder, testObjectProperties", 0,
"object: %s , property_dict: %s" %\
(str(object), str(property_dict)))
for key in property_dict: for key in property_dict:
# XXX FIXME (or not) getter_name = 'get%s' % convertToUpperCase(key)
# Relation is not coherent
# You set it with set...Value
# And get it with get...
new_key = key
if key.endswith("_value"):
new_key = key[:-len("_value")]
getter_name = 'get%s' % convertToUpperCase(new_key)
if hasattr(object, getter_name): if hasattr(object, getter_name):
value = getattr(object, getter_name)() value = getattr(object, getter_name)()
if value != property_dict[key]: if value != property_dict[key]:
...@@ -223,27 +222,28 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -223,27 +222,28 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
break break
return result return result
def buildDeliveryList(self, movement_group): def buildDeliveryList(self, movement_group, delivery_relative_url_list=[]):
""" """
Build deliveries from a list of movements Build deliveries from a list of movements
""" """
# Module where we can create new deliveries # Module where we can create new deliveries
delivery_module = getattr(self, self.getDeliveryModule()) delivery_module = getattr(self, self.getDeliveryModule())
delivery_to_update_list = [self.restrictedTraverse(relative_url) for\
relative_url in delivery_relative_url_list]
# Deliveries we are trying to update # Deliveries we are trying to update
to_update_delivery_list = []
delivery_select_method_id = self.getDeliverySelectMethodId() delivery_select_method_id = self.getDeliverySelectMethodId()
if delivery_select_method_id not in ["", None]: if delivery_select_method_id not in ["", None]:
to_update_delivery_sql_list = getattr(self, delivery_select_method_id)() to_update_delivery_sql_list = getattr(self, delivery_select_method_id)()
to_update_delivery_list = [x.getObject() for x\ delivery_to_update_list.extend([x.getObject() for x\
in to_update_delivery_sql_list] in to_update_delivery_sql_list])
delivery_list = self._deliveryGroupProcessing( delivery_list = self._deliveryGroupProcessing(
delivery_module, delivery_module,
movement_group, movement_group,
self.getDeliveryCollectOrderList(), self.getDeliveryCollectOrderList(),
{}, {},
delivery_to_update_list=to_update_delivery_list) delivery_to_update_list=delivery_to_update_list)
return delivery_list return delivery_list
...@@ -263,10 +263,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -263,10 +263,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
# Get sorted movement for each delivery # Get sorted movement for each delivery
for group in movement_group.getGroupList(): for group in movement_group.getGroupList():
new_delivery_list = self._deliveryGroupProcessing( new_delivery_list = self._deliveryGroupProcessing(
delivery_module, delivery_module,
group, group,
collect_order_list[1:], collect_order_list[1:],
property_dict.copy()) property_dict.copy(),
delivery_to_update_list=delivery_to_update_list)
delivery_list.extend(new_delivery_list) delivery_list.extend(new_delivery_list)
...@@ -374,7 +375,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -374,7 +375,11 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
# Get sorted movement for each delivery line # Get sorted movement for each delivery line
for group in movement_group.getGroupList(): for group in movement_group.getGroupList():
self._deliveryLineGroupProcessing( self._deliveryLineGroupProcessing(
delivery_line, group, collect_order_list[1:], property_dict.copy()) delivery_line,
group,
collect_order_list[1:],
property_dict.copy(),
update_existing_line=update_existing_line)
else: else:
movement_list = movement_group.getMovementList() movement_list = movement_group.getMovementList()
if len(movement_list) != 1: if len(movement_list) != 1:
...@@ -400,15 +405,16 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -400,15 +405,16 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
update_existing_movement=1 update_existing_movement=1
else: else:
for cell in delivery_line.contentValues( for cell_key in delivery_line.getCellKeyList(base_id=base_id):
filter={'portal_type':self.getDeliveryCellPortalType()}): if delivery_line.hasCell(base_id=base_id, *cell_key):
if self.testObjectProperties(cell, property_dict): cell = delivery_line.getCell(base_id=base_id, *cell_key)
# We update a existing cell if self.testObjectProperties(cell, property_dict):
# delivery_ratio of new related movement to this cell # We update a existing cell
# must be updated to 0. # delivery_ratio of new related movement to this cell
update_existing_movement=1 # must be updated to 0.
object_to_update = cell update_existing_movement=1
break object_to_update = cell
break
if object_to_update is None: if object_to_update is None:
# create a new cell # create a new cell
...@@ -462,8 +468,6 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -462,8 +468,6 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
# Update simulation movement # Update simulation movement
simulation_movement.setDeliveryValue(delivery_movement) simulation_movement.setDeliveryValue(delivery_movement)
# Simulation consistency propagation # Simulation consistency propagation
security.declareProtected(Permissions.ModifyPortalContent, security.declareProtected(Permissions.ModifyPortalContent,
'updateFromSimulation') 'updateFromSimulation')
...@@ -514,12 +518,17 @@ class DeliveryBuilder(XMLObject, Amount, Predicate): ...@@ -514,12 +518,17 @@ class DeliveryBuilder(XMLObject, Amount, Predicate):
# Launch delivery creation # Launch delivery creation
if (create_new_delivery == 1) and\ if (create_new_delivery == 1) and\
(rejected_movement_list != []): (rejected_movement_list != []):
movement_relative_url_list = [x.getRelativeUrl() for x in\ movement_relative_url_list = []
rejected_movement_list] for movement in rejected_movement_list:
# XXX FIXME Not very generic...
if movement.__class__.__name__ == "FakeMovement":
movement_relative_url_list.extend(
[x.getRelativeUrl() for x in movement.getMovementList()])
else:
movement_relative_url_list.append(movement.getRelativeUrl())
self.activate().build( self.activate().build(
movement_relative_url_list=movement_relative_url_list) movement_relative_url_list=movement_relative_url_list)
def _deliveryUpdateGroupProcessing(self, delivery, movement_group): def _deliveryUpdateGroupProcessing(self, delivery, movement_group):
""" """
Update delivery movement Update delivery movement
......
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