summaryrefslogtreecommitdiff
path: root/addons/crm_livechat
diff options
context:
space:
mode:
authorDavid Beguin <dbe@odoo.com>2019-10-07 15:05:10 +0000
committerDavid Beguin <dbe@odoo.com>2019-11-20 13:33:08 +0000
commitdc101d12a59583563f0969d1a8eeb4406a107f99 (patch)
tree52a8d4ef25ea45fb76d78137a9e999e7a19aa309 /addons/crm_livechat
parent75dc5149555458596501491d81983cdcc774be29 (diff)
[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 closes odoo/odoo#41960 X-original-commit: 8c257a6219f72118af4e81c14fb2c6c9f320df17 Signed-off-by: David Beguin <dbeguin@users.noreply.github.com>
Diffstat (limited to 'addons/crm_livechat')
-rw-r--r--addons/crm_livechat/models/mail_channel.py34
1 files changed, 19 insertions, 15 deletions
diff --git a/addons/crm_livechat/models/mail_channel.py b/addons/crm_livechat/models/mail_channel.py
index 9b3765942c8..346859b906e 100644
--- a/addons/crm_livechat/models/mail_channel.py
+++ b/addons/crm_livechat/models/mail_channel.py
@@ -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