[FIX]crm: case_mark_lost and case_mark_won only were only setting the stage of the...
authorDenis Ledoux <dle@openerp.com>
Thu, 14 Nov 2013 13:13:13 +0000 (14:13 +0100)
committerDenis Ledoux <dle@openerp.com>
Thu, 14 Nov 2013 13:13:13 +0000 (14:13 +0100)
bzr revid: dle@openerp.com-20131114131313-bml9m0ejsp82thjn

addons/crm/crm_lead.py

index 5f52980..9eaddc9 100644 (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 """