Initial commit: Crm packages

This commit is contained in:
Ernad Husremovic 2025-08-29 15:20:49 +02:00
commit 21a345b5b9
654 changed files with 418312 additions and 0 deletions

View file

@ -0,0 +1,6 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import chatbot_common
from . import test_chatbot_lead
from . import test_crm_lead

View file

@ -0,0 +1,66 @@
# -*- 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,
}])

View file

@ -0,0 +1,51 @@
# -*- 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)

View file

@ -0,0 +1,94 @@
# -*- 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='email',
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='email',
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 user: should not be set as customer
# '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)]
})
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'])
# public + someone else: no customer (as they were 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)