Merge pull request #18060 from adityahase/fix-sales-funnel

fix(sales-funnel): Use frappe.Chart() instead of Chart()
This commit is contained in:
rohitwaghchaure 2019-06-25 21:36:26 +05:30 committed by GitHub
commit b98e825ceb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -90,70 +90,31 @@ erpnext.SalesFunnel = class SalesFunnel {
get_data(btn) { get_data(btn) {
var me = this; var me = this;
if (me.options.chart == 'sales_funnel'){ const method_map = {
frappe.call({ "sales_funnel": "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data",
method: "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_data", "opp_by_lead_source": "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source",
args: { "sales_pipeline": "erpnext.selling.page.sales_funnel.sales_funnel.get_pipeline_data"
from_date: this.options.from_date, };
to_date: this.options.to_date, frappe.call({
company: this.company method: method_map[this.options.chart],
}, args: {
btn: btn, from_date: this.options.from_date,
callback: function(r) { to_date: this.options.to_date,
if(!r.exc) { company: this.company
me.options.data = r.message; },
if (me.options.data=='empty') { btn: btn,
const $parent = me.elements.funnel_wrapper; callback: function(r) {
$parent.html(__('No data for this period')); if(!r.exc) {
} else { me.options.data = r.message;
me.render_funnel(); if (me.options.data=='empty') {
} const $parent = me.elements.funnel_wrapper;
$parent.html(__('No data for this period'));
} else {
me.render();
} }
} }
}); }
} else if (me.options.chart == 'opp_by_lead_source'){ });
frappe.call({
method: "erpnext.selling.page.sales_funnel.sales_funnel.get_opp_by_lead_source",
args: {
from_date: this.options.from_date,
to_date: this.options.to_date,
company: this.company
},
btn: btn,
callback: function(r) {
if(!r.exc) {
me.options.data = r.message;
if (me.options.data=='empty') {
const $parent = me.elements.funnel_wrapper;
$parent.html(__('No data for this period'));
} else {
me.render_opp_by_lead_source();
}
}
}
});
} else if (me.options.chart == 'sales_pipeline'){
frappe.call({
method: "erpnext.selling.page.sales_funnel.sales_funnel.get_pipeline_data",
args: {
from_date: this.options.from_date,
to_date: this.options.to_date,
company: this.company
},
btn: btn,
callback: function(r) {
if(!r.exc) {
me.options.data = r.message;
if (me.options.data=='empty') {
const $parent = me.elements.funnel_wrapper;
$parent.html(__('No data for this period'));
} else {
me.render_pipeline();
}
}
}
});
}
} }
render() { render() {
@ -161,9 +122,9 @@ erpnext.SalesFunnel = class SalesFunnel {
if (me.options.chart == 'sales_funnel'){ if (me.options.chart == 'sales_funnel'){
me.render_funnel(); me.render_funnel();
} else if (me.options.chart == 'opp_by_lead_source'){ } else if (me.options.chart == 'opp_by_lead_source'){
me.render_opp_by_lead_source(); me.render_chart("Sales Opportunities by Source");
} else if (me.options.chart == 'sales_pipeline'){ } else if (me.options.chart == 'sales_pipeline'){
me.render_pipeline(); me.render_chart("Sales Pipeline by Stage");
} }
} }
@ -270,15 +231,15 @@ erpnext.SalesFunnel = class SalesFunnel {
context.fillText(__(title), width + 20, y_mid); context.fillText(__(title), width + 20, y_mid);
} }
render_opp_by_lead_source() { render_chart(title) {
let me = this; let me = this;
let currency = frappe.defaults.get_default("currency"); let currency = frappe.defaults.get_default("currency");
let chart_data = me.options.data ? me.options.data : null; let chart_data = me.options.data ? me.options.data : null;
const parent = me.elements.funnel_wrapper[0]; const parent = me.elements.funnel_wrapper[0];
this.chart = new Chart(parent, { this.chart = new frappe.Chart(parent, {
title: __("Sales Opportunities by Source"), title: title,
height: 400, height: 400,
data: chart_data, data: chart_data,
type: 'bar', type: 'bar',
@ -290,23 +251,4 @@ erpnext.SalesFunnel = class SalesFunnel {
} }
}); });
} }
render_pipeline() {
let me = this;
let currency = frappe.defaults.get_default("currency");
let chart_data = me.options.data ? me.options.data : null;
const parent = me.elements.funnel_wrapper[0];
this.chart = new Chart(parent, {
title: __("Sales Pipeline by Stage"),
height: 400,
data: chart_data,
type: 'bar',
tooltipOptions: {
formatTooltipY: d => format_currency(d, currency),
},
colors: ['light-green', 'green']
});
}
}; };