From 198a0b8ff615531931c3515de12ca2d0761a3d03 Mon Sep 17 00:00:00 2001 From: keyur gajjar Date: Tue, 12 Jul 2016 17:08:08 +0530 Subject: [PATCH] [IMP] crm: Set lost reason when marking several leads as lost ======= PURPOSE ======= In list view, when handling in mass the opportunities and mark it as lost, it should be possible to set the lost reason. The reason would be the same for all the selected opportunities. ============= SPECIFICATION ============= On clicking of 'Mark as Lost', ask user the lost reason through wizard. and then set that lost reason to all the opportunities selected. --- addons/crm/views/crm_lead_views.xml | 6 ++++-- addons/crm/wizard/crm_lead_lost.py | 6 +++--- addons/crm/wizard/crm_lead_lost_views.xml | 1 - 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml index 29e2a3dcefb..efbf61de851 100644 --- a/addons/crm/views/crm_lead_views.xml +++ b/addons/crm/views/crm_lead_views.xml @@ -670,8 +670,10 @@ code - if env.context.get('active_model') == 'crm.lead' and env.context.get('active_ids'): - env['crm.lead'].browse(context['active_ids']).action_set_lost() + if context.get('active_model') == 'crm.lead' and context.get('active_ids'): + action_values = env.ref('crm.crm_lead_lost_action').read()[0] + action_values.update({'context': context}) + action = action_values diff --git a/addons/crm/wizard/crm_lead_lost.py b/addons/crm/wizard/crm_lead_lost.py index df80cac0303..4bcdf46992a 100644 --- a/addons/crm/wizard/crm_lead_lost.py +++ b/addons/crm/wizard/crm_lead_lost.py @@ -7,10 +7,10 @@ class CrmLeadLost(models.TransientModel): _name = 'crm.lead.lost' _description = 'Get Lost Reason' - lead_id = fields.Many2one('crm.lead', 'Lead', required=True) lost_reason_id = fields.Many2one('crm.lost.reason', 'Lost Reason') @api.multi def action_lost_reason_apply(self): - self.lead_id.lost_reason = self.lost_reason_id - return self.lead_id.action_set_lost() + leads = self.env['crm.lead'].browse(self.env.context.get('active_ids')) + leads.write({'lost_reason': self.lost_reason_id.id}) + return leads.action_set_lost() diff --git a/addons/crm/wizard/crm_lead_lost_views.xml b/addons/crm/wizard/crm_lead_lost_views.xml index 512baa711a0..844e5e91d5f 100644 --- a/addons/crm/wizard/crm_lead_lost_views.xml +++ b/addons/crm/wizard/crm_lead_lost_views.xml @@ -6,7 +6,6 @@
-