summaryrefslogtreecommitdiff
path: root/addons/crm/tests/test_crm_lead_lost.py
blob: 7f2819f78253cb462dba8c7aaf1c6b84487010d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()