[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
This commit is contained in:
committed by
Thibault Delavallée
parent
a661b00015
commit
f49d83f07d
@@ -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',
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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>
|
||||
Reference in New Issue
Block a user