From d34186d12f03a2bf0d0f663c6b0f5c9ad16dfbec Mon Sep 17 00:00:00 2001 From: Thibault Francois Date: Fri, 10 Dec 2010 18:54:55 +0100 Subject: [PATCH] [FIX] crm : next/previous_stage behavior bzr revid: tfr@openerp.com-20101210175455-hvoh7pqjnak6b1wh --- addons/crm/crm.py | 115 ++++++++++++++-------------- addons/crm/crm_lead_data.xml | 14 ++-- addons/crm_claim/crm_claim_data.xml | 2 +- 3 files changed, 65 insertions(+), 66 deletions(-) diff --git a/addons/crm/crm.py b/addons/crm/crm.py index c3a4ef44a9c..a91009583f2 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -22,6 +22,7 @@ import time import base64 import tools + from osv import fields from osv import osv from tools.translate import _ @@ -135,6 +136,57 @@ class crm_case(object): user = self.pool.get('res.users').browse(cr, uid, uid, context=context) return user.context_section_id.id or False + def _find_next_stage(self, cr, uid, stage_list, index, current_seq, stage_pool, context=None): + if index + 1 == len(stage_list): + return False + print "cul" + print index + next_stage_id = stage_list[index + 1] + next_stage = stage_pool.browse(cr, uid, next_stage_id, context=context) + if not next_stage: + return False + + next_seq = next_stage.sequence + if (abs(next_seq - current_seq)) >= 1: + print next_stage + return next_stage + else : + return _find_next_stage(cr, uid, stage_list, index + 1, current_seq, stage_pool) + + def stage_change(self, cr, uid, ids, context=None, order='sequence'): + if not context: + context = {} + stage_pool = self.pool.get('crm.case.stage') + stage_type = context and context.get('stage_type','') + current_seq = False + next_stage_id = False + for case in self.browse(cr, uid, ids, context): + print case + next_stage = False + data = {} + print stage_type + domain = [('type', '=', stage_type),('section_ids', '=', case.section_id.id)] + if case.section_id and case.section_id.stage_ids: + domain.append(('id', 'in', map(lambda x: x.id, case.section_id.stage_ids))) + + stages = stage_pool.search(cr, uid, domain, order=order) + current_seq = case.stage_id.sequence + index = -1 + if case.stage_id and case.stage_id.id in stages: + index = stages.index(case.stage_id.id) + print stages + print "call" + next_stage = self._find_next_stage(cr, uid, stages, index, current_seq, stage_pool, context=context) + if next_stage: + next_stage_id = next_stage.id + data = {'stage_id': next_stage.id} + if next_stage.on_change: + data.update({'probability': next_stage.probability}) + self.write(cr, uid, [case.id], data, context=context) + + return next_stage_id + + def stage_next(self, cr, uid, ids, context=None): """This function computes next stage for case from its current stage using available stage for that case type @@ -143,36 +195,10 @@ class crm_case(object): @param uid: the current user’s ID for security checks, @param ids: List of case IDs @param context: A standard dictionary for contextual values""" - if not context: - context = {} - stage_pool = self.pool.get('crm.case.stage') - stage_type = context and context.get('stage_type','') - current_seq = False - for case in self.browse(cr, uid, ids, context): - next_stage = False - data = {} - domain = [('type', '=', stage_type),('section_ids', '=', case.section_id.id)] - if case.section_id and case.section_id.stage_ids: - domain.append(('id', 'in', map(lambda x: x.id, case.section_id.stage_ids))) - stages = stage_pool.search(cr, uid, domain, order='sequence') - index = -1 - if case.stage_id and case.stage_id.id in stages: - index = stages.index(case.stage_id.id) - if index + 1 == len(stages): - return False - else: - next_stage = stages[index + 1] - current_seq = case.stage_id.sequence - if next_stage: - stage = stage_pool.browse(cr, uid, next_stage, context=context) - next_seq = stage.sequence - if current_seq and (next_seq - current_seq) >= 1: - data = {'stage_id': next_stage} - if stage.on_change: - data.update({'probability': stage.probability}) - self.write(cr, uid, [case.id], data, context=context) - return next_stage - + + + return self.stage_change(cr, uid, ids, context=context, order='sequence') + def stage_previous(self, cr, uid, ids, context=None): """This function computes previous stage for case from its current stage using available stage for that case type @@ -181,34 +207,7 @@ class crm_case(object): @param uid: the current user’s ID for security checks, @param ids: List of case IDs @param context: A standard dictionary for contextual values""" - if not context: - context = {} - stage_pool = self.pool.get('crm.case.stage') - stage_type = context and context.get('stage_type','') - for case in self.browse(cr, uid, ids, context): - prev_stage = False - data = {} - domain = [('type', '=', stage_type),('section_ids', '=', case.section_id.id)] - if case.section_id and case.section_id.stage_ids: - domain.append(('id', 'in', map(lambda x: x.id, case.section_id.stage_ids))) - stages = stage_pool.search(cr, uid, domain, order='sequence') - index = 0 - if case.stage_id and case.stage_id.id in stages: - index = stages.index(case.stage_id.id) - if index == 0: - return False - else: - prev_stage = stages[index - 1] - current_seq = case.stage_id.sequence - if prev_stage: - stage = stage_pool.browse(cr, uid, prev_stage, context=context) - prev_seq = stage.sequence - if current_seq and (prev_seq - current_seq) <= 1: - data = {'stage_id': prev_stage} - if stage.on_change: - data.update({'probability': stage.probability}) - self.write(cr, uid, [case.id], data, context=context) - return prev_stage + return self.stage_change(cr, uid, ids, context=context, order='sequence desc') def onchange_partner_id(self, cr, uid, ids, part, email=False): """This function returns value of partner address based on partner diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index f10ba72ef8e..3cb34c49299 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -2,7 +2,12 @@ - + + Lost + + + lead + New @@ -40,12 +45,7 @@ lead - - Lost - - - lead - + Sales Department diff --git a/addons/crm_claim/crm_claim_data.xml b/addons/crm_claim/crm_claim_data.xml index 4d321a42b6e..e917ba5bea6 100644 --- a/addons/crm_claim/crm_claim_data.xml +++ b/addons/crm_claim/crm_claim_data.xml @@ -59,7 +59,7 @@ Won't fix - 11 + 0 claim