Commit 766c9a01 authored by Julien Muchembled's avatar Julien Muchembled

Simplify Delivery.getMovementList

parent b4b5bcf8
...@@ -241,58 +241,42 @@ class Delivery(XMLObject, ImmobilisationDelivery, ...@@ -241,58 +241,42 @@ class Delivery(XMLObject, ImmobilisationDelivery,
""" """
Return a list of movements Return a list of movements
""" """
movement_portal_type_list = self.getPortalMovementTypeList() movement_portal_type_set = set(
sub_object_list = self.objectValues( self.getPortalObject().getPortalMovementTypeList())
portal_type=movement_portal_type_list, **kw) movement_list = self.objectValues(
if not sub_object_list: portal_type=movement_portal_type_set, **kw)
return [] if movement_list:
if isinstance(portal_type, str): if isinstance(portal_type, str):
portal_type = set((portal_type,)) portal_type = set((portal_type,))
elif isinstance(portal_type, (list, tuple)): elif isinstance(portal_type, (list, tuple)):
portal_type = set(portal_type) portal_type = set(portal_type)
movement_list = [] # Browse lines recursively and collect leafs.
add_movement = movement_list.append stack = [iter(movement_list)]
object_list_stack = [sub_object_list] movement_list = []
stack_index = 0 while stack:
object_list_index_stack = [] for sub_object in stack[-1]:
object_index = 0 content_list = sub_object.objectValues(
while object_list_stack: portal_type=movement_portal_type_set, **kw)
try: if sub_object.hasCellContent():
sub_object = object_list_stack[stack_index][object_index] cell_list = sub_object.getCellValueList()
except IndexError: if len(cell_list) != len(content_list):
object_list_stack.pop() content_list = set(content_list).difference(cell_list)
stack_index -= 1 if content_list:
if object_list_index_stack: stack.append(iter(content_list))
object_index = object_list_index_stack.pop() break
else: else:
content_list = sub_object.objectValues( movement_list.extend(x for x in content_list
portal_type=movement_portal_type_list, **kw) if portal_type is None or x.getPortalType() in portal_type)
elif content_list:
new_stack = [] stack.append(iter(content_list))
if sub_object.hasCellContent(): break
cell_list = sub_object.getCellValueList() elif portal_type is None or \
if len(cell_list) != len(content_list): sub_object.getPortalType() in portal_type:
for x in content_list: movement_list.append(sub_object)
if x not in cell_list: else:
new_stack.append(x) del stack[-1]
else:
for sub_object in content_list:
if (portal_type is None or
sub_object.getPortalType() in portal_type):
add_movement(sub_object)
elif content_list:
new_stack = content_list
elif portal_type is None or sub_object.getPortalType() in portal_type:
add_movement(sub_object)
object_index += 1
if new_stack:
object_list_stack.append(new_stack)
object_list_index_stack.append(object_index)
stack_index += 1
object_index = 0
return movement_list return movement_list
......
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