From 10562b67fc4c90fc4b7d579220dda17d0e3fcb3b Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Tue, 25 Jun 2019 17:07:41 +0530 Subject: [PATCH 1/2] fix(sales-funnel): Use frappe.Chart() instead of Chart() --- erpnext/selling/page/sales_funnel/sales_funnel.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js index f2e972adf8..6a98da8a5d 100644 --- a/erpnext/selling/page/sales_funnel/sales_funnel.js +++ b/erpnext/selling/page/sales_funnel/sales_funnel.js @@ -277,7 +277,7 @@ erpnext.SalesFunnel = class SalesFunnel { let chart_data = me.options.data ? me.options.data : null; const parent = me.elements.funnel_wrapper[0]; - this.chart = new Chart(parent, { + this.chart = new frappe.Chart(parent, { title: __("Sales Opportunities by Source"), height: 400, data: chart_data, @@ -298,7 +298,7 @@ erpnext.SalesFunnel = class SalesFunnel { let chart_data = me.options.data ? me.options.data : null; const parent = me.elements.funnel_wrapper[0]; - this.chart = new Chart(parent, { + this.chart = new frappe.Chart(parent, { title: __("Sales Pipeline by Stage"), height: 400, data: chart_data, From 2caaa1b03dffe85299389d3ee59fb7300f385647 Mon Sep 17 00:00:00 2001 From: Aditya Hase Date: Tue, 25 Jun 2019 17:17:38 +0530 Subject: [PATCH 2/2] fix(sales-funnel): Remove duplicate code --- .../selling/page/sales_funnel/sales_funnel.js | 112 +++++------------- 1 file changed, 27 insertions(+), 85 deletions(-) diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.js b/erpnext/selling/page/sales_funnel/sales_funnel.js index 6a98da8a5d..85c0cd8bf0 100644 --- a/erpnext/selling/page/sales_funnel/sales_funnel.js +++ b/erpnext/selling/page/sales_funnel/sales_funnel.js @@ -90,70 +90,31 @@ erpnext.SalesFunnel = class SalesFunnel { get_data(btn) { var me = this; - if (me.options.chart == 'sales_funnel'){ - frappe.call({ - method: "erpnext.selling.page.sales_funnel.sales_funnel.get_funnel_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_funnel(); - } + const method_map = { + "sales_funnel": "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", + "sales_pipeline": "erpnext.selling.page.sales_funnel.sales_funnel.get_pipeline_data" + }; + frappe.call({ + method: method_map[this.options.chart], + 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(); } } - }); - } 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() { @@ -161,9 +122,9 @@ erpnext.SalesFunnel = class SalesFunnel { if (me.options.chart == 'sales_funnel'){ me.render_funnel(); } 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'){ - me.render_pipeline(); + me.render_chart("Sales Pipeline by Stage"); } } @@ -270,7 +231,7 @@ erpnext.SalesFunnel = class SalesFunnel { context.fillText(__(title), width + 20, y_mid); } - render_opp_by_lead_source() { + render_chart(title) { let me = this; let currency = frappe.defaults.get_default("currency"); @@ -278,7 +239,7 @@ erpnext.SalesFunnel = class SalesFunnel { const parent = me.elements.funnel_wrapper[0]; this.chart = new frappe.Chart(parent, { - title: __("Sales Opportunities by Source"), + title: title, height: 400, data: chart_data, 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 frappe.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'] - }); - } };