Commit fd68f6a4 authored by Nicolas Dumazet's avatar Nicolas Dumazet

one iteration over supply_link_list instead of three list comprehensions


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@35976 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 1e0d3a7a
...@@ -140,27 +140,28 @@ class SupplyChain(Path, XMLObject): ...@@ -140,27 +140,28 @@ class SupplyChain(Path, XMLObject):
""" """
Return the previous SupplyLink list. Return the previous SupplyLink list.
""" """
if current_supply_link is not None: if current_supply_link is None:
# No current_supply_link defined, we need to return the last SupplyLink
return [self.getLastLink()]
else:
# Get all SupplyLink in the SupplyChain # Get all SupplyLink in the SupplyChain
supply_link_list = self.objectValues( supply_link_list = self.objectValues(
portal_type=self.supply_link_portal_type) portal_type=self.supply_link_portal_type)
# Destination of valid link must be the source of the current link. # Destination of valid link must be the source of the current link.
current_node_value = current_supply_link.getCurrentNodeValue() current_node_value = current_supply_link.getCurrentNodeValue()
previous_supply_link_list = [
x for x in supply_link_list if\ previous_supply_link_list = []
x.getNextNodeValue() == current_node_value] previous_production_list = []
# Prevent infinite loop for supply_link in supply_link_list:
if current_supply_link in previous_supply_link_list: if supply_link != current_supply_link and \
previous_supply_link_list.remove(current_supply_link) supply_link.getNextNodeValue() == current_node_value:
# Get only production node in the list, or return the entire list previous_supply_link_list.append(supply_link)
previous_production_list = [x for x in previous_supply_link_list\ if supply_link.isProductionSupplyLink():
if x.isProductionSupplyLink()] previous_production_list.append(supply_link)
if previous_production_list != []: if previous_production_list != []:
previous_supply_link_list = previous_production_list previous_supply_link_list = previous_production_list
else:
# No current_supply_link defined, we need to return the last SupplyLink
previous_supply_link_list = [self.getLastLink()]
# Return result
return previous_supply_link_list return previous_supply_link_list
security.declareProtected(Permissions.View, security.declareProtected(Permissions.View,
......
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