From 7c1cb42e1769ea32fa79468a2d7dfe0ac28fd8a9 Mon Sep 17 00:00:00 2001 From: Denis Ledoux Date: Thu, 14 Nov 2013 14:13:13 +0100 Subject: [PATCH] [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 --- addons/crm/crm_lead.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 5f52980..9eaddc9 100644 --- a/addons/crm/crm_lead.py +++ b/addons/crm/crm_lead.py @@ -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 """ -- 1.7.10.4