[FIX] crm : next/previous_stage behavior
bzr revid: tfr@openerp.com-20101210175455-hvoh7pqjnak6b1wh
This commit is contained in:
+57
-58
@@ -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
|
||||
|
||||
@@ -2,7 +2,12 @@
|
||||
<openerp>
|
||||
<data noupdate="1">
|
||||
|
||||
|
||||
<record model="crm.case.stage" id="stage_lead6">
|
||||
<field name="name">Lost</field>
|
||||
<field eval="'0'" name="probability"/>
|
||||
<field eval="'0'" name="sequence"/>
|
||||
<field name="type">lead</field>
|
||||
</record>
|
||||
<!-- CASE STATUS(stage_id) -->
|
||||
<record model="crm.case.stage" id="stage_lead1">
|
||||
<field name="name">New</field>
|
||||
@@ -40,12 +45,7 @@
|
||||
<field name="type">lead</field>
|
||||
</record>
|
||||
|
||||
<record model="crm.case.stage" id="stage_lead6">
|
||||
<field name="name">Lost</field>
|
||||
<field eval="'0'" name="probability"/>
|
||||
<field eval="'6'" name="sequence"/>
|
||||
<field name="type">lead</field>
|
||||
</record>
|
||||
|
||||
|
||||
<record model="crm.case.section" id="section_sales_department">
|
||||
<field name="name">Sales Department</field>
|
||||
|
||||
@@ -59,7 +59,7 @@
|
||||
</record>
|
||||
<record model="crm.case.stage" id="stage_claim3">
|
||||
<field name="name">Won't fix</field>
|
||||
<field name="sequence">11</field>
|
||||
<field name="sequence">0</field>
|
||||
<field name="type">claim</field>
|
||||
</record>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user