diff --git a/addons/crm_livechat/__init__.py b/addons/crm_livechat/__init__.py new file mode 100644 index 00000000000..81fc81d29c9 --- /dev/null +++ b/addons/crm_livechat/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import models diff --git a/addons/crm_livechat/__manifest__.py b/addons/crm_livechat/__manifest__.py new file mode 100644 index 00000000000..bbded070830 --- /dev/null +++ b/addons/crm_livechat/__manifest__.py @@ -0,0 +1,14 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'CRM Livechat', + 'category': 'crm', + 'summary': 'Create lead from livechat conversation', + 'depends': [ + 'crm', + 'im_livechat' + ], + 'description': 'Create new lead with using /lead command in the channel', + 'auto_install': True +} diff --git a/addons/crm_livechat/models/__init__.py b/addons/crm_livechat/models/__init__.py new file mode 100644 index 00000000000..aadaef60aaf --- /dev/null +++ b/addons/crm_livechat/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +import mail_channel diff --git a/addons/crm_livechat/models/mail_channel.py b/addons/crm_livechat/models/mail_channel.py new file mode 100644 index 00000000000..9db2cfd2ea4 --- /dev/null +++ b/addons/crm_livechat/models/mail_channel.py @@ -0,0 +1,37 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import models, _ +from odoo.tools import html2plaintext + +class MailChannel(models.Model): + _inherit = 'mail.channel' + + def _define_command_lead(self): + return {'help': _('Create a new lead (/lead lead title)')} + + def _execute_command_lead(self, **kwargs): + partner = self.env.user.partner_id + key = kwargs['body'] + channel_partners = self.env['mail.channel.partner'].search([ + ('partner_id', '!=', partner.id), + ('channel_id', '=', self.id)], limit=1 + ) + 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') + ) + 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 + }) + lead._onchange_partner_id() + msg = _('Created a new lead: %s') % (lead.id, lead.name) + self._send_transient_message(partner, msg)