diff options
| author | Jérémy Hennecart <jeh@odoo.com> | 2020-01-27 13:28:31 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2020-06-10 16:10:28 +0000 |
| commit | dbad574ef9c67cc88c495bb00e60204d1ac10b04 (patch) | |
| tree | 34931f3addcc16c6cff3e98a8edd811102a4259e /addons | |
| parent | 76129e3b445e29c70b143fd7af3fb694a1e70680 (diff) | |
[ADD] event_crm_sale: create leads from attendees
PURPOSE
Introduce an automated tool to create leads from event registrations. Events
are a powerful source of leads as they attract attention. This leads to leads
with good quality as they mark interest while gathering contact information
which allows to follow-up.
This merge aims at automating this process by automatically creating leads
based on user-defined rules.
SPECIFICATIONS
Ensure information updated on sale order also updates lead information.
Also display group-based option for rules as registrations can now be
grouped by sale order.
LINKS
Task ID 2166679
PR #52334
Upgrade PR odoo/upgrade#1292
Co-Authored-By: Jérémy Hennecart <jeh@odoo.com>
Co-Authored-By: Thibault Delavallée <tde@odoo.com>
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/event_crm_sale/__init__.py | 4 | ||||
| -rw-r--r-- | addons/event_crm_sale/__manifest__.py | 16 | ||||
| -rw-r--r-- | addons/event_crm_sale/models/__init__.py | 4 | ||||
| -rw-r--r-- | addons/event_crm_sale/models/event_registration.py | 49 | ||||
| -rw-r--r-- | addons/event_crm_sale/views/event_lead_rule_views.xml | 23 |
5 files changed, 96 insertions, 0 deletions
diff --git a/addons/event_crm_sale/__init__.py b/addons/event_crm_sale/__init__.py new file mode 100644 index 00000000000..dc5e6b693d1 --- /dev/null +++ b/addons/event_crm_sale/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import models diff --git a/addons/event_crm_sale/__manifest__.py b/addons/event_crm_sale/__manifest__.py new file mode 100644 index 00000000000..566aea08da3 --- /dev/null +++ b/addons/event_crm_sale/__manifest__.py @@ -0,0 +1,16 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +{ + 'name': 'Event CRM Sale', + 'version': '1.0', + 'category': 'Marketing/Events', + 'website': 'https://www.odoo.com/page/events', + 'description': "Add information of sale order linked to the registration for the creation of the lead.", + 'depends': ['event_crm', 'event_sale'], + 'data': [ + 'views/event_lead_rule_views.xml', + ], + 'installable': True, + 'auto_install': True, +} diff --git a/addons/event_crm_sale/models/__init__.py b/addons/event_crm_sale/models/__init__.py new file mode 100644 index 00000000000..20ce9ac3fb4 --- /dev/null +++ b/addons/event_crm_sale/models/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from . import event_registration diff --git a/addons/event_crm_sale/models/event_registration.py b/addons/event_crm_sale/models/event_registration.py new file mode 100644 index 00000000000..480d4a0e41f --- /dev/null +++ b/addons/event_crm_sale/models/event_registration.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from collections import defaultdict + +from odoo import models + + +class EventRegistration(models.Model): + _inherit = 'event.registration' + + def _get_lead_grouping(self, rules, rule_to_new_regs): + """ Override to support sale-order based grouping and update. + + When checking for groups for rules, we search for existing leads linked + to same group (based on sale_order_id) and rule. Each rule can therefore + update an existing lead or create a new one, for each sale order that + makes the group. """ + so_registrations = self.filtered(lambda reg: reg.sale_order_id) + grouping_res = super(EventRegistration, self - so_registrations)._get_lead_grouping(rules, rule_to_new_regs) + + if so_registrations: + # find existing leads in batch to put them in cache and avoid multiple search / queries + related_registrations = self.env['event.registration'].search([ + ('sale_order_id', 'in', so_registrations.sale_order_id.ids) + ]) + related_leads = self.env['crm.lead'].search([ + ('event_lead_rule_id', 'in', rules.ids), + ('registration_ids', 'in', related_registrations.ids) + ]) + + for rule in rules: + rule_new_regs = rule_to_new_regs[rule] + + # for each group (sale_order), find its linked registrations + so_to_regs = defaultdict(lambda: self.env['event.registration']) + for registration in rule_new_regs & so_registrations: + so_to_regs[registration.sale_order_id] |= registration + + # for each grouped registrations, prepare result with group and existing lead + so_res = [] + for sale_order, registrations in so_to_regs.items(): + registrations = registrations.sorted('id') # as an OR was used, re-ensure order + leads = related_leads.filtered(lambda lead: lead.event_lead_rule_id == rule and lead.registration_ids.sale_order_id == sale_order) + so_res.append((leads, sale_order, registrations)) + if so_res: + grouping_res[rule] = grouping_res.get(rule, list()) + so_res + + return grouping_res diff --git a/addons/event_crm_sale/views/event_lead_rule_views.xml b/addons/event_crm_sale/views/event_lead_rule_views.xml new file mode 100644 index 00000000000..e00481c8566 --- /dev/null +++ b/addons/event_crm_sale/views/event_lead_rule_views.xml @@ -0,0 +1,23 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record id="event_lead_rule_view_tree" model="ir.ui.view"> + <field name="name">event.lead.rule.view.tree.inherit.event.crm.sale</field> + <field name="model">event.lead.rule</field> + <field name="inherit_id" ref="event_crm.event_lead_rule_view_tree"/> + <field name="arch" type="xml"> + <xpath expr="//field[@name='lead_creation_basis']" position="attributes"> + <attribute name="invisible">0</attribute> + </xpath> + </field> + </record> + <record id="event_lead_rule_view_form" model="ir.ui.view"> + <field name="name">event.lead.rule.view.form.inherit.event.crm.sale</field> + <field name="model">event.lead.rule</field> + <field name="inherit_id" ref="event_crm.event_lead_rule_view_form"/> + <field name="arch" type="xml"> + <xpath expr="//group[@name='lead_creation_basis']" position="attributes"> + <attribute name="invisible">0</attribute> + </xpath> + </field> + </record> +</odoo> |
