[MERGE + CLEAN] fix of bug 783374 by dbr
bzr revid: tfr@openerp.com-20110615090826-l6o2ysaf72vzhyx2
This commit is contained in:
commit
9e0223a90c
|
@ -714,27 +714,35 @@ class task(osv.osv):
|
|||
self.log(cr, uid, id, message)
|
||||
return True
|
||||
|
||||
def next_type(self, cr, uid, ids, *args):
|
||||
def _change_type(self, cr, uid, ids, next, *args):
|
||||
"""
|
||||
go to the next stage
|
||||
if next is False, go to previous stage
|
||||
"""
|
||||
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 [])
|
||||
if types:
|
||||
if task.project_id.type_ids:
|
||||
typeid = task.type_id.id
|
||||
types_seq={}
|
||||
for type in task.project_id.type_ids :
|
||||
types_seq[type.id] = type.sequence
|
||||
if next:
|
||||
types = sorted(types_seq.items(), lambda x, y: cmp(x[1], y[1]))
|
||||
else:
|
||||
types = sorted(types_seq.items(), lambda x, y: cmp(y[1], x[1]))
|
||||
sorted_types = [x[0] for x in 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]})
|
||||
self.write(cr, uid, task.id, {'type_id': sorted_types[0]})
|
||||
elif typeid and typeid in sorted_types and sorted_types.index(typeid) != len(sorted_types)-1:
|
||||
index = sorted_types.index(typeid)
|
||||
self.write(cr, uid, task.id, {'type_id': sorted_types[index+1]})
|
||||
return True
|
||||
|
||||
def next_type(self, cr, uid, ids, *args):
|
||||
return self._change_type(cr, uid, ids, True, *args)
|
||||
|
||||
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 [])
|
||||
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})
|
||||
return True
|
||||
return self._change_type(cr, uid, ids, False, *args)
|
||||
|
||||
|
||||
task()
|
||||
|
||||
|
|
Loading…
Reference in New Issue