RATIONALE
Channel model is a mail.thread enabled model behaving strangely with followers,
notifications and discuss. Its code should however be simplified to be more
self contained and avoid unwanted side effects on other models.
SPECIFICATIONS
Purpose of this commit is to better differentiate channel members technical
model from partner members in code :
* ``channel_partner_ids``: contacts member of a channel, filtering notably
on active and checking ACLs on res.partner business model. This one
should be used whenever we deal with members of a channel at business
level;
* ``channel_last_seen_partner_ids``: memberships of a channel and technical
model. This one should be used for internal processes and members
management;
Also containing
* clean naming or API of methods managing channel members. This should
not change anything functionally as only code renaming / cleaning is
performed;
* improve performances of channel member auto subscription by aggregating
all members to add and creating them at once;
* check the use of ``mail.channel.partner`` and ``res.partner`` records
through ``channel_last_seen_partner_ids`` and ``channel_partner_ids``
Channel fields;
Functionally nothing should change with this commit. It only cleans code
in order to prepare future modifications.
LINKS
Task ID-2070632 (main task)
Task ID-2419762 (followup task)
COM PR odoo/odoo#62859
ENT PR odoo/enterprise#15172
UPG PR odoo/upgrade#2005
78 lines
3.1 KiB
Python
78 lines
3.1 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.crm.tests.common import TestCrmCommon
|
|
from odoo.addons.mail.tests.common import mail_new_test_user
|
|
from odoo.tests.common import users
|
|
|
|
|
|
class TestLivechatLead(TestCrmCommon):
|
|
|
|
@classmethod
|
|
def setUpClass(cls):
|
|
super(TestLivechatLead, cls).setUpClass()
|
|
|
|
cls.user_anonymous = mail_new_test_user(
|
|
cls.env, login='user_anonymous',
|
|
name='Anonymous Website', email=False,
|
|
company_id=cls.company_main.id,
|
|
notification_type='inbox',
|
|
groups='base.group_public',
|
|
)
|
|
cls.user_portal = mail_new_test_user(
|
|
cls.env, login='user_portal',
|
|
name='Paulette Portal', email='user_portal@test.example.com',
|
|
company_id=cls.company_main.id,
|
|
notification_type='inbox',
|
|
groups='base.group_portal',
|
|
)
|
|
|
|
@users('user_sales_leads')
|
|
def test_crm_lead_creation_guest(self):
|
|
""" Test customer set on lead: not if public, guest if not public """
|
|
# public: should not be set as customer
|
|
channel = self.env['mail.channel'].create({
|
|
'name': 'Chat with Visitor',
|
|
'channel_partner_ids': [(4, self.user_anonymous.partner_id.id)]
|
|
})
|
|
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
|
|
|
self.assertEqual(
|
|
channel.channel_partner_ids,
|
|
self.user_sales_leads.partner_id | self.user_anonymous.partner_id
|
|
)
|
|
self.assertEqual(lead.name, 'TestLead command')
|
|
self.assertEqual(lead.partner_id, self.env['res.partner'])
|
|
|
|
# public + someone else: no customer (as he was anonymous)
|
|
channel.write({
|
|
'channel_partner_ids': [(4, self.user_sales_manager.partner_id.id)]
|
|
})
|
|
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
|
self.assertEqual(lead.partner_id, self.env['res.partner'])
|
|
|
|
# portal: should be set as customer
|
|
channel = self.env['mail.channel'].create({
|
|
'name': 'Chat with Visitor',
|
|
'channel_partner_ids': [(4, self.user_portal.partner_id.id)]
|
|
})
|
|
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
|
|
|
self.assertEqual(
|
|
channel.channel_partner_ids,
|
|
self.user_sales_leads.partner_id | self.user_portal.partner_id
|
|
)
|
|
self.assertEqual(lead.partner_id, self.user_portal.partner_id)
|
|
|
|
# another operator invited: internal user should not be customer if portal is present
|
|
channel.write({
|
|
'channel_partner_ids': [(4, self.user_sales_manager.partner_id.id)]
|
|
})
|
|
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
|
|
|
self.assertEqual(
|
|
channel.channel_partner_ids,
|
|
self.user_sales_leads.partner_id | self.user_portal.partner_id | self.user_sales_manager.partner_id
|
|
)
|
|
self.assertEqual(lead.partner_id, self.user_portal.partner_id)
|