[FIX]crm: case_mark_lost and case_mark_won only were only setting the stage of the first lead passed, instead of the whole list.

bzr revid: dle@openerp.com-20131114131313-bml9m0ejsp82thjn
This commit is contained in:
Denis Ledoux 2013-11-14 14:13:13 +01:00
parent b61997e716
commit 7c1cb42e17
1 changed files with 18 additions and 4 deletions

View File

@ -391,29 +391,43 @@ class crm_lead(format_address, osv.osv):
""" Mark the case as lost: state=cancel and probability=0
:deprecated: this method will be removed in OpenERP v8.
"""
for lead in self.browse(cr, uid, ids):
stages_leads = {}
for lead in self.browse(cr, uid, ids, context=context):
stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 0.0), ('fold', '=', True), ('sequence', '>', 1)], context=context)
if stage_id:
return self.write(cr, uid, [lead.id], {'stage_id': stage_id}, context=context)
if stages_leads.get(stage_id):
stages_leads[stage_id].append(lead.id)
else:
stages_leads[stage_id] = [lead.id]
else:
raise osv.except_osv(_('Warning!'),
_('To relieve your sales pipe and group all Lost opportunities, configure one of your sales stage as follow:\n'
'probability = 0 %, select "Change Probability Automatically".\n'
'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.'))
for stage_id, lead_ids in stages_leads.items():
self.write(cr, uid, lead_ids, {'stage_id': stage_id}, context=context)
return True
def case_mark_won(self, cr, uid, ids, context=None):
""" Mark the case as won: state=done and probability=100
:deprecated: this method will be removed in OpenERP v8.
"""
for lead in self.browse(cr, uid, ids):
stages_leads = {}
for lead in self.browse(cr, uid, ids, context=context):
stage_id = self.stage_find(cr, uid, [lead], lead.section_id.id or False, [('probability', '=', 100.0), ('fold', '=', True)], context=context)
if stage_id:
return self.write(cr, uid, [lead.id], {'stage_id': stage_id}, context=context)
if stages_leads.get(stage_id):
stages_leads[stage_id].append(lead.id)
else:
stages_leads[stage_id] = [lead.id]
else:
raise osv.except_osv(_('Warning!'),
_('To relieve your sales pipe and group all Won opportunities, configure one of your sales stage as follow:\n'
'probability = 100 % and select "Change Probability Automatically".\n'
'Create a specific stage or edit an existing one by editing columns of your opportunity pipe.'))
for stage_id, lead_ids in stages_leads.items():
self.write(cr, uid, lead_ids, {'stage_id': stage_id}, context=context)
return True
def case_escalate(self, cr, uid, ids, context=None):
""" Escalates case to parent level """