summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThibault Delavallée <tde@odoo.com>2020-01-23 14:34:25 +0000
committerThibault Delavallée <tde@odoo.com>2020-01-23 14:43:32 +0000
commit69625cac78ebc5d953c2ad92d52cf2b0c3e80f84 (patch)
tree33134df0bcd2e98d7608cef76fcd9332f53cfed1
parentcb30f536368c65f36533e30b4cdc0bc461fcbf3c (diff)
[IMP] crm: add tests for lost wizard
PURPOSE As crm will soon evolve (onchange -> compute, code improvements, better management of sales teams) cleaning and improving tests is necessary to avoid regressions. SPECIFICATIONS This wizard has no tests at all. Even if it not really complex it is better to have some tests ensuring at least marking a lead as lost with a reason correctly updates it. LINKS Task ID 2180521 (add tests for crm wizards) Task ID 2056759 (remove crm.partner.binding mixin) Task ID 2088565 (crm onchange -> compute) Community PR odoo/odoo#43473
-rw-r--r--addons/crm/tests/__init__.py1
-rw-r--r--addons/crm/tests/test_crm_lead_lost.py63
2 files changed, 64 insertions, 0 deletions
diff --git a/addons/crm/tests/__init__.py b/addons/crm/tests/__init__.py
index 22d6d774639..e8c18d42468 100644
--- a/addons/crm/tests/__init__.py
+++ b/addons/crm/tests/__init__.py
@@ -3,6 +3,7 @@
from . import test_crm_lead
from . import test_crm_lead_notification
from . import test_crm_lead_convert
+from . import test_crm_lead_lost
from . import test_crm_lead_merge
from . import test_crm_activity
from . import test_crm_ui
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 00000000000..1cc0defab98
--- /dev/null
+++ b/addons/crm/tests/test_crm_lead_lost.py
@@ -0,0 +1,63 @@
+# -*- 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_wizard.write({'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_wizard.write({'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()