File: test_new_lead_notification.py

package info (click to toggle)
oca-core 11.0.20180730-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 509,684 kB
  • sloc: xml: 258,806; python: 164,081; sql: 217; sh: 92; makefile: 16
file content (38 lines) | stat: -rw-r--r-- 1,788 bytes parent folder | download
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
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.

from .common import TestCrm


class NewLeadNotification(TestCrm):

    def test_new_lead_notification(self):
        """ Test newly create leads like from the website. People and channels
        subscribed to the sales channel shoud be notified. """
        # subscribe a partner and a channel to the sales channel with new lead subtype
        subtype = self.env.ref("crm.mt_salesteam_lead")
        self.sales_team_1.message_subscribe(partner_ids=[self.user_salesman_all.partner_id.id], subtype_ids=[subtype.id])
        self.sales_team_1.message_subscribe(channel_ids=[self.channel_listen.id], subtype_ids=[subtype.id])

        # Imitate what happens in the controller when somebody creates a new
        # lead from the website form
        lead = self.env["crm.lead"].with_context(mail_create_nosubscribe=True).sudo().create({
            "contact_name": "Somebody",
            "description": "Some question",
            "email_from": "somemail@example.com",
            "name": "Some subject",
            "partner_name": "Some company",
            "team_id": self.sales_team_1.id,
            "phone": "+0000000000"
        })
        # partner and channel should be auto subscribed
        self.assertIn(self.user_salesman_all.partner_id, lead.message_partner_ids)
        self.assertIn(self.channel_listen, lead.message_channel_ids)

        msg = lead.message_ids[0]
        self.assertIn(self.user_salesman_all.partner_id, msg.needaction_partner_ids)
        self.assertIn(self.channel_listen, msg.channel_ids)

        # The user should have a new unread message
        lead_user = lead.sudo(self.user_salesman_all)
        self.assertTrue(lead_user.message_needaction)