diff --git a/addons/crm/models/crm_lead.py b/addons/crm/models/crm_lead.py index 8bb07da6af2..14a072f7377 100644 --- a/addons/crm/models/crm_lead.py +++ b/addons/crm/models/crm_lead.py @@ -999,6 +999,7 @@ class Lead(models.Model): def action_set_lost_with_reason(self): action = self.env['ir.actions.act_window']._for_xml_id('crm.crm_lead_lost_action') action.update({'context': {**self.env.context, **literal_eval(action.get('context', '{}'))}}) + action.setdefault('default_lead_ids', self.ids) return action def action_set_won(self): diff --git a/addons/crm/tests/test_crm_lead_lost.py b/addons/crm/tests/test_crm_lead_lost.py index 33d5f38ea41..4c39abe6f82 100644 --- a/addons/crm/tests/test_crm_lead_lost.py +++ b/addons/crm/tests/test_crm_lead_lost.py @@ -41,9 +41,8 @@ class TestLeadConvert(crm_common.TestCrmCommon): self.assertEqual(update_message.subtype_id, self.env.ref('mail.mt_note')) # mark as lost using the wizard - lost_wizard = self.env['crm.lead.lost'].with_context({ - 'active_ids': lead.ids, - }).create({ + lost_wizard = self.env['crm.lead.lost'].create({ + 'lead_ids': lead.ids, 'lost_reason_id': self.lost_reason.id, 'lost_feedback': '
', # void content }) @@ -76,9 +75,8 @@ class TestLeadConvert(crm_common.TestCrmCommon): self.assertEqual(len(leads), 10) self.flush_tracking() - lost_wizard = self.env['crm.lead.lost'].with_context({ - 'active_ids': leads.ids, - }).create({ + lost_wizard = self.env['crm.lead.lost'].create({ + 'lead_ids': leads.ids, 'lost_reason_id': self.lost_reason.id, 'lost_feedback': 'I cannot find it. It was in my closet and pouf, disappeared.
', }) @@ -121,12 +119,12 @@ class TestLeadConvert(crm_common.TestCrmCommon): 'name': 'Test Reason' }) - lost_wizard = self.env['crm.lead.lost'].with_context({ - 'active_ids': lead.ids - }).create({ - 'lost_reason_id': lost_reason.id - }) - # nice try little salesman, you cannot invoke a wizard to update other people leads with self.assertRaises(AccessError): + # wizard needs to be here due to cache clearing in assertRaises + # (ORM does not load m2m records unavailable to the user from database) + lost_wizard = self.env['crm.lead.lost'].create({ + 'lead_ids': lead.ids, + 'lost_reason_id': lost_reason.id + }) lost_wizard.action_lost_reason_apply() diff --git a/addons/crm/views/crm_lead_views.xml b/addons/crm/views/crm_lead_views.xml index dea34eccdb9..3f15ae04dae 100644 --- a/addons/crm/views/crm_lead_views.xml +++ b/addons/crm/views/crm_lead_views.xml @@ -9,8 +9,8 @@ - +