Browse Source

[UPDT] CRM dashboard update

pull/195/head
Ajmal Cybro 4 years ago
parent
commit
3dbb6d87af
  1. 2
      crm_dashboard/README.rst
  2. 4
      crm_dashboard/__manifest__.py
  3. 2
      crm_dashboard/doc/RELEASE_NOTES.md
  4. 45
      crm_dashboard/models/crm_dashboard.py
  5. 63
      crm_dashboard/static/src/js/custom.js
  6. 342
      crm_dashboard/static/src/js/dashboard_view.js
  7. 24
      crm_dashboard/static/src/xml/dashboard_view.xml

2
crm_dashboard/README.rst

@ -1,5 +1,5 @@
CRM Dashboard
=============
==================
* CRM Dashboard module for Odoo 15.
Installation

4
crm_dashboard/__manifest__.py

@ -25,7 +25,7 @@
'summary': """CRM dashboard module brings a multipurpose graphical dashboard"""
""" for CRM module and making the relationship management better and easier""",
'category': 'Sales',
'version': '15.0.1.0.0',
'version': '15.0.1.0.1',
'author': 'Cybrosys Techno Solutions',
'company': 'Cybrosys Techno Solutions',
'maintainer': 'Cybrosys Techno Solutions',
@ -51,7 +51,7 @@
],
'web.assets_qweb': [
'crm_dashboard/static/src/xml/dashboard_view.xml',
'crm_dashboard/static/src/xml/sub_dashboard.xml',
# 'crm_dashboard/static/src/xml/sub_dashboard.xml',
],
},
'images': [

2
crm_dashboard/doc/RELEASE_NOTES.md

@ -1,6 +1,6 @@
## Module <crm_dashboard>
#### 13.12.2021
#### 30.10.2021
#### Version 15.0.1.0.0
#### ADD
- Initial commit for CRM Dashboard Module

45
crm_dashboard/models/crm_dashboard.py

@ -322,8 +322,8 @@ class CRMLead(models.Model):
"""Top 10 Deals Table"""
self._cr.execute('''SELECT crm_lead.user_id,crm_lead.id,crm_lead.expected_revenue,
crm_lead.name,crm_lead.company_id, (SELECT crm_team.name FROM crm_team
WHERE crm_lead.team_id = crm_team.id) from crm_lead
where crm_lead.expected_revenue is not null GROUP BY crm_lead.user_id,
WHERE crm_lead.team_id = crm_team.id) from crm_lead where crm_lead.expected_revenue
is not null and crm_lead.type = 'opportunity' GROUP BY crm_lead.user_id,
crm_lead.id,crm_lead.expected_revenue,crm_lead.name,crm_lead.company_id
order by crm_lead.expected_revenue DESC limit 10''')
data1 = self._cr.fetchall()
@ -350,10 +350,11 @@ class CRMLead(models.Model):
"""Monthly Goal Gauge"""
uid = request.session.uid
leads = self.env['crm.lead'].search([('date_deadline', '!=', False),
('user_id', '=', uid)])
('user_id', '=', uid),
('type', '=', 'opportunity')])
leads_won = self.env['crm.lead'].search([('date_closed', '!=', False),
('stage_id', '=', 4),
('user_id', '=', uid)])
('stage_id', '=', 4), ('user_id', '=', uid),
('type', '=', 'opportunity')])
currency_symbol = self.env.company.currency_id.symbol
goals = []
@ -490,23 +491,23 @@ class CRMLead(models.Model):
return test
@api.model
def get_lost_reason_count(self):
"""Top 5 Lost Reason and Count"""
self._cr.execute('''select lost_reason,count(lost_reason) as counts
from crm_lead where probability=0 and active=false and lost_reason is not null
group by lost_reason order by counts desc limit 5''')
data1 = self._cr.fetchall()
reason_count = []
for rec in data1:
reason_id = rec[0]
reason_id_obj = self.env['crm.lost.reason'].browse(reason_id)
rec_list = list(rec)
rec_list[0] = reason_id_obj.name
reason_count.append(rec_list)
return {'reason_count': reason_count}
# @api.model
# def get_lost_reason_count(self):
# """Top 5 Lost Reason and Count"""
# self._cr.execute('''select lost_reason_id,count(lost_reason_id) as counts
# from crm_lead where probability=0 and active=false and lost_reason_id is not null
# group by lost_reason_id order by counts desc limit 5''')
# data1 = self._cr.fetchall()
#
# reason_count = []
# for rec in data1:
# reason_id = rec[0]
# reason_id_obj = self.env['crm.lost.reason'].browse(reason_id)
# rec_list = list(rec)
# rec_list[0] = reason_id_obj.name
# reason_count.append(rec_list)
#
# return {'reason_count': reason_count}
@api.model
def get_ratio_based_country(self):

63
crm_dashboard/static/src/js/custom.js

@ -1,34 +1,39 @@
odoo.define('crm_dashboard.custom', function (require) {
'use strict';
// $(document).ready(function(){
// $(window).load(function() {
// $(document).on("click", ".monthly_goal_div", function(event){
// $(document).on("click", "body", function(event){
var rpc = require('web.rpc');
var manager = false;
rpc.query({
model: "crm.lead",
method: "check_user_group",
})
.then(function (res) {
manager = res;
})
$(document).on("mousemove", ".dashboard_main_section", function(event){
var percentage_crm = $('#percentage_crm').val();
var gauge = new Gauge(document.getElementById("gauge"));
gauge.value(percentage_crm);
$('#country_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
$('#country_count_table').columnHeatmap({
columns: [1],
inverse:true,
});
$('#salesperson_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
if (manager) {
var percentage_crm = $('#percentage_crm').val();
var gauge = new Gauge(document.getElementById("gauge"));
gauge.value(percentage_crm);
$('#country_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
$('#country_count_table').columnHeatmap({
columns: [1],
inverse:true,
});
$('#salesperson_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
}
});
$(document).on("click", "#view_lost_dashboard", function(event){
$(".dashboard_main_section").css({'display':'none'});
$("#dashboard_sub_section").css({'display':'block'});
});
function BreadcrumbSubDash(){
$(".dashboard_main_section").css({'display':'block'});
$("#dashboard_sub_section").css({'display':'none'});
};
// $(document).on("click", "#view_lost_dashboard", function(event){
// $(".dashboard_main_section").css({'display':'none'});
// $("#dashboard_sub_section").css({'display':'block'});
// });
// function BreadcrumbSubDash(){
// $(".dashboard_main_section").css({'display':'block'});
// $("#dashboard_sub_section").css({'display':'none'});
// };
});

342
crm_dashboard/static/src/js/dashboard_view.js

@ -1,8 +1,5 @@
console.log("entered to dashboard_view js")
odoo.define('crm_dashboard.CRMDashboard', function (require) {
'use strict';
console.log("dashboard_view js loaded")
var AbstractAction = require('web.AbstractAction');
var ajax = require('web.ajax');
@ -48,24 +45,25 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
this.onclick_lost_last_month($target.val());
}
},
'change #total_loosed_crm_sub': function(e) {
e.stopPropagation();
var $target = $(e.target);
var value = $target.val();
if (value=="sub_lost_last_12months"){
this.onclick_sub_lost_last_12months($target.val());
}else if (value=="sub_lost_last_6months"){
this.onclick_sub_lost_last_6months($target.val());
}else if (value=="sub_lost_last_month"){
this.onclick_sub_lost_last_month($target.val());
}
},
// 'change #total_loosed_crm_sub': function(e) {
// e.stopPropagation();
// var $target = $(e.target);
// var value = $target.val();
// if (value=="sub_lost_last_12months"){
// this.onclick_sub_lost_last_12months($target.val());
// }else if (value=="sub_lost_last_6months"){
// this.onclick_sub_lost_last_6months($target.val());
// }else if (value=="sub_lost_last_month"){
// this.onclick_sub_lost_last_month($target.val());
// }
// },
},
init: function(parent, context) {
this._super(parent, context);
this.upcoming_events = [];
this.dashboards_templates = ['LoginUser','Managercrm','Admincrm', 'SubDashboard'];
// this.dashboards_templates = ['LoginUser','Managercrm','Admincrm', 'SubDashboard'];
this.dashboards_templates = ['LoginUser','Managercrm','Admincrm'];
this.login_employee = [];
},
@ -135,13 +133,13 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
self.top_country_count = res['country_count'];
});
var def7 = self._rpc({
model: "crm.lead",
method: "get_lost_reason_count",
})
.then(function (res) {
self.top_reason_count = res['reason_count'];
});
// var def7 = self._rpc({
// model: "crm.lead",
// method: "get_lost_reason_count",
// })
// .then(function (res) {
// self.top_reason_count = res['reason_count'];
// });
var def8 = self._rpc({
model: "crm.lead",
@ -191,12 +189,12 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
self.top_sp_by_invoice = res['sales_person_invoice'];
});
return $.when(def0, def1, def2, def3, def4, def5, def6, def7, def8, def9, def10, def11, def12, def13);
// return $.when(def0, def1, def2, def3, def4, def5, def6, def7, def8, def9, def10, def11, def12, def13);
return $.when(def0, def1, def2, def3, def4, def5, def6, def8, def9, def10, def11, def12, def13);
});
},
onclick_this_year: function (ev) {
console.log("onclick_this_year");
var self = this;
rpc.query({
model: 'crm.lead',
@ -253,7 +251,6 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
},
onclick_this_quarter: function (ev) {
console.log("onclick_this_quarter");
var self = this;
rpc.query({
model: 'crm.lead',
@ -310,7 +307,6 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
},
onclick_this_month: function (ev) {
console.log("onclick_this_month");
var self = this;
rpc.query({
model: 'crm.lead',
@ -367,7 +363,6 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
},
onclick_this_week: function (ev) {
console.log("onclick_this_week");
var self = this;
rpc.query({
model: 'crm.lead',
@ -424,7 +419,6 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
},
renderElement: function (ev) {
console.log("renderElement");
var self = this;
$.when(this._super())
.then(function (ev) {
@ -566,19 +560,11 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
self.render_medium_leads_graph();
self.render_source_leads_graph();
self.onclick_lost_last_12months();
self.onclick_sub_lost_last_12months();
// self.onclick_sub_lost_last_12months();
self.render_lost_leads_graph();
self.render_lost_leads_by_stage_graph();
self.render_revenue_count_pie();
// self.render_monthly_goal();
},
// render_monthly_goal: function () {
// console.log("month");
// var percentage_crm = this.$('#percentage_crm').val();
// console.log("percentage_crm",percentage_crm);
// var gauge = new Gauge(document.getElementById("gauge"));
// gauge.value(percentage_crm);
// },
funnel_chart: function () {
rpc.query({
@ -1374,136 +1360,136 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
});
},
onclick_sub_lost_last_12months: function(ev) {
var self = this;
if( self.is_manager == true){
self.initial_render = true;
rpc.query({
model: "crm.lead",
method: "get_total_lost_crm",
args: ['12']
}).then(function(result){
var ctx = document.getElementById('canvas_graph').getContext('2d');
// Define the data
var lost_reason = result.month; // Add data values to array
var count = result.count;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: lost_reason,//x axis
datasets: [{
label: 'Count', // Name the series
data: count, // Specify the data values array
backgroundColor: '#66aecf',
borderColor: '#66aecf',
barPercentage: 0.5,
barThickness: 6,
maxBarThickness: 8,
minBarLength: 0,
borderWidth: 1, // Specify bar border width
type: 'bar', // Set this data to a line chart
fill: false
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
},
responsive: true, // Instruct chart js to respond nicely.
maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
}
});
});
};
},
onclick_sub_lost_last_6months: function(ev) {
var self = this;
self.initial_render = true;
rpc.query({
model: "crm.lead",
method: "get_total_lost_crm",
args: ['6']
}).then(function(result){
var ctx = document.getElementById("canvas_graph").getContext('2d');
// Define the data
var lost_reason = result.month // Add data values to array
var count = result.count;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: lost_reason,//x axis
datasets: [{
label: 'Count', // Name the series
data: count, // Specify the data values array
backgroundColor: '#66aecf',
borderColor: '#66aecf',
barPercentage: 0.5,
barThickness: 6,
maxBarThickness: 8,
minBarLength: 0,
borderWidth: 1, // Specify bar border width
type: 'bar', // Set this data to a line chart
fill: false
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
},
responsive: true, // Instruct chart js to respond nicely.
maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
}
});
});
},
onclick_sub_lost_last_month: function(ev) {
var self = this;
self.initial_render = true;
rpc.query({
model: "crm.lead",
method: "get_total_lost_crm",
args: ['1']
}).then(function(result){
var ctx = document.getElementById("canvas_graph").getContext('2d');
// Define the data
var lost_reason = result.month // Add data values to array
var count = result.count;
var myChart = new Chart(ctx, {
type: 'bar',
data: {
labels: lost_reason,//x axis
datasets: [{
label: 'Count', // Name the series
data: count, // Specify the data values array
backgroundColor: '#66aecf',
borderColor: '#66aecf',
barPercentage: 0.5,
barThickness: 6,
maxBarThickness: 8,
minBarLength: 0,
borderWidth: 1, // Specify bar border width
type: 'bar', // Set this data to a line chart
fill: false
}]
},
options: {
scales: {
y: {
beginAtZero: true
}
},
responsive: true, // Instruct chart js to respond nicely.
maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
}
});
});
},
// onclick_sub_lost_last_12months: function(ev) {
// var self = this;
// if( self.is_manager == true){
// self.initial_render = true;
// rpc.query({
// model: "crm.lead",
// method: "get_total_lost_crm",
// args: ['12']
// }).then(function(result){
// var ctx = document.getElementById('canvas_graph').getContext('2d');
// // Define the data
// var lost_reason = result.month; // Add data values to array
// var count = result.count;
// var myChart = new Chart(ctx, {
// type: 'bar',
// data: {
// labels: lost_reason,//x axis
// datasets: [{
// label: 'Count', // Name the series
// data: count, // Specify the data values array
// backgroundColor: '#66aecf',
// borderColor: '#66aecf',
// barPercentage: 0.5,
// barThickness: 6,
// maxBarThickness: 8,
// minBarLength: 0,
// borderWidth: 1, // Specify bar border width
// type: 'bar', // Set this data to a line chart
// fill: false
// }]
// },
// options: {
// scales: {
// y: {
// beginAtZero: true
// }
// },
// responsive: true, // Instruct chart js to respond nicely.
// maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
// }
// });
// });
// };
// },
//
// onclick_sub_lost_last_6months: function(ev) {
// var self = this;
// self.initial_render = true;
// rpc.query({
// model: "crm.lead",
// method: "get_total_lost_crm",
// args: ['6']
// }).then(function(result){
// var ctx = document.getElementById("canvas_graph").getContext('2d');
// // Define the data
// var lost_reason = result.month // Add data values to array
// var count = result.count;
// var myChart = new Chart(ctx, {
// type: 'bar',
// data: {
// labels: lost_reason,//x axis
// datasets: [{
// label: 'Count', // Name the series
// data: count, // Specify the data values array
// backgroundColor: '#66aecf',
// borderColor: '#66aecf',
// barPercentage: 0.5,
// barThickness: 6,
// maxBarThickness: 8,
// minBarLength: 0,
// borderWidth: 1, // Specify bar border width
// type: 'bar', // Set this data to a line chart
// fill: false
// }]
// },
// options: {
// scales: {
// y: {
// beginAtZero: true
// }
// },
// responsive: true, // Instruct chart js to respond nicely.
// maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
// }
// });
// });
// },
//
// onclick_sub_lost_last_month: function(ev) {
// var self = this;
// self.initial_render = true;
// rpc.query({
// model: "crm.lead",
// method: "get_total_lost_crm",
// args: ['1']
// }).then(function(result){
// var ctx = document.getElementById("canvas_graph").getContext('2d');
// // Define the data
// var lost_reason = result.month // Add data values to array
// var count = result.count;
// var myChart = new Chart(ctx, {
// type: 'bar',
// data: {
// labels: lost_reason,//x axis
// datasets: [{
// label: 'Count', // Name the series
// data: count, // Specify the data values array
// backgroundColor: '#66aecf',
// borderColor: '#66aecf',
// barPercentage: 0.5,
// barThickness: 6,
// maxBarThickness: 8,
// minBarLength: 0,
// borderWidth: 1, // Specify bar border width
// type: 'bar', // Set this data to a line chart
// fill: false
// }]
// },
// options: {
// scales: {
// y: {
// beginAtZero: true
// }
// },
// responsive: true, // Instruct chart js to respond nicely.
// maintainAspectRatio: false, // Add to prevent default behaviour of full-width/height
// }
// });
// });
// },
fetch_data: function() {
var self = this;
@ -1568,13 +1554,13 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
self.top_country_count = res['country_count'];
});
var def7 = self._rpc({
model: "crm.lead",
method: "get_lost_reason_count",
})
.then(function (res) {
self.top_reason_count = res['reason_count'];
});
// var def7 = self._rpc({
// model: "crm.lead",
// method: "get_lost_reason_count",
// })
// .then(function (res) {
// self.top_reason_count = res['reason_count'];
// });
var def8 = self._rpc({
model: "crm.lead",
@ -1624,7 +1610,8 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
self.top_sp_by_invoice = res['sales_person_invoice'];
});
return $.when(def0, def1, def2, def3, def4, def5, def6, def7, def8, def9, def10, def11, def12, def13);
// return $.when(def0, def1, def2, def3, def4, def5, def6, def7, def8, def9, def10, def11, def12, def13);
return $.when(def0, def1, def2, def3, def4, def5, def6, def8, def9, def10, def11, def12, def13);
},
render_dashboards: function() {
@ -1632,7 +1619,8 @@ odoo.define('crm_dashboard.CRMDashboard', function (require) {
if (this.login_employee){
var templates = []
if( self.is_manager == true){
templates = ['LoginUser', 'Managercrm', 'Admincrm', 'SubDashboard'];
// templates = ['LoginUser', 'Managercrm', 'Admincrm', 'SubDashboard'];
templates = ['LoginUser', 'Managercrm', 'Admincrm'];
}
else{
templates = ['LoginUser','Managercrm'];

24
crm_dashboard/static/src/xml/dashboard_view.xml

@ -349,12 +349,6 @@
</span>
</div>
</div>
<script>
percentage_crm = document.getElementById("percentage_crm");
var gauge = new Gauge(document.getElementById("gauge"));
gauge.value(percentage_crm.value);
console.log("month");
</script>
</div>
<div class="leads_campaign_pie_div half_chart chart-container card-shadow">
<h3 class="h5">Leads group by Campaign</h3>
@ -405,12 +399,6 @@
</tbody>
</table>
</div>
<script>
$('#salesperson_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
</script>
</div>
<div class="top_country_revenue_div col-12 col-sm-12 col-md-4">
@ -434,12 +422,6 @@
</tbody>
</table>
</div>
<script>
$('#country_revenue_table').columnHeatmap({
columns: [1],
inverse:true,
});
</script>
</div>
<div class="top_country_count_div col-12 col-sm-12 col-md-4">
@ -463,12 +445,6 @@
</tbody>
</table>
</div>
<script>
$('#country_count_table').columnHeatmap({
columns: [1],
inverse:true,
});
</script>
</div>
</div>

Loading…
Cancel
Save