Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

How can I sort (reorder) documents in List View

By
Cihan Altinay
on 1/16/14, 8:24 PM 1,741 views

I am not able to reorder the view of documents under Knowledge->Documents in the list view. I can click on the columns and a request is sent to the server but the result looks exactly the same (seemingly unsorted by anything).

The server logs only show the following line anytime I click on any column: webgeo werkzeug: 127.0.0.1 - - [<datetime>] "POST /web/dataset/search_read HTTP/1.1" 200 -

If it makes a difference: there is no filestore but the documents are stored in the DB (default) and I'm using the OpenERP 7.0-20140116 package on debian.

1
Cihan Altinay
On 1/18/14, 1:31 AM

Alright I dug into the source myself and found that the reason I can't sort is the document plugin.

More specifically, the search() method in addons/document/document.py (around line 105) overwrites the search results in order to see if the user is allowed to read the actual directory of the document.

My fix was to apply the same strategy as in base/ir/ir_attachment.py to return the filtered ids but ordered as requested:

ids = [id for id in orig_ids if id in ids]

Now I'm pretty new to openERP so if this is the wrong place to report this, could someone please let me know where to do this instead so it gets fixed upstream?

Here's a full patch (can't attach due to karma<30):

--- a/addons/document/document.py   2012-12-27 12:06:00.000000000 +1000
+++ b/addons/document/document.py   2014-01-18 15:18:33.000000000 +1000
@@ -85,14 +85,14 @@

     def search(self, cr, uid, args, offset=0, limit=None, order=None, context=None, count=False):
         # Grab ids, bypassing 'count'
-        ids = super(document_file, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=False)
-        if not ids:
+        orig_ids = super(document_file, self).search(cr, uid, args, offset=offset, limit=limit, order=order, context=context, count=False)
+        if not orig_ids:
             return 0 if count else []

         # Filter out documents that are in directories that the user is not allowed to read.
         # Must use pure SQL to avoid access rules exceptions (we want to remove the records,
         # not fail), and the records have been filtered in parent's search() anyway.
-        cr.execute('SELECT id, parent_id from ir_attachment WHERE id in %s', (tuple(ids),))
+        cr.execute('SELECT id, parent_id from ir_attachment WHERE id in %s', (tuple(orig_ids),))

         # cont a dict of parent -> attach
         parents = {}
@@ -108,6 +108,8 @@
         for parent_id in visible_parent_ids:
             ids.extend(parents[parent_id])

+        # sort result according to the original sort ordering
+        ids = [id for id in orig_ids if id in ids]
         return len(ids) if count else ids

     def copy(self, cr, uid, id, default=None, context=None):

Thanks! I was dealing with the same problem.

Martin Varela
on 5/13/14, 5:41 PM
0
Martin Varela
On 5/13/14, 5:41 PM

Thanks! I was dealing with the same problem.

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 1/16/14, 8:24 PM
Seen: 1741 times
Last updated: 3/16/15, 8:10 AM