Files
odoo_source/addons/crm/tests/test_new_lead_notification.py
T
Thibault Delavallée b6d2351df4 [REF] mail: improve implementation of message subscribe
This commit refactors mail.thread message_subscribe method. It is done for two
purposes. First one is to optimize performance by using the new followers
computation methods introduced recently. Second purpose is to clean the API
of message_subscribe to make it simpler to use.

This commit splits message_subscribe in two main parts :

 * _message_subscribe is a private method calling the follower new
   subscription methods and updating the record set;
 * message_subscribe is a public wrapper on _message_subscribe that adds
   access rights checks;

Simplification comes by removing message_subscribe_users that was a
shortcut to message_subscribe. Having a method to subscribe partners and
channels is sufficient as we would like to avoid bloating the public API
of mail.thread. A force parameter is also removed from message_subscribe
as this implementation detail can be induced in the computation.

Various addons using the removed methods are updated in order to use the new
subscription API. They have the same functional behavior.

This commit has a great impact when subscribing several followers. In a more
general way all code using message_post is also optimized as posting a message
generally implies subscribing followers. It also improves activity use as
posting a message and subscribing new followers are common process in
activities.
2018-04-03 17:11:43 +02:00

44 lines
1.9 KiB
Python

# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from .common import TestCrmCases
class NewLeadNotification(TestCrmCases):
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
channel_listen = self.env['mail.channel'].create({'name': 'Listener'})
sales_team_1 = self.env['crm.team'].create({
'name': 'Test Sales Channel',
'alias_name': 'test_sales_team',
})
subtype = self.env.ref("crm.mt_salesteam_lead")
sales_team_1.message_subscribe(partner_ids=[self.crm_salesman.partner_id.id], channel_ids=[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": sales_team_1.id,
"phone": "+0000000000"
})
# partner and channel should be auto subscribed
self.assertIn(self.crm_salesman.partner_id, lead.message_partner_ids)
self.assertIn(channel_listen, lead.message_channel_ids)
msg = lead.message_ids[0]
self.assertIn(self.crm_salesman.partner_id, msg.needaction_partner_ids)
self.assertIn(channel_listen, msg.channel_ids)
# The user should have a new unread message
lead_user = lead.sudo(self.crm_salesman)
self.assertTrue(lead_user.message_needaction)