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>
67 lines
2.6 KiB
Python
67 lines
2.6 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo.addons.im_livechat.tests.chatbot_common import ChatbotCase
|
|
from odoo.addons.mail.tests.common import mail_new_test_user
|
|
|
|
|
|
class CrmChatbotCase(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,
|
|
})
|
|
|
|
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,
|
|
cls.step_create_lead,
|
|
] = cls.env['chatbot.script.step'].sudo().create([{
|
|
'step_type': 'question_email',
|
|
'message': 'Could you provide us your email please.',
|
|
'sequence': 20,
|
|
'triggering_answer_ids': [(4, cls.step_dispatch_create_lead.id)],
|
|
'chatbot_script_id': cls.chatbot_script.id,
|
|
}, {
|
|
'step_type': 'question_phone',
|
|
'message': 'Could you also provide your phone please.',
|
|
'sequence': 21,
|
|
'triggering_answer_ids': [(4, cls.step_dispatch_create_lead.id)],
|
|
'chatbot_script_id': cls.chatbot_script.id,
|
|
}, {
|
|
'step_type': 'create_lead',
|
|
'message': 'Thank you! A lead has been created.',
|
|
'sequence': 22,
|
|
'triggering_answer_ids': [(4, cls.step_dispatch_create_lead.id)],
|
|
'crm_team_id': cls.sale_team.id,
|
|
'chatbot_script_id': cls.chatbot_script.id,
|
|
}])
|