diff options
| author | qmo-odoo <qmo@odoo.com> | 2019-08-02 07:50:19 +0000 |
|---|---|---|
| committer | Thibault Delavallée <tde@odoo.com> | 2019-08-02 12:33:42 +0000 |
| commit | f49d83f07dee59ddc19b7aa722ab50ad87e34389 (patch) | |
| tree | 998d25efe1d2219d056dafd9975c2462f40900a7 | |
| parent | a661b00015557281faca7c88eae4aa5321a2b843 (diff) | |
[IMP] utm, crm: add lead/opportunity stats on campaign
PURPOSE
This commit removes the mass_mailing.campaign model. Instead of having a fully
fledged model, we will simply inherit utm.campaign. We will also add relevant
statistics on utm campaign model in order to use it in various applications.
SPECIFICATIONS
This commit adds leads/generated statistics in the kanban and
the form view of the utm campaign.
Kanban and form views will now display the number of leads and
opportunities generated with the campaign
TaskID: 2002029
PR: #34452
| -rw-r--r-- | addons/crm/__manifest__.py | 1 | ||||
| -rw-r--r-- | addons/crm/models/__init__.py | 1 | ||||
| -rw-r--r-- | addons/crm/models/utm.py | 42 | ||||
| -rw-r--r-- | addons/crm/views/utm_campaign_views.xml | 50 |
4 files changed, 94 insertions, 0 deletions
diff --git a/addons/crm/__manifest__.py b/addons/crm/__manifest__.py index 1100d1f4214..acb084220cc 100644 --- a/addons/crm/__manifest__.py +++ b/addons/crm/__manifest__.py @@ -47,6 +47,7 @@ 'report/crm_opportunity_report_views.xml', 'views/crm_team_views.xml', 'views/digest_views.xml', + 'views/utm_campaign_views.xml' ], 'demo': [ 'data/crm_demo.xml', diff --git a/addons/crm/models/__init__.py b/addons/crm/models/__init__.py index 0a441965aa8..463bcc22e85 100644 --- a/addons/crm/models/__init__.py +++ b/addons/crm/models/__init__.py @@ -10,3 +10,4 @@ from . import res_config_settings from . import res_partner from . import digest from . import crm_lead_scoring_frequency +from . import utm diff --git a/addons/crm/models/utm.py b/addons/crm/models/utm.py new file mode 100644 index 00000000000..c68f6b43365 --- /dev/null +++ b/addons/crm/models/utm.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Part of Odoo. See LICENSE file for full copyright and licensing details. + +from odoo import fields, models, api, SUPERUSER_ID + +class UtmCampaign(models.Model): + _inherit = 'utm.campaign' + + crm_lead_activated = fields.Boolean('Use Leads', compute='_compute_crm_lead_activated') + lead_count = fields.Integer('Lead Count', groups='sales_team.group_sale_salesman', compute="_compute_global_opportunity_and_lead_count") + opportunity_count = fields.Integer('Opportunity Count', groups='sales_team.group_sale_salesman', compute="_compute_global_opportunity_and_lead_count") + + def _compute_crm_lead_activated(self): + for campaign in self: + campaign.crm_lead_activated = self.env.user.has_group('crm.group_use_lead') + + def _compute_global_opportunity_and_lead_count(self): + lead_data = self.env['crm.lead'].with_context(active_test=False).read_group([ + ('campaign_id', 'in', self.ids)], + ['campaign_id'], ['campaign_id']) + data_map = {datum['campaign_id'][0]: datum['campaign_id_count'] for datum in lead_data} + if self.env.user.has_group('crm.group_use_lead'): + for campaign in self: + campaign.lead_count = data_map.get(campaign.id, 0) + campaign.opportunity_count = 0 + else: + for campaign in self: + campaign.lead_count = 0 + campaign.opportunity_count = data_map.get(campaign.id, 0) + + def action_redirect_to_leads(self): + action = self.env.ref('crm.crm_lead_all_leads').read()[0] + action['domain'] = [('campaign_id', '=', self.id)] + action['context'] = {'default_type': 'lead', 'active_test': False} + return action + + def action_redirect_to_opportunities(self): + action = self.env.ref('crm.crm_lead_opportunities').read()[0] + action['view_mode'] = 'tree,kanban,graph,pivot,form,calendar' + action['domain'] = [('campaign_id', '=', self.id)] + action['context'] = {'active_test': False} + return action diff --git a/addons/crm/views/utm_campaign_views.xml b/addons/crm/views/utm_campaign_views.xml new file mode 100644 index 00000000000..bb6e0abb78d --- /dev/null +++ b/addons/crm/views/utm_campaign_views.xml @@ -0,0 +1,50 @@ +<?xml version="1.0" encoding="utf-8"?> +<odoo> + <record model="ir.ui.view" id="utm_campaign_view_kanban"> + <field name="name">utm.campaign.view.kanban</field> + <field name="model">utm.campaign</field> + <field name="inherit_id" ref="utm.utm_campaign_view_kanban"/> + <field name="arch" type="xml"> + <xpath expr="//div[@id='utm_statistics']" position="inside"> + <field name="crm_lead_activated" invisible="1"/> + <div class="d-flex justify-content-between align-items-center w-100 order-3 mb-1" + groups="sales_team.group_sale_salesman" + attrs="{'invisible': [('crm_lead_activated', '=', False)]}"> + <strong>Leads</strong> <span><field name="lead_count"/></span> + </div> + <div class="d-flex justify-content-between align-items-center w-100 order-3 mb-1" + groups="sales_team.group_sale_salesman" + attrs="{'invisible': [('crm_lead_activated', '=', True)]}"> + <strong>Opportunities</strong> <span><field name="opportunity_count"/></span> + </div> + </xpath> + </field> + </record> + + <record model="ir.ui.view" id="utm_campaign_view_form"> + <field name="name">utm.campaign.view.form</field> + <field name="model">utm.campaign</field> + <field name="inherit_id" ref="utm.utm_campaign_view_form"/> + <field name="arch" type="xml"> + <xpath expr="//div[hasclass('oe_button_box')]" position="inside"> + <field name="crm_lead_activated" invisible="1"/> + <button name="action_redirect_to_leads" + type="object" + class="oe_stat_button order-3" + icon="fa-star" + groups="sales_team.group_sale_salesman" + attrs="{'invisible': [('crm_lead_activated', '=', False)]}"> + <field name="lead_count" widget="statinfo" string="Leads"/> + </button> + <button name="action_redirect_to_opportunities" + type="object" + class="oe_stat_button order-3" + icon="fa-star" + groups="sales_team.group_sale_salesman" + attrs="{'invisible': [('crm_lead_activated', '=', True)]}"> + <field name="opportunity_count" widget="statinfo" string="Opportunities"/> + </button> + </xpath> + </field> + </record> +</odoo> |
