Commit fed459cb authored by Arnaud Fontaine's avatar Arnaud Fontaine

Fix sorting of movements in getMovementList().

When sorting on int_index for example, the returned movement list
was in reversed order of the expected one.
parent 0d3632e0
...@@ -239,40 +239,61 @@ class Delivery(XMLObject, ImmobilisationDelivery, ...@@ -239,40 +239,61 @@ class Delivery(XMLObject, ImmobilisationDelivery,
'_getMovementList') '_getMovementList')
def _getMovementList(self, portal_type=None, **kw): def _getMovementList(self, portal_type=None, **kw):
""" """
Return a list of movements. Return a list of movements
First, we collect movements by movement type portal types, then
we filter the result by specified portal types.
""" """
movement_portal_type_list = self.getPortalMovementTypeList() movement_portal_type_list = self.getPortalMovementTypeList()
sub_object_list = self.objectValues(
portal_type=movement_portal_type_list, **kw)
if not sub_object_list:
return []
if isinstance(portal_type, str):
portal_type = set((portal_type,))
elif isinstance(portal_type, (list, tuple)):
portal_type = set(portal_type)
movement_list = [] movement_list = []
add_movement = movement_list.append add_movement = movement_list.append
extend_movement = movement_list.extend object_list_stack = [sub_object_list]
sub_object_list = self.objectValues(\ stack_index = 0
portal_type=movement_portal_type_list, **kw) object_list_index_stack = []
extend_sub_object = sub_object_list.extend object_index = 0
append_sub_object = sub_object_list.append while object_list_stack:
while sub_object_list: try:
sub_object = sub_object_list.pop() sub_object = object_list_stack[stack_index][object_index]
content_list = sub_object.objectValues(\ except IndexError:
portal_type=movement_portal_type_list, **kw) object_list_stack.pop()
if sub_object.hasCellContent(): stack_index -= 1
cell_list = sub_object.getCellValueList() if object_list_index_stack:
if len(cell_list) != len(content_list): object_index = object_list_index_stack.pop()
for x in content_list:
if x not in cell_list:
append_sub_object(x)
else:
extend_movement(content_list)
elif content_list:
extend_sub_object(content_list)
else: else:
add_movement(sub_object) content_list = sub_object.objectValues(
if isinstance(portal_type, (list, tuple)): portal_type=movement_portal_type_list, **kw)
return [x for x in movement_list \
if x.getPortalType() in portal_type] new_stack = []
elif portal_type is not None: if sub_object.hasCellContent():
return [x for x in movement_list \ cell_list = sub_object.getCellValueList()
if x.getPortalType() == portal_type] if len(cell_list) != len(content_list):
for x in content_list:
if x not in cell_list:
new_stack.append(x)
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
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
......
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