diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 2b4075e4f7f..99c7c67c770 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -282,16 +282,7 @@ class crm_case(osv.osv): return super(crm_case, self).unlink(cr, uid, ids, context) def stage_next(self, cr, uid, ids, context={}): - ok = False - sid = self.pool.get('crm.case.stage').search(cr, uid, [('object_id.model', '=', self._name)], context=context) - s = {} - previous = {} - for stage in self.pool.get('crm.case.stage').browse(cr, uid, sid, context=context): - section = stage.section_id.id or False - s.setdefault(section, {}) - s[section][previous.get(section, False)] = stage.id - previous[section] = stage.id - + s = self.get_stage_dict(cr, uid, ids, context=context) for case in self.browse(cr, uid, ids, context): section = (case.section_id.id or False) if section in s: @@ -300,7 +291,29 @@ class crm_case(osv.osv): self.write(cr, uid, [case.id], {'stage_id': s[section][st]}) return True - + + def get_stage_dict(self, cr, uid, ids, context={}): + sid = self.pool.get('crm.case.stage').search(cr, uid, [('object_id.model', '=', self._name)], context=context) + s = {} + previous = {} + for stage in self.pool.get('crm.case.stage').browse(cr, uid, sid, context=context): + section = stage.section_id.id or False + s.setdefault(section, {}) + s[section][previous.get(section, False)] = stage.id + previous[section] = stage.id + return s + + def stage_previous(self, cr, uid, ids, context={}): + s = self.get_stage_dict(cr, uid, ids, context=context) + for case in self.browse(cr, uid, ids, context): + section = (case.section_id.id or False) + if section in s: + st = case.stage_id.id or False + s[section] = dict([(v, k) for (k, v) in s[section].iteritems()]) + if st in s[section]: + self.write(cr, uid, [case.id], {'stage_id': s[section][st]}) + return True + def onchange_categ_id(self, cr, uid, ids, categ, context={}): if not categ: return {'value':{}} diff --git a/addons/crm_project/crm_bugs_view.xml b/addons/crm_project/crm_bugs_view.xml index ac6b1a530de..9821471a5ee 100644 --- a/addons/crm_project/crm_bugs_view.xml +++ b/addons/crm_project/crm_bugs_view.xml @@ -72,8 +72,9 @@