mirror of
https://github.com/bringout/oca-ocb-crm.git
synced 2026-04-23 20:52:02 +02:00
19.0 vanilla
This commit is contained in:
parent
dc68f80d3f
commit
7221b9ac46
610 changed files with 135477 additions and 161677 deletions
|
|
@ -4,3 +4,4 @@
|
|||
from . import chatbot_common
|
||||
from . import test_chatbot_lead
|
||||
from . import test_crm_lead
|
||||
from . import test_discuss_channel_access
|
||||
|
|
|
|||
|
|
@ -1,45 +1,32 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
from odoo.addons.im_livechat.tests.chatbot_common import ChatbotCase
|
||||
from odoo.addons.mail.tests.common import mail_new_test_user
|
||||
from odoo.addons.mail.tests.common import MailCommon
|
||||
|
||||
|
||||
class CrmChatbotCase(ChatbotCase):
|
||||
class CrmChatbotCase(MailCommon, ChatbotCase):
|
||||
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super(CrmChatbotCase, cls).setUpClass()
|
||||
|
||||
cls.company_id = cls.env['res.company'].create({
|
||||
'name': 'Test Company',
|
||||
'country_id': cls.env.ref('base.be').id,
|
||||
})
|
||||
|
||||
cls.user_public = mail_new_test_user(
|
||||
cls.env, login='user_public', groups='base.group_public', name='Public User')
|
||||
cls.user_portal = mail_new_test_user(
|
||||
cls.env, login='user_portal', groups='base.group_portal', name='Portal User',
|
||||
company_id=cls.company_id.id, email='portal@example.com')
|
||||
# update company_id on partner since the user's company is not propagated
|
||||
cls.user_portal.partner_id.write({'company_id': cls.company_id.id})
|
||||
|
||||
cls.sale_team = cls.env['crm.team'].create({
|
||||
'name': 'Test Sale Team 1',
|
||||
'company_id': cls.company_id.id,
|
||||
})
|
||||
|
||||
cls.sale_team_with_lead = cls.env['crm.team'].create({
|
||||
'name': 'Test Sale Team 2',
|
||||
'use_leads': True,
|
||||
'company_id': cls.company_id.id,
|
||||
})
|
||||
|
||||
super().setUpClass()
|
||||
cls._create_portal_user()
|
||||
teams_data = [
|
||||
{
|
||||
"company_id": cls.company_admin.id,
|
||||
"crm_team_member_ids": [Command.create({"user_id": cls.user_employee.id})],
|
||||
"name": "Test Sale Team 1",
|
||||
},
|
||||
{
|
||||
"company_id": cls.company_admin.id,
|
||||
"name": "Test Sale Team 2",
|
||||
"use_leads": True,
|
||||
},
|
||||
]
|
||||
cls.sale_team, cls.sale_team_with_lead = cls.env["crm.team"].create(teams_data)
|
||||
cls.step_dispatch_create_lead = cls.env['chatbot.script.answer'].sudo().create({
|
||||
'name': 'Create a lead',
|
||||
'script_step_id': cls.step_dispatch.id,
|
||||
})
|
||||
|
||||
[
|
||||
cls.step_create_lead_email,
|
||||
cls.step_create_lead_phone,
|
||||
|
|
|
|||
|
|
@ -1,15 +1,15 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
from odoo.addons.crm_livechat.tests import chatbot_common
|
||||
from odoo.tests.common import users
|
||||
from odoo.tests.common import tagged
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class CrmChatbotCase(chatbot_common.CrmChatbotCase):
|
||||
|
||||
@users('user_public')
|
||||
def test_chatbot_lead_public_user(self):
|
||||
self._chatbot_create_lead(self.user_public)
|
||||
def test_chatbot_create_lead_public_user(self):
|
||||
self._play_session_with_lead()
|
||||
|
||||
created_lead = self.env['crm.lead'].sudo().search([], limit=1, order='id desc')
|
||||
self.assertEqual(created_lead.name, "Testing Bot's New Lead")
|
||||
|
|
@ -19,10 +19,73 @@ class CrmChatbotCase(chatbot_common.CrmChatbotCase):
|
|||
self.assertEqual(created_lead.team_id, self.sale_team)
|
||||
self.assertEqual(created_lead.type, 'opportunity')
|
||||
|
||||
@users('user_portal')
|
||||
def test_chatbot_lead_portal_user(self):
|
||||
def test_chatbot_create_lead_and_forward_public_user(self):
|
||||
"""Test create_lead_and_forward properly creates a lead, assigns it to an available sales
|
||||
team member, and forwards the discussion to that member."""
|
||||
self.step_create_lead.sudo().step_type = "create_lead_and_forward"
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
not_available_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertEqual(not_available_lead.name, "Testing Bot's New Lead")
|
||||
self.assertEqual(not_available_lead.email_from, "test2@example.com")
|
||||
self.assertEqual(not_available_lead.phone, "123456")
|
||||
self.assertEqual(not_available_lead.team_id, self.sale_team)
|
||||
self.assertEqual(not_available_lead.type, "opportunity")
|
||||
chatbot_partner = self.chatbot_script.operator_partner_id
|
||||
# sales team member is not available
|
||||
self.assertFalse(not_available_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
# sales team member is available
|
||||
self.env["mail.presence"]._update_presence(self.user_employee)
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
assigned_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertEqual(assigned_lead.user_id, self.user_employee)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, self.partner_employee)
|
||||
# sales team member quota is reached (lead already assigned before)
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
quota_reached_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertFalse(quota_reached_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
assigned_lead.unlink()
|
||||
# sales team member opt out
|
||||
self.sale_team.crm_team_member_ids.assignment_optout = True
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
optout_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertFalse(optout_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
self.sale_team.crm_team_member_ids.assignment_optout = False
|
||||
# sales team member invalid domain (probability of lead is 5.39)
|
||||
self.sale_team.crm_team_member_ids.assignment_domain = "[('probability', '>=', 20)]"
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
non_matching_domain_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertFalse(non_matching_domain_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
self.sale_team.crm_team_member_ids.assignment_domain = False
|
||||
# auto-assign team
|
||||
self.step_create_lead.crm_team_id = False
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
auto_team_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertEqual(auto_team_lead.user_id, self.user_employee)
|
||||
self.assertEqual(auto_team_lead.team_id, self.sale_team)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, self.partner_employee)
|
||||
auto_team_lead.unlink()
|
||||
# sales team opt out
|
||||
self.sale_team.assignment_optout = True
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
team_optout_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertFalse(team_optout_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
self.sale_team.assignment_optout = False
|
||||
# sales team invalid domain (probability of lead is 5.39)
|
||||
self.sale_team.assignment_domain = "[('probability', '>=', 20)]"
|
||||
discuss_channel = self._play_session_with_lead()
|
||||
team_non_matching_domain_lead = self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
self.assertFalse(team_non_matching_domain_lead.user_id)
|
||||
self.assertEqual(discuss_channel.livechat_operator_id, chatbot_partner)
|
||||
|
||||
def test_chatbot_create_lead_portal_user(self):
|
||||
self.authenticate(self.user_portal.login, self.user_portal.login)
|
||||
self.step_create_lead.write({'crm_team_id': self.sale_team_with_lead})
|
||||
self._chatbot_create_lead(self.user_portal)
|
||||
self._play_session_with_lead()
|
||||
|
||||
created_lead = self.env['crm.lead'].sudo().search([], limit=1, order='id desc')
|
||||
self.assertEqual(created_lead.name, "Testing Bot's New Lead")
|
||||
|
|
@ -32,20 +95,135 @@ class CrmChatbotCase(chatbot_common.CrmChatbotCase):
|
|||
self.assertEqual(created_lead.team_id, self.sale_team_with_lead)
|
||||
self.assertEqual(created_lead.type, 'lead')
|
||||
|
||||
def _chatbot_create_lead(self, user):
|
||||
channel_info = self.livechat_channel._open_livechat_mail_channel(
|
||||
anonymous_name='Test Visitor', chatbot_script=self.chatbot_script, user_id=user.id)
|
||||
mail_channel = self.env['mail.channel'].sudo().browse(channel_info['id'])
|
||||
def test_chatbot_create_lead_company(self):
|
||||
self.user_portal.write({"company_ids": self.company_2, "company_id": self.company_2})
|
||||
team = self.sale_team_with_lead
|
||||
partner = self.user_portal.partner_id
|
||||
self.step_create_lead.crm_team_id = team
|
||||
self.authenticate(self.user_portal.login, self.user_portal.login)
|
||||
|
||||
self._post_answer_and_trigger_next_step(
|
||||
mail_channel,
|
||||
self.step_dispatch_create_lead.name,
|
||||
chatbot_script_answer=self.step_dispatch_create_lead
|
||||
def play_script_and_get_created_lead():
|
||||
self.env["crm.lead"].search([]).unlink()
|
||||
self._play_session_with_lead()
|
||||
return self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
|
||||
# lead has company of partner and no team if no company matching
|
||||
partner.company_id = self.company_2
|
||||
team.company_id = self.company_3
|
||||
lead = play_script_and_get_created_lead()
|
||||
self.assertEqual(lead.company_id, self.company_2)
|
||||
self.assertFalse(lead.team_id)
|
||||
# lead has common company of partner and team if both are matching
|
||||
partner.company_id = self.company_2
|
||||
team.company_id = self.company_2
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has team company if partner has no company
|
||||
partner.company_id = False
|
||||
team.company_id = self.company_2
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has partner company if team has no company
|
||||
partner.company_id = self.company_2
|
||||
team.company_id = False
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has no company if no company on partner and team
|
||||
partner.company_id = False
|
||||
team.company_id = False
|
||||
self.assertFalse(play_script_and_get_created_lead().company_id)
|
||||
|
||||
def test_chatbot_create_lead_and_forward_company(self):
|
||||
self.step_create_lead.sudo().step_type = "create_lead_and_forward"
|
||||
self.user_portal.write({"company_ids": self.company_2.ids, "company_id": self.company_2.id})
|
||||
self.user_employee.write({"company_ids": self.company_3.ids, "company_id": self.company_3.id})
|
||||
self.user_employee.partner_id.company_id = self.company_3
|
||||
teams = self.sale_team_with_lead + self.sale_team
|
||||
partner = self.user_portal.partner_id
|
||||
self.authenticate(self.user_portal.login, self.user_portal.login)
|
||||
|
||||
def play_script_and_get_created_lead():
|
||||
self.env["crm.lead"].search([]).unlink()
|
||||
self._play_session_with_lead()
|
||||
return self.env["crm.lead"].sudo().search([], limit=1, order="id desc")
|
||||
|
||||
# lead has company of partner and no team if no company matching
|
||||
partner.company_id = self.company_2
|
||||
teams.company_id = self.company_3
|
||||
lead = play_script_and_get_created_lead()
|
||||
self.assertEqual(lead.company_id, self.company_2)
|
||||
self.assertFalse(lead.team_id)
|
||||
# lead has common company of partner and team if both are matching
|
||||
self.user_employee.write({"company_ids": self.company_2.ids, "company_id": self.company_2.id})
|
||||
self.user_employee.partner_id.company_id = self.company_2
|
||||
partner.company_id = self.company_2
|
||||
teams.company_id = self.company_2
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has team company if partner has no company
|
||||
partner.company_id = False
|
||||
teams.company_id = self.company_2
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has partner company if team has no company
|
||||
partner.company_id = self.company_2
|
||||
teams.company_id = False
|
||||
self.assertEqual(play_script_and_get_created_lead().company_id, self.company_2)
|
||||
# lead has no company if no company on partner and team
|
||||
partner.company_id = False
|
||||
teams.company_id = False
|
||||
self.assertFalse(play_script_and_get_created_lead().company_id)
|
||||
|
||||
def _play_session_with_lead(self):
|
||||
data = self.make_jsonrpc_request("/im_livechat/get_session", {
|
||||
'channel_id': self.livechat_channel.id,
|
||||
'chatbot_script_id': self.chatbot_script.id,
|
||||
})
|
||||
discuss_channel = (
|
||||
self.env["discuss.channel"].sudo().browse(data["channel_id"])
|
||||
)
|
||||
self.assertEqual(mail_channel.chatbot_current_step_id, self.step_create_lead_email)
|
||||
self._post_answer_and_trigger_next_step(mail_channel, 'test2@example.com')
|
||||
self._post_answer_and_trigger_next_step(
|
||||
discuss_channel, chatbot_script_answer=self.step_dispatch_create_lead
|
||||
)
|
||||
self.assertEqual(discuss_channel.chatbot_current_step_id, self.step_create_lead_email)
|
||||
self._post_answer_and_trigger_next_step(discuss_channel, email="test2@example.com")
|
||||
self.assertEqual(discuss_channel.chatbot_current_step_id, self.step_create_lead_phone)
|
||||
self._post_answer_and_trigger_next_step(discuss_channel, '123456')
|
||||
self.assertEqual(discuss_channel.chatbot_current_step_id, self.step_create_lead)
|
||||
return discuss_channel
|
||||
|
||||
self.assertEqual(mail_channel.chatbot_current_step_id, self.step_create_lead_phone)
|
||||
self._post_answer_and_trigger_next_step(mail_channel, '123456')
|
||||
|
||||
self.assertEqual(mail_channel.chatbot_current_step_id, self.step_create_lead)
|
||||
def test_create_lead_from_chatbot(self):
|
||||
chatbot_script = self.env["chatbot.script"].create({"title": "Create lead bot"})
|
||||
self.env["chatbot.script.step"].create(
|
||||
[
|
||||
{
|
||||
"chatbot_script_id": chatbot_script.id,
|
||||
"message": "Hello, how can I help you?",
|
||||
"step_type": "free_input_single",
|
||||
},
|
||||
{
|
||||
"step_type": "question_email",
|
||||
"chatbot_script_id": chatbot_script.id,
|
||||
"message": "Would you mind leaving your email address so that we can reach you back?",
|
||||
},
|
||||
{
|
||||
"step_type": "create_lead",
|
||||
"chatbot_script_id": chatbot_script.id,
|
||||
"message": "Thank you, you should hear back from us very soon!",
|
||||
},
|
||||
]
|
||||
)
|
||||
livechat_channel = self.env["im_livechat.channel"].create(
|
||||
{
|
||||
"name": "Create lead channel",
|
||||
"rule_ids": [
|
||||
Command.create(
|
||||
{
|
||||
"regex_url": "/",
|
||||
"chatbot_script_id": chatbot_script.id,
|
||||
}
|
||||
)
|
||||
],
|
||||
}
|
||||
)
|
||||
self.start_tour(
|
||||
f"/im_livechat/support/{livechat_channel.id}", "crm_livechat.create_lead_from_chatbot"
|
||||
)
|
||||
lead = self.env["crm.lead"].search([("origin_channel_id", "=", livechat_channel.channel_ids.id)])
|
||||
self.assertEqual(lead.name, "I'd like to know more about the CRM application.")
|
||||
self.assertTrue(lead.origin_channel_id.has_crm_lead)
|
||||
|
|
|
|||
|
|
@ -1,24 +1,22 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo import Command
|
||||
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
|
||||
from odoo.tests.common import HttpCase, tagged, users
|
||||
|
||||
|
||||
class TestLivechatLead(TestCrmCommon):
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestLivechatLead(HttpCase, 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='email',
|
||||
groups='base.group_public',
|
||||
)
|
||||
cls.env["mail.presence"]._update_presence(cls.user_sales_leads)
|
||||
cls.livechat_channel = cls.env['im_livechat.channel'].create({
|
||||
'name': 'Test Livechat Channel',
|
||||
'user_ids': [Command.link(cls.user_sales_leads.id)],
|
||||
})
|
||||
cls.user_portal = mail_new_test_user(
|
||||
cls.env, login='user_portal',
|
||||
name='Paulette Portal', email='user_portal@test.example.com',
|
||||
|
|
@ -31,16 +29,16 @@ class TestLivechatLead(TestCrmCommon):
|
|||
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)]
|
||||
data = self.make_jsonrpc_request("/im_livechat/get_session", {
|
||||
'channel_id': self.livechat_channel.id,
|
||||
'persisted': True,
|
||||
})
|
||||
channel = self.env["discuss.channel"].browse(data["channel_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.origin_channel_id, channel)
|
||||
self.assertTrue(any(m.partner_id == self.user_sales_leads.partner_id for m in channel.channel_member_ids))
|
||||
self.assertTrue(any(bool(m.guest_id) for m in channel.channel_member_ids))
|
||||
self.assertEqual(lead.name, 'TestLead command')
|
||||
self.assertEqual(lead.partner_id, self.env['res.partner'])
|
||||
|
||||
|
|
@ -48,31 +46,33 @@ class TestLivechatLead(TestCrmCommon):
|
|||
# 'base.public_user' is archived by default
|
||||
self.assertFalse(self.env.ref('base.public_user').active)
|
||||
|
||||
channel = self.env['mail.channel'].create({
|
||||
'name': 'Chat with Visitor',
|
||||
'channel_partner_ids': [(4, self.env.ref('base.public_partner').id)]
|
||||
data = self.make_jsonrpc_request("/im_livechat/get_session", {
|
||||
'channel_id': self.livechat_channel.id,
|
||||
'persisted': True,
|
||||
})
|
||||
channel = self.env["discuss.channel"].browse(data["channel_id"])
|
||||
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
||||
|
||||
self.assertEqual(
|
||||
channel.channel_member_ids.partner_id,
|
||||
self.user_sales_leads.partner_id | self.env.ref('base.public_partner')
|
||||
)
|
||||
self.assertEqual(lead.name, 'TestLead command')
|
||||
self.assertEqual(lead.partner_id, self.env['res.partner'])
|
||||
self.assertTrue(any(m.partner_id == self.user_sales_leads.partner_id for m in channel.channel_member_ids))
|
||||
self.assertTrue(any(bool(m.guest_id) for m in channel.channel_member_ids))
|
||||
|
||||
# public + someone else: no customer (as they were anonymous)
|
||||
channel.write({
|
||||
# sudo: discuss.channel.member - removing non-self member for test setup purposes
|
||||
channel.sudo().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'])
|
||||
|
||||
@users('user_sales_leads')
|
||||
def test_crm_lead_creation_portal(self):
|
||||
# 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)]
|
||||
self.authenticate("user_portal", "user_portal")
|
||||
data = self.make_jsonrpc_request("/im_livechat/get_session", {
|
||||
'channel_id': self.livechat_channel.id,
|
||||
'persisted': True,
|
||||
})
|
||||
channel = self.env["discuss.channel"].browse(data["channel_id"])
|
||||
lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
|
||||
|
||||
self.assertEqual(
|
||||
|
|
@ -92,3 +92,25 @@ class TestLivechatLead(TestCrmCommon):
|
|||
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)
|
||||
|
||||
def test_create_lead_when_channel_has_deleted_message(self):
|
||||
bob_operator = mail_new_test_user(
|
||||
self.env, login="bob_user", groups="im_livechat.im_livechat_group_user,sales_team.group_sale_salesman"
|
||||
)
|
||||
self.authenticate("bob_user", "bob_user")
|
||||
self.livechat_channel.user_ids = bob_operator
|
||||
self.env["mail.presence"]._update_presence(bob_operator)
|
||||
data = self.make_jsonrpc_request(
|
||||
"/im_livechat/get_session", {"channel_id": self.livechat_channel.id}
|
||||
)
|
||||
channel = self.env["discuss.channel"].browse(data["channel_id"])
|
||||
message = channel.message_post(
|
||||
author_id=bob_operator.partner_id.id,
|
||||
body="Hello, how can I help you?",
|
||||
message_type="comment",
|
||||
)
|
||||
channel._message_update_content(message, body="")
|
||||
self.env.invalidate_all()
|
||||
self.assertFalse(channel.lead_ids)
|
||||
channel.with_user(bob_operator).execute_command_lead(body="/lead BobLead")
|
||||
self.assertEqual(channel.lead_ids.name, "BobLead")
|
||||
|
|
|
|||
|
|
@ -0,0 +1,68 @@
|
|||
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
||||
|
||||
from odoo.exceptions import AccessError
|
||||
from odoo.tests.common import HttpCase, new_test_user, tagged
|
||||
|
||||
|
||||
@tagged("post_install", "-at_install")
|
||||
class TestDiscussChannelAccess(HttpCase):
|
||||
def test_access_channel_from_lead(self):
|
||||
test_cases = [
|
||||
# user_grp - has_lead - expected_result
|
||||
("base.group_public", False, False),
|
||||
("base.group_public", True, False),
|
||||
("base.group_portal", False, False),
|
||||
("base.group_portal", True, False),
|
||||
("base.group_user", False, False),
|
||||
("base.group_user", True, False),
|
||||
("sales_team.group_sale_salesman", False, False),
|
||||
("sales_team.group_sale_salesman", True, True),
|
||||
]
|
||||
for idx, case in enumerate(test_cases):
|
||||
user_grp, has_lead, expected_result = case
|
||||
crm_lead = self.env["crm.lead"]
|
||||
if has_lead:
|
||||
crm_lead = self.env["crm.lead"].create({"name": f"ticket_{idx}"})
|
||||
channel = self.env["discuss.channel"].create(
|
||||
{
|
||||
"name": f"channel_{idx}",
|
||||
"livechat_operator_id": self.env.user.partner_id.id,
|
||||
"channel_type": "livechat",
|
||||
"lead_ids": crm_lead.ids,
|
||||
}
|
||||
)
|
||||
user = new_test_user(self.env, login=f"user_{idx}_{user_grp}", groups=user_grp)
|
||||
self.assertEqual(
|
||||
channel.with_user(user).has_access("read"),
|
||||
expected_result,
|
||||
f"user_grp={user_grp}, has_lead={has_lead}, expected_result={expected_result}",
|
||||
)
|
||||
|
||||
def test_cannot_link_lead_to_restricted_channel(self):
|
||||
user = new_test_user(self.env, login="bob_user", groups="sales_team.group_sale_salesman")
|
||||
channel = (
|
||||
self.env["discuss.channel"]
|
||||
.create(
|
||||
{
|
||||
"name": f"Visitor #11",
|
||||
"livechat_operator_id": self.env.user.partner_id.id,
|
||||
"channel_type": "livechat",
|
||||
}
|
||||
)
|
||||
.with_user(user)
|
||||
)
|
||||
self.assertFalse(channel.has_access("read"))
|
||||
with self.assertRaises(
|
||||
AccessError,
|
||||
msg="You cannot create a lead linked to a channel you don't have access to.",
|
||||
):
|
||||
self.env["crm.lead"].with_user(user).create(
|
||||
{"name": "lead", "origin_channel_id": channel.id}
|
||||
)
|
||||
|
||||
lead = self.env["crm.lead"].with_user(user).create({"name": "lead"})
|
||||
with self.assertRaises(
|
||||
AccessError,
|
||||
msg="You cannot update a lead and link it to a channel you don't have access to.",
|
||||
):
|
||||
lead.write({"origin_channel_id": channel.id})
|
||||
Loading…
Add table
Add a link
Reference in a new issue