diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website_crm_livechat/models | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website_crm_livechat/models')
| -rw-r--r-- | addons/website_crm_livechat/models/__init__.py | 5 | ||||
| -rw-r--r-- | addons/website_crm_livechat/models/crm_lead.py | 21 | ||||
| -rw-r--r-- | addons/website_crm_livechat/models/mail_channel.py | 19 |
3 files changed, 45 insertions, 0 deletions
diff --git a/addons/website_crm_livechat/models/__init__.py b/addons/website_crm_livechat/models/__init__.py new file mode 100644 index 00000000..e81172ec --- /dev/null +++ b/addons/website_crm_livechat/models/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import crm_lead +from . import mail_channel diff --git a/addons/website_crm_livechat/models/crm_lead.py b/addons/website_crm_livechat/models/crm_lead.py new file mode 100644 index 00000000..1b2622aa --- /dev/null +++ b/addons/website_crm_livechat/models/crm_lead.py @@ -0,0 +1,21 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import api, fields, models + + +class Lead(models.Model): + _inherit = 'crm.lead' + + visitor_sessions_count = fields.Integer('# Sessions', compute="_compute_visitor_sessions_count", groups="im_livechat.im_livechat_group_user") + + @api.depends('visitor_ids.mail_channel_ids') + def _compute_visitor_sessions_count(self): + for lead in self: + lead.visitor_sessions_count = len(lead.visitor_ids.mail_channel_ids) + + def action_redirect_to_livechat_sessions(self): + visitors = self.visitor_ids + action = self.env["ir.actions.actions"]._for_xml_id("website_livechat.website_visitor_livechat_session_action") + action['domain'] = [('livechat_visitor_id', 'in', visitors.ids), ('channel_message_ids', '!=', False)] + return action diff --git a/addons/website_crm_livechat/models/mail_channel.py b/addons/website_crm_livechat/models/mail_channel.py new file mode 100644 index 00000000..64d5b93c --- /dev/null +++ b/addons/website_crm_livechat/models/mail_channel.py @@ -0,0 +1,19 @@ +# -*- 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)]}) + lead.country_id = lead.country_id or visitor_sudo.country_id + return lead |
