diff --git a/addons/crm/crm_lead.py b/addons/crm/crm_lead.py index 5f52980c8b0..9eaddc9fc0e 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 """