← Back to team overview

openerp-dev-web team mailing list archive

[Merge] lp:~openerp-dev/openobject-addons/trunk-bug-783374-dbr into lp:openobject-addons

 

Devishree Brahmbhatt (OpenERP) has proposed merging lp:~openerp-dev/openobject-addons/trunk-bug-783374-dbr into lp:openobject-addons.

Requested reviews:
  Bhumika (OpenERP) (sbh-openerp)
Related bugs:
  Bug #783374 in OpenERP Addons: "task stages are not sorted by sequence"
  https://bugs.launchpad.net/openobject-addons/+bug/783374

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-783374-dbr/+merge/61704
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-783374-dbr/+merge/61704
Your team OpenERP R&D Team is subscribed to branch lp:~openerp-dev/openobject-addons/trunk-bug-783374-dbr.
=== modified file 'project/project.py'
--- project/project.py	2011-05-16 11:35:55 +0000
+++ project/project.py	2011-05-20 07:11:08 +0000
@@ -718,22 +718,48 @@
         for task in self.browse(cr, uid, ids):
             typeid = task.type_id.id
             types = map(lambda x:x.id, task.project_id.type_ids or [])
+            l = []
+            from operator import itemgetter
             if types:
-                if not typeid:
-                    self.write(cr, uid, task.id, {'type_id': types[0]})
-                elif typeid and typeid in types and types.index(typeid) != len(types)-1:
-                    index = types.index(typeid)
-                    self.write(cr, uid, task.id, {'type_id': types[index+1]})
+                for type in task.project_id.type_ids:
+                    l.append([type.sequence, type.id])
+                l.sort(key=itemgetter(0))
+                if type:
+                    if not typeid:
+                        self.write(cr, uid, task.id, {'type_id': l[0][1]})
+                    else:
+                        for o,sublist in enumerate(l):
+                            position = o
+                            if typeid in sublist:
+                                if position >= len(l)-1:
+                                    return False
+                                else:
+                                    self.write(cr, uid, task.id, {'type_id': l[position+1][1]})
         return True
 
     def prev_type(self, cr, uid, ids, *args):
         for task in self.browse(cr, uid, ids):
             typeid = task.type_id.id
             types = map(lambda x:x.id, task.project_id and task.project_id.type_ids or [])
+            l = []
+            from operator import itemgetter
             if types:
-                if typeid and typeid in types:
-                    index = types.index(typeid)
-                    self.write(cr, uid, task.id, {'type_id': index and types[index-1] or False})
+                for type in task.project_id.type_ids:
+                    l.append([type.sequence, type.id])
+                l.sort(key=itemgetter(0))
+                if type:
+                    if not typeid:
+                        self.write(cr, uid, task.id, {'type_id': False})
+                    else:
+                        for o,sublist in enumerate(l):
+                            position = o
+                            if typeid in sublist:
+                                self.write(cr, uid, task.id, {'type_id': l[position-1][1]})
+                                position = position-1
+                                if position < 0:
+                                    self.write(cr, uid, task.id, {'type_id': False})
+                                else:
+                                    return True
         return True
 
 task()


Follow ups