PURPOSE This commits adds a special step_type on the chatbot.script.steps that allows creating a crm.lead when reaching it. SPECS In addition, we let the end user configure in which crm.team that lead will land upon being created, making it possible to sort your leads based on previous questions. e.g: "In which country do you live" And based on the answer, you assign to a different sales.team. This commit comes with the necessary business code to make this feature work as well as some extra testing methods that ensure it is correctly implemented. Task-2030386 Part-of: odoo/odoo#84000 Co-authored-by: Patrick Hoste <pko@odoo.com> Co-authored-by: Aurélien Warnon <awa@odoo.com>
29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Part of Odoo. See LICENSE file for full copyright and licensing details.
|
|
|
|
from odoo import models, fields
|
|
|
|
|
|
class ChatbotScript(models.Model):
|
|
_inherit = 'chatbot.script'
|
|
|
|
lead_count = fields.Integer(
|
|
string='Generated Lead Count', compute='_compute_lead_count')
|
|
|
|
def _compute_lead_count(self):
|
|
mapped_leads = {}
|
|
if self.ids:
|
|
leads_data = self.env['crm.lead'].with_context(active_test=False).sudo()._read_group(
|
|
[('source_id', 'in', self.mapped('source_id').ids)], ['source_id'], ['source_id'])
|
|
mapped_leads = {lead['source_id'][0]: lead['source_id_count'] for lead in leads_data}
|
|
|
|
for script in self:
|
|
script.lead_count = mapped_leads.get(script.source_id.id, 0)
|
|
|
|
def action_view_leads(self):
|
|
self.ensure_one()
|
|
action = self.env['ir.actions.act_window']._for_xml_id('crm.crm_lead_all_leads')
|
|
action['domain'] = [('source_id', '=', self.source_id.id)]
|
|
action['context'] = {'create': False}
|
|
return action
|