From 4ab7b7e28dc7be9cde1e941248590f866cb8530d Mon Sep 17 00:00:00 2001
From: Nicolas Delaby <nicolas@nexedi.com>
Date: Mon, 8 Aug 2011 16:55:17 +0200
Subject: [PATCH] Fix sorting

This sorting is inefficient if the id generator of module is random based.
This feature is replaced by a catalog query against creation_date parameter.
---
 product/ERP5/Document/Document.py | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/product/ERP5/Document/Document.py b/product/ERP5/Document/Document.py
index 021f26717b..294513bfd0 100644
--- a/product/ERP5/Document/Document.py
+++ b/product/ERP5/Document/Document.py
@@ -580,7 +580,8 @@ class Document(DocumentExtensibleTraversableMixin, XMLObject, UrlMixin,
       # Find all document with same (reference, version, language)
       kw = dict(portal_type=self.getPortalType(),
                 reference=self.getReference(),
-                where_expression=SQLQuery("validation_state NOT IN ('archived', 'cancelled', 'deleted')"))
+                where_expression=SQLQuery("validation_state NOT IN ('archived', 'cancelled', 'deleted')"),
+                sort_on='creation_date')
       if self.getVersion():
         kw['version'] = self.getVersion()
       if self.getLanguage():
@@ -589,8 +590,6 @@ class Document(DocumentExtensibleTraversableMixin, XMLObject, UrlMixin,
       existing_document = None
       # Select the first one which is not self and which
       # shares the same coordinates
-      document_list = list(document_list)
-      document_list.sort(key=lambda x: x.getId())
       for o in document_list:
         if o.getRelativeUrl() != self.getRelativeUrl() and\
            o.getVersion() == self.getVersion() and\
-- 
2.30.9