← Back to team overview

openerp-community-reviewer team mailing list archive

[Merge] lp:~hirt/ocb-addons/6.1-sort-events-mat into lp:ocb-addons/6.1

 

Etienne Hirt has proposed merging lp:~hirt/ocb-addons/6.1-sort-events-mat into lp:ocb-addons/6.1.

Requested reviews:
  OpenERP Community Backports Team (ocb)
Related bugs:
  Bug #1023322 in OpenERP Addons: ""Order by" in meetings not working due to  get_recurrent_ids(def search) method of calendar.event"
  https://bugs.launchpad.net/openobject-addons/+bug/1023322

For more details, see:
https://code.launchpad.net/~hirt/ocb-addons/6.1-sort-events-mat/+merge/196434

[FIX] correct order-by for crm_meetings with patch that is targeted for lp:openobject-addons/7.0
Consider merging also in ocb-addons 
-- 
https://code.launchpad.net/~hirt/ocb-addons/6.1-sort-events-mat/+merge/196434
Your team OpenERP Community Backports Team is requested to review the proposed merge of lp:~hirt/ocb-addons/6.1-sort-events-mat into lp:ocb-addons/6.1.
=== modified file 'base_calendar/base_calendar.py'
--- base_calendar/base_calendar.py	2012-03-05 14:35:54 +0000
+++ base_calendar/base_calendar.py	2013-11-23 23:07:49 +0000
@@ -30,6 +30,7 @@
 import re
 import time
 import tools
+from operator import itemgetter
 
 months = {
     1: "January", 2: "February", 3: "March", 4: "April", \
@@ -85,7 +86,7 @@
                 return (int(real_id), real_date, end.strftime("%Y-%m-%d %H:%M:%S"))
             return int(real_id)
 
-    return base_calendar_id and int(base_calendar_id) or base_calendar_id
+    return base_calendar_id and int(base_calendar_id) or base_calendar_id 
 
 def real_id2base_calendar_id(real_id, recurrent_date):
     """
@@ -1303,6 +1304,18 @@
                 res.append(base_calendar_id2real_id(id))
             return res
 
+    def _multikeysort(self, items, columns):
+       
+        comparers = [ ((itemgetter(col[1:].strip()), -1) if col.startswith('-') else (itemgetter(col.strip()), 1)) for col in columns]
+        def comparer(left, right):
+            for fn, mult in comparers:
+                result = cmp(fn(left), fn(right))
+                if result:
+                    return mult * result
+                else:
+                    return 0
+        return sorted(items, cmp=comparer)
+
     def search(self, cr, uid, args, offset=0, limit=0, order=None, context=None, count=False):
         context = context or {}
         args_without_date = []
@@ -1327,6 +1340,17 @@
                                  0, 0, order, context, count=False)
         if context.get('virtual_id', True):
             res = self.get_recurrent_ids(cr, uid, res, args, limit, context=context)
+            if order:
+                order = order.split(',')
+                sortby = {}
+                for o in order:
+                    spl = o.split()
+                    sortby[spl[0]] = spl[1]
+                fields = sortby.keys()
+                ordered = self.read(cr, uid, res, fields=fields, context=context)
+                res = self._multikeysort(ordered, [key.split()[0] if sortby[key.split()[0]] == 'ASC' else '-%s' % key.split()[0] for key in order])
+                res = [x['id'] for x in res]                                                      
+                                                      
 
         if count:
             return len(res)


Follow ups