PURPOSE This commits adds a special step_type on the chatbot.script.steps that allows creating a crm.lead when reaching it. SPECS In addition, we let the end user configure in which crm.team that lead will land upon being created, making it possible to sort your leads based on previous questions. e.g: "In which country do you live" And based on the answer, you assign to a different sales.team. This commit comes with the necessary business code to make this feature work as well as some extra testing methods that ensure it is correctly implemented. Task-2030386 Part-of: odoo/odoo#84000 Co-authored-by: Patrick Hoste <pko@odoo.com> Co-authored-by: Aurélien Warnon <awa@odoo.com>
52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.crm_livechat.tests import chatbot_common
|
|
from odoo.tests.common import users
|
|
|
|
|
|
class CrmChatbotCase(chatbot_common.CrmChatbotCase):
|
|
|
|
@users('user_public')
|
|
def test_chatbot_lead_public_user(self):
|
|
self._chatbot_create_lead(self.user_public)
|
|
|
|
created_lead = self.env['crm.lead'].sudo().search([], limit=1, order='id desc')
|
|
self.assertEqual(created_lead.name, "Testing Bot's New Lead")
|
|
self.assertEqual(created_lead.email_from, 'test2@example.com')
|
|
self.assertEqual(created_lead.phone, '123456')
|
|
|
|
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):
|
|
self.step_create_lead.write({'crm_team_id': self.sale_team_with_lead})
|
|
self._chatbot_create_lead(self.user_portal)
|
|
|
|
created_lead = self.env['crm.lead'].sudo().search([], limit=1, order='id desc')
|
|
self.assertEqual(created_lead.name, "Testing Bot's New Lead")
|
|
self.assertNotEqual(created_lead.email_from, 'test2@example.com', "User's email should'nt have been overridden")
|
|
self.assertEqual(created_lead.phone, '123456', "User's phone should have been updated")
|
|
|
|
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'])
|
|
|
|
self._post_answer_and_trigger_next_step(
|
|
mail_channel,
|
|
self.step_dispatch_create_lead.name,
|
|
chatbot_script_answer=self.step_dispatch_create_lead
|
|
)
|
|
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.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)
|