summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorFlorent de Labarre <florent.mirieu@gmail.com>2021-05-11 10:13:12 +0000
committerFlorent de Labarre <florent.mirieu@gmail.com>2021-05-11 13:27:39 +0000
commit9fc8511ad85c85d803503346fb0f0a39bb0e6b23 (patch)
treef5a7b1b39412d7ae55f594852e351aa297353320 /addons
parent37be09d7d73bd4942396f06f5b5cfa22cca78f56 (diff)
[FIX] crm_livechat: do not set public user partner as lead customer usign /lead command
Before this commit, when you create a lead from livechat with the command /lead, the public user is used inside the lead. Because the public user is archived, and self.env.ref('base.public_partner').user_ids return an empty recordset. closes odoo/odoo#70655 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
Diffstat (limited to 'addons')
-rw-r--r--addons/crm_livechat/models/mail_channel.py2
-rw-r--r--addons/crm_livechat/tests/test_crm_lead.py17
2 files changed, 18 insertions, 1 deletions
diff --git a/addons/crm_livechat/models/mail_channel.py b/addons/crm_livechat/models/mail_channel.py
index b7650342d5a..9c775983b12 100644
--- a/addons/crm_livechat/models/mail_channel.py
+++ b/addons/crm_livechat/models/mail_channel.py
@@ -39,7 +39,7 @@ class MailChannel(models.Model):
# anonymous user whatever the participants. Otherwise keep only share
# partners (no user or portal user) to link to the lead.
customers = self.env['res.partner']
- for customer in channel_partners.partner_id.filtered('partner_share'):
+ for customer in channel_partners.partner_id.filtered('partner_share').with_context(active_test=False):
if customer.user_ids and all(user._is_public() for user in customer.user_ids):
customers = self.env['res.partner']
break
diff --git a/addons/crm_livechat/tests/test_crm_lead.py b/addons/crm_livechat/tests/test_crm_lead.py
index c3d6364e385..0c012b2058a 100644
--- a/addons/crm_livechat/tests/test_crm_lead.py
+++ b/addons/crm_livechat/tests/test_crm_lead.py
@@ -44,6 +44,23 @@ class TestLivechatLead(TestCrmCommon):
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, channel.channel_last_seen_partner_ids, '/lead TestLead command')
+
+ self.assertEqual(
+ channel.channel_last_seen_partner_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 he was anonymous)
channel.write({
'channel_partner_ids': [(4, self.user_sales_manager.partner_id.id)]