diff --git a/addons/crm/crm.py b/addons/crm/crm.py index 9798fd09a4e..c3a4ef44a9c 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -146,11 +146,12 @@ class crm_case(object): if not context: context = {} stage_pool = self.pool.get('crm.case.stage') - model = self._name + 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 = [('object_id.model', '=', model),('section_ids', '=', case.section_id.id)] + 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') @@ -161,9 +162,12 @@ class crm_case(object): return False else: next_stage = stages[index + 1] + current_seq = case.stage_id.sequence if next_stage: - data = {'stage_id': 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) @@ -180,11 +184,11 @@ class crm_case(object): if not context: context = {} stage_pool = self.pool.get('crm.case.stage') - model = self._name + stage_type = context and context.get('stage_type','') for case in self.browse(cr, uid, ids, context): prev_stage = False data = {} - domain = [('object_id.model', '=', model),('section_ids', '=', case.section_id.id)] + 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') @@ -195,9 +199,12 @@ class crm_case(object): return False else: prev_stage = stages[index - 1] + current_seq = case.stage_id.sequence if prev_stage: - data = {'stage_id': 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) @@ -482,27 +489,27 @@ class crm_case_stage(osv.osv): _columns = { 'name': fields.char('Stage Name', size=64, required=True, translate=True), 'sequence': fields.integer('Sequence', help="Gives the sequence order when displaying a list of case stages."), - 'object_id': fields.many2one('ir.model', 'Object Name'), 'probability': fields.float('Probability (%)', required=True, help="This percentage depicts the default/average probability of the Case for this stage to be a success"), 'on_change': fields.boolean('Change Probability Automatically', \ help="Change Probability on next and previous stages."), - 'requirements': fields.text('Requirements') + 'requirements': fields.text('Requirements'), + 'type': fields.selection([('lead','Lead'),('opportunity','Opportunity'),('claim','Claim'), ('fundraising','Fundraising')], 'Type'), } - def _find_object_id(self, cr, uid, context=None): - """Finds id for case object + + def _find_stage_type(self, cr, uid, context=None): + """Finds type of stage according to object. @param self: The object pointer @param cr: the current row, from the database cursor, @param uid: the current user’s ID for security checks, @param context: A standard dictionary for contextual values """ - object_id = context and context.get('object_id', False) or False - ids = self.pool.get('ir.model').search(cr, uid, [('model', '=', object_id)]) - return ids and ids[0] + type = context and context.get('type', '') or '' + return type _defaults = { 'sequence': lambda *args: 1, 'probability': lambda *args: 0.0, - 'object_id' : _find_object_id + 'type': _find_stage_type, } crm_case_stage() diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index e0bed8934f2..8cc45c75e57 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -135,7 +135,7 @@ class crm_lead(crm_case, osv.osv): ],'Type', help="Type is used to separate Leads and Opportunities"), 'priority': fields.selection(crm.AVAILABLE_PRIORITIES, 'Priority'), 'date_closed': fields.datetime('Closed', readonly=True), - 'stage_id': fields.many2one('crm.case.stage', 'Stage'), + 'stage_id': fields.many2one('crm.case.stage', 'Stage', domain="[('type','=','lead')]"), 'user_id': fields.many2one('res.users', 'Salesman',help='By Default Salesman is Administrator when create New User'), 'referred': fields.char('Referred By', size=64), 'date_open': fields.datetime('Opened', readonly=True), @@ -150,6 +150,19 @@ class crm_lead(crm_case, osv.osv): \nIf the case needs to be reviewed then the state is set to \'Pending\'.'), 'message_ids': fields.one2many('mailgate.message', 'res_id', 'Messages', domain=[('model','=',_name)]), } + + def _get_stage_id(self, cr, uid, context=None): + """Finds type of stage according to object. + @param self: The object pointer + @param cr: the current row, from the database cursor, + @param uid: the current user’s ID for security checks, + @param context: A standard dictionary for contextual values + """ + if context is None: + context = {} + type = context and context.get('stage_type', '') + stage_ids = self.pool.get('crm.case.stage').search(cr, uid, [('type','=',type),('sequence','>=',1)]) + return stage_ids and stage_ids[0] or False _defaults = { 'active': lambda *a: 1, @@ -160,6 +173,7 @@ class crm_lead(crm_case, osv.osv): 'section_id': crm_case._get_section, 'company_id': lambda s, cr, uid, c: s.pool.get('res.company')._company_default_get(cr, uid, 'crm.lead', context=c), 'priority': lambda *a: crm.AVAILABLE_PRIORITIES[2][0], + 'stage_id': _get_stage_id, } def onchange_partner_address_id(self, cr, uid, ids, add, email=False): @@ -297,7 +311,7 @@ class crm_lead(crm_case, osv.osv): return super(crm_lead,self).write(cr, uid, ids, vals, context) def stage_next(self, cr, uid, ids, context=None): - stage = super(crm_lead, self).stage_next(cr, uid, ids, context) + stage = super(crm_lead, self).stage_next(cr, uid, ids, context=context) if stage: stage_obj = self.pool.get('crm.case.stage').browse(cr, uid, stage, context=context) if stage_obj.on_change: diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index 2a49e43e683..f10ba72ef8e 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -8,28 +8,28 @@ New - + lead Qualification - + lead Proposition - + lead Negotiation - + lead @@ -37,14 +37,14 @@ - + lead Lost - + lead diff --git a/addons/crm/crm_lead_menu.xml b/addons/crm/crm_lead_menu.xml index 6c74dccac15..2fff1b57d3c 100644 --- a/addons/crm/crm_lead_menu.xml +++ b/addons/crm/crm_lead_menu.xml @@ -9,7 +9,7 @@ ['|', ('type','=','lead'), ('type','=',False)] - {'search_default_current':1, 'default_type': 'lead', 'search_default_section_id': section_id} + {'search_default_current':1, 'default_type': 'lead', 'search_default_section_id': section_id, 'stage_type': 'lead'} 'Leads' allows you to manage and keep track of all first potential interests of a partner in one of your products or services. A lead is a first, unqualified, contact with a prospect or customer. After being qualified, a lead can be converted into a business opportunity with the creation of the related partner for further detailed tracking of any linked activities. You can use leads when you import a database of prospects or to integrate your website's contact form with OpenERP. diff --git a/addons/crm/crm_lead_view.xml b/addons/crm/crm_lead_view.xml index cda3c4fcc1f..87eb7ff3bd1 100644 --- a/addons/crm/crm_lead_view.xml +++ b/addons/crm/crm_lead_view.xml @@ -9,8 +9,8 @@ crm.case.stage form - [('object_id.model', '=', 'crm.lead')] - {'object_id':'crm.lead'} + [('type', '=', 'lead')] + {'type':'lead'} Create specific stages that will help your sales better organise their sales pipeline by maintaining them to their leads and sales opportunities. It will allow them to easily track how is positioned a specific lead or opportunity in the sales cycle. @@ -57,11 +57,11 @@ - +