diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/crm/tests/test_crm_lead_lost.py | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/crm/tests/test_crm_lead_lost.py')
| -rw-r--r-- | addons/crm/tests/test_crm_lead_lost.py | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/addons/crm/tests/test_crm_lead_lost.py b/addons/crm/tests/test_crm_lead_lost.py new file mode 100644 index 00000000..7f2819f7 --- /dev/null +++ b/addons/crm/tests/test_crm_lead_lost.py @@ -0,0 +1,65 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo.addons.crm.tests import common as crm_common +from odoo.exceptions import AccessError +from odoo.tests.common import tagged, users + + +@tagged('lead_manage') +class TestLeadConvert(crm_common.TestCrmCommon): + + @classmethod + def setUpClass(cls): + super(TestLeadConvert, cls).setUpClass() + cls.lost_reason = cls.env['crm.lost.reason'].create({ + 'name': 'Test Reason' + }) + + @users('user_sales_salesman') + def test_lead_lost(self): + self.lead_1.with_user(self.user_sales_manager).write({ + 'user_id': self.user_sales_salesman.id, + 'probability': 32, + }) + + lead = self.lead_1.with_user(self.env.user) + self.assertEqual(lead.probability, 32) + + lost_wizard = self.env['crm.lead.lost'].with_context({ + 'active_ids': lead.ids, + }).create({ + 'lost_reason_id': self.lost_reason.id + }) + + lost_wizard.action_lost_reason_apply() + + self.assertEqual(lead.probability, 0) + self.assertEqual(lead.automated_probability, 0) + self.assertFalse(lead.active) + self.assertEqual(lead.lost_reason, self.lost_reason) # TDE FIXME: should be called lost_reason_id non didjou + + @users('user_sales_salesman') + def test_lead_lost_crm_rights(self): + lead = self.lead_1.with_user(self.env.user) + + # nice try little salesman but only managers can create lost reason to avoid bloating the DB + with self.assertRaises(AccessError): + lost_reason = self.env['crm.lost.reason'].create({ + 'name': 'Test Reason' + }) + + with self.with_user('user_sales_manager'): + lost_reason = self.env['crm.lost.reason'].create({ + '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): + lost_wizard.action_lost_reason_apply() |
