Skip to content
Snippets Groups Projects
Commit 8c257a62 authored by David Beguin's avatar David Beguin
Browse files

[IMP] website_crm_livechat : link visitor to lead on /lead command


If an operator executes the /lead commands, the visitor was not linked to the
lead. This commit fixed that. The visitor is now linked to the lead but the
visitor does not take the lead's name.
(As '/lead leadName' creates a lead with 'leadName' as name but not as contact
name and the visitor needs the contact name of the lead)

Task ID: 2081534
PR #38706

Signed-off-by: default avatarThibault Delavallee (tde) <tde@openerp.com>
parent 3ae0f156
Branches
Tags
No related merge requests found
......@@ -21,20 +21,24 @@ class MailChannel(models.Model):
if key.strip() == '/lead':
msg = self._define_command_lead()['help']
else:
description = ''.join(
'%s: %s\n' % (message.author_id.name or self.anonymous_name, message.body)
for message in self.channel_message_ids.sorted('id')
)
utm_source = self.env.ref('crm_livechat.utm_source_livechat', raise_if_not_found=False)
lead = self.env['crm.lead'].create({
'name': html2plaintext(key[5:]),
'partner_id': channel_partners.partner_id.id,
'user_id': None,
'team_id': None,
'description': html2plaintext(description),
'referred': partner.name,
'source_id': utm_source and utm_source.id,
})
lead._onchange_partner_id()
lead = self._convert_visitor_to_lead(partner, channel_partners, key)
msg = _('Created a new lead: <a href="#" data-oe-id="%s" data-oe-model="crm.lead">%s</a>') % (lead.id, lead.name)
self._send_transient_message(partner, msg)
def _convert_visitor_to_lead(self, partner, channel_partners, key):
description = ''.join(
'%s: %s\n' % (message.author_id.name or self.anonymous_name, message.body)
for message in self.channel_message_ids.sorted('id')
)
utm_source = self.env.ref('crm_livechat.utm_source_livechat', raise_if_not_found=False)
lead = self.env['crm.lead'].create({
'name': html2plaintext(key[5:]),
'partner_id': channel_partners.partner_id.id,
'user_id': None,
'team_id': None,
'description': html2plaintext(description),
'referred': partner.name,
'source_id': utm_source and utm_source.id,
})
lead._onchange_partner_id()
return lead
......@@ -2,3 +2,4 @@
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from . import crm_lead
from . import mail_channel
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
from odoo import models
class MailChannel(models.Model):
_inherit = 'mail.channel'
def _convert_visitor_to_lead(self, partner, channel_partners, key):
""" When website is installed, we can link the created lead from /lead command
to the current website_visitor. We do not use the lead name as it does not correspond
to the lead contact name."""
lead = super(MailChannel, self)._convert_visitor_to_lead(partner, channel_partners, key)
visitor_sudo = self.livechat_visitor_id.sudo()
if visitor_sudo:
visitor_sudo.write({'lead_ids': [(4, lead.id)]})
return lead
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment