[IMP] crm_livechat: add source on lead cmd

Auto add source Livechat when lead created from livechat command /lead

task:internal-request

closes odoo/odoo#34763

Signed-off-by: Jérémy Kersten (jke) <jke@openerp.com>
This commit is contained in:
Jeremy Kersten
2019-07-10 15:28:37 +00:00
parent 4a51fad2d5
commit 378e448a89
3 changed files with 13 additions and 1 deletions
+3
View File
@@ -5,6 +5,9 @@
'name': 'CRM Livechat',
'category': 'crm',
'summary': 'Create lead from livechat conversation',
'data': [
'data/utm_data.xml',
],
'depends': [
'crm',
'im_livechat'
+6
View File
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record model="utm.source" id="utm_source_livechat">
<field name="name">Livechat</field>
</record>
</odoo>
+4 -1
View File
@@ -4,6 +4,7 @@
from odoo import models, _
from odoo.tools import html2plaintext
class MailChannel(models.Model):
_inherit = 'mail.channel'
@@ -24,13 +25,15 @@ class MailChannel(models.Model):
'%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
'referred': partner.name,
'source_id': utm_source and utm_source.id,
})
lead._onchange_partner_id()
msg = _('Created a new lead: <a href="#" data-oe-id="%s" data-oe-model="crm.lead">%s</a>') % (lead.id, lead.name)