Skip to content
Snippets Groups Projects
Commit 9fc8511a authored by Florent de Labarre's avatar Florent de Labarre
Browse files

[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: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 37be09d7
Branches
Tags
No related merge requests found
......@@ -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
......
......@@ -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)]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment