[IMP] crm: change heuristic for lost / won stages from

being fold-based to on_change based. Interesting stages have the on_change
field set to true to update the lead / opportunity. Having it folded or not
is more a matter of display than logic.
This commit is contained in:
Jaysinh Shukla
2015-02-25 10:20:44 +01:00
committed by Thibault Delavallée
parent d4e9640e34
commit e5875acc6a
4 changed files with 17 additions and 16 deletions
+1 -2
View File
@@ -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,
+9 -9
View File
@@ -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'
+2
View File
@@ -32,6 +32,7 @@
<field name="name">Proposition</field>
<field name="case_default">1</field>
<field name="probability">40</field>
<field name="on_change">1</field>
<field name="sequence">50</field>
<field name="type">opportunity</field>
</record>
@@ -39,6 +40,7 @@
<field name="name">Negotiation</field>
<field name="case_default">1</field>
<field name="probability">60</field>
<field name="on_change">1</field>
<field name="sequence">60</field>
<field name="type">opportunity</field>
</record>
+5 -5
View File
@@ -79,19 +79,19 @@
<field name="name"/>
<field name="sequence"/>
<field name="type"/>
<label for="probability" />
<div>
<field name="on_change"/>
<label for="probability" attrs="{'invisible': [('on_change', '=', False)]}"/>
<div attrs="{'invisible': [('on_change', '=', False)]}">
<field name="probability"/>
<p class="text-muted">
A stage will be considered as 'Won' if the probability is 100% and it is folded in Kanban View.<br/>
A stage will be considered as 'Lost (Dead)' if the probability is 0% and it is folded in Kanban View.
A stage will be considered as 'Won' if the probability is 100% and if 'Change Probability Automatically' is true. The sequence should be greater than 1.<br/>
A stage will be considered as 'Lost' or 'Dead' if the probability is 0% and if 'Change Probability Automatically' is true. The sequence should be greater than 1.
</p>
</div>
<field name="case_default" groups="base.group_multi_salesteams"/>
</group>
<group>
<field name="fold"/>
<field name="on_change"/>
<field name="legend_priority"/>
</group>
</group>