test_crm_lead.py 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. # -*- coding: utf-8 -*-
  2. # Part of Odoo. See LICENSE file for full copyright and licensing details.
  3. from odoo.addons.crm.tests.common import TestCrmCommon
  4. from odoo.addons.mail.tests.common import mail_new_test_user
  5. from odoo.tests.common import users
  6. class TestLivechatLead(TestCrmCommon):
  7. @classmethod
  8. def setUpClass(cls):
  9. super(TestLivechatLead, cls).setUpClass()
  10. cls.user_anonymous = mail_new_test_user(
  11. cls.env, login='user_anonymous',
  12. name='Anonymous Website', email=False,
  13. company_id=cls.company_main.id,
  14. notification_type='email',
  15. groups='base.group_public',
  16. )
  17. cls.user_portal = mail_new_test_user(
  18. cls.env, login='user_portal',
  19. name='Paulette Portal', email='user_portal@test.example.com',
  20. company_id=cls.company_main.id,
  21. notification_type='email',
  22. groups='base.group_portal',
  23. )
  24. @users('user_sales_leads')
  25. def test_crm_lead_creation_guest(self):
  26. """ Test customer set on lead: not if public, guest if not public """
  27. # public: should not be set as customer
  28. channel = self.env['mail.channel'].create({
  29. 'name': 'Chat with Visitor',
  30. 'channel_partner_ids': [(4, self.user_anonymous.partner_id.id)]
  31. })
  32. lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
  33. self.assertEqual(
  34. channel.channel_partner_ids,
  35. self.user_sales_leads.partner_id | self.user_anonymous.partner_id
  36. )
  37. self.assertEqual(lead.name, 'TestLead command')
  38. self.assertEqual(lead.partner_id, self.env['res.partner'])
  39. # public user: should not be set as customer
  40. # 'base.public_user' is archived by default
  41. self.assertFalse(self.env.ref('base.public_user').active)
  42. channel = self.env['mail.channel'].create({
  43. 'name': 'Chat with Visitor',
  44. 'channel_partner_ids': [(4, self.env.ref('base.public_partner').id)]
  45. })
  46. lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
  47. self.assertEqual(
  48. channel.channel_member_ids.partner_id,
  49. self.user_sales_leads.partner_id | self.env.ref('base.public_partner')
  50. )
  51. self.assertEqual(lead.name, 'TestLead command')
  52. self.assertEqual(lead.partner_id, self.env['res.partner'])
  53. # public + someone else: no customer (as they were anonymous)
  54. channel.write({
  55. 'channel_partner_ids': [(4, self.user_sales_manager.partner_id.id)]
  56. })
  57. lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
  58. self.assertEqual(lead.partner_id, self.env['res.partner'])
  59. # portal: should be set as customer
  60. channel = self.env['mail.channel'].create({
  61. 'name': 'Chat with Visitor',
  62. 'channel_partner_ids': [(4, self.user_portal.partner_id.id)]
  63. })
  64. lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
  65. self.assertEqual(
  66. channel.channel_partner_ids,
  67. self.user_sales_leads.partner_id | self.user_portal.partner_id
  68. )
  69. self.assertEqual(lead.partner_id, self.user_portal.partner_id)
  70. # another operator invited: internal user should not be customer if portal is present
  71. channel.write({
  72. 'channel_partner_ids': [(4, self.user_sales_manager.partner_id.id)]
  73. })
  74. lead = channel._convert_visitor_to_lead(self.env.user.partner_id, '/lead TestLead command')
  75. self.assertEqual(
  76. channel.channel_partner_ids,
  77. self.user_sales_leads.partner_id | self.user_portal.partner_id | self.user_sales_manager.partner_id
  78. )
  79. self.assertEqual(lead.partner_id, self.user_portal.partner_id)