diff --git a/addons/crm/crm.py b/addons/crm/crm.py index d4758d969fa..0c5d0f1e5ae 100644 --- a/addons/crm/crm.py +++ b/addons/crm/crm.py @@ -63,8 +63,7 @@ class crm_stage(osv.Model): _defaults = { 'sequence': 1, - 'probability': 0.0, - 'on_change': True, + 'probability': 1.0, 'fold': False, 'type': 'both', 'case_default': True, diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 42dfc8103cf..70bdb498865 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -300,8 +300,8 @@ class crm_lead(format_address, osv.osv): if not stage.on_change: return {'value': {}} vals = {'probability': stage.probability} - if stage.probability >= 100 or (stage.probability == 0 and stage.sequence > 1): - vals['date_closed'] = fields.datetime.now() + if stage.on_change and (stage.probability >= 100 or (stage.probability == 0 and stage.sequence > 1)): + vals['date_closed'] = fields.datetime.now() return {'value': vals} def on_change_partner_id(self, cr, uid, ids, partner_id, context=None): @@ -384,7 +384,7 @@ class crm_lead(format_address, osv.osv): """ stages_leads = {} for lead in self.browse(cr, uid, ids, context=context): - stage_id = self.stage_find(cr, uid, [lead], lead.team_id.id or False, [('probability', '=', 0.0), ('fold', '=', True), ('sequence', '>', 1)], context=context) + stage_id = self.stage_find(cr, uid, [lead], lead.team_id.id or False, [('probability', '=', 0.0), ('on_change', '=', True), ('sequence', '>', 1)], context=context) if stage_id: if stages_leads.get(stage_id): stages_leads[stage_id].append(lead.id) @@ -403,7 +403,7 @@ class crm_lead(format_address, osv.osv): """ stages_leads = {} for lead in self.browse(cr, uid, ids, context=context): - stage_id = self.stage_find(cr, uid, [lead], lead.team_id.id or False, [('probability', '=', 100.0), ('fold', '=', True)], context=context) + stage_id = self.stage_find(cr, uid, [lead], lead.team_id.id or False, [('probability', '=', 100.0), ('on_change', '=', True)], context=context) if stage_id: if stages_leads.get(stage_id): stages_leads[stage_id].append(lead.id) @@ -603,7 +603,7 @@ class crm_lead(format_address, osv.osv): """ Search for opportunities that have the same partner and that arent done or cancelled """ - final_stage_domain = [('stage_id.probability', '<', 100), '|', ('stage_id.probability', '>', 0), ('stage_id.sequence', '<=', 1)] + final_stage_domain = ['|', '|', ('stage_id.on_change', '=', False), ('stage_id.probability', 'not in', [0, 100]), ('stage_id.sequence', '<=', 1)] partner_match_domain = [] for email in set(email_split(email) + [email]): partner_match_domain.append(('email_from', '=ilike', email)) @@ -645,7 +645,7 @@ class crm_lead(format_address, osv.osv): # An Opportunity always has higher confidence level than a lead, unless its stage probability is 0.0 for opportunity in opportunities: sequence = -1 - if opportunity.stage_id and not opportunity.stage_id.fold: + if opportunity.stage_id and opportunity.stage_id.on_change: sequence = opportunity.stage_id.sequence sequenced_opps.append(((int(sequence != -1 and opportunity.type == 'opportunity'), sequence, -opportunity.id), opportunity)) @@ -714,7 +714,7 @@ class crm_lead(format_address, osv.osv): customer = partner.browse(cr, uid, partner_id, context=context) for lead in self.browse(cr, uid, ids, context=context): # TDE: was if lead.state in ('done', 'cancel'): - if lead.probability == 100 or (lead.probability == 0 and lead.stage_id.fold): + if (lead.probability == 100 or lead.probability == 0) and lead.stage_id.on_change and lead.stage_id.sequence > 1: continue vals = self._convert_opportunity_data(cr, uid, lead, customer, team_id, context=context) self.write(cr, uid, [lead.id], vals, context=context) @@ -971,9 +971,9 @@ class crm_lead(format_address, osv.osv): def _track_subtype(self, cr, uid, ids, init_values, context=None): record = self.browse(cr, uid, ids[0], context=context) - if 'stage_id' in init_values and record.probability == 100 and record.stage_id and record.stage_id.fold: + if 'stage_id' in init_values and record.probability == 100 and record.stage_id and record.stage_id.on_change: return 'crm.mt_lead_won' - elif 'stage_id' in init_values and record.probability == 0 and record.stage_id and record.stage_id.fold and record.stage_id.sequence > 1: + elif 'stage_id' in init_values and record.probability == 0 and record.stage_id and record.stage_id.on_change and record.stage_id.sequence > 1: return 'crm.mt_lead_lost' elif 'stage_id' in init_values and record.probability == 0 and record.stage_id and record.stage_id.sequence <= 1: return 'crm.mt_lead_create' diff --git a/addons/crm/crm_lead_data.xml b/addons/crm/crm_lead_data.xml index e9ab6358f86..fbee866b238 100644 --- a/addons/crm/crm_lead_data.xml +++ b/addons/crm/crm_lead_data.xml @@ -32,6 +32,7 @@ Proposition 1 40 + 1 50 opportunity @@ -39,6 +40,7 @@ Negotiation 1 60 + 1 60 opportunity diff --git a/addons/crm/crm_view.xml b/addons/crm/crm_view.xml index ce4c22e773b..5445259af36 100644 --- a/addons/crm/crm_view.xml +++ b/addons/crm/crm_view.xml @@ -79,19 +79,19 @@ -