diff --git a/product/ERP5/Document/SupplyChain.py b/product/ERP5/Document/SupplyChain.py index 16ba51c336ef2dd2f8ff8cf1130f8287e389d43f..3fb9c707a0cb48187363978766b42b9f1ff2fd26 100644 --- a/product/ERP5/Document/SupplyChain.py +++ b/product/ERP5/Document/SupplyChain.py @@ -140,28 +140,29 @@ class SupplyChain(Path, XMLObject): """ 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 supply_link_list = self.objectValues( portal_type=self.supply_link_portal_type) # Destination of valid link must be the source of the current link. current_node_value = current_supply_link.getCurrentNodeValue() - previous_supply_link_list = [ - x for x in supply_link_list if\ - x.getNextNodeValue() == current_node_value] - # Prevent infinite loop - if current_supply_link in previous_supply_link_list: - previous_supply_link_list.remove(current_supply_link) - # Get only production node in the list, or return the entire list - previous_production_list = [x for x in previous_supply_link_list\ - if x.isProductionSupplyLink()] + + previous_supply_link_list = [] + previous_production_list = [] + for supply_link in supply_link_list: + if supply_link != current_supply_link and \ + supply_link.getNextNodeValue() == current_node_value: + previous_supply_link_list.append(supply_link) + if supply_link.isProductionSupplyLink(): + previous_production_list.append(supply_link) + if 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, 'getPreviousProductionSupplyLinkList')