chore: Added Dynamic Charts to DN and PR Trends Reports

This commit is contained in:
marination 2020-05-15 01:33:43 +05:30
parent 10bd2417ff
commit bb95cd5fd8
5 changed files with 67 additions and 6 deletions

View File

@ -51,7 +51,10 @@ erpnext.get_purchase_trends_filters = function() {
{ "value": "Supplier Group", "label": __("Supplier Group") }, { "value": "Supplier Group", "label": __("Supplier Group") },
{ "value": "Project", "label": __("Project") } { "value": "Project", "label": __("Project") }
], ],
"default": "Item" "default": "Item",
"dashboard_config": {
"read_only": 1,
}
}, },
{ {
"fieldname":"group_by", "fieldname":"group_by",

View File

@ -27,7 +27,10 @@ erpnext.get_sales_trends_filters = function() {
{ "value": "Territory", "label": __("Territory") }, { "value": "Territory", "label": __("Territory") },
{ "value": "Project", "label": __("Project") } { "value": "Project", "label": __("Project") }
], ],
"default": "Item" "default": "Item",
"dashboard_config": {
"read_only": 1,
}
}, },
{ {
"fieldname":"group_by", "fieldname":"group_by",

View File

@ -10,7 +10,7 @@ from erpnext.stock.utils import get_stock_value_from_bin
@frappe.whitelist() @frappe.whitelist()
@cache_source @cache_source
def get(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None, def get(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None,
to_date = None, timespan = None, time_interval = None): to_date = None, timespan = None, time_interval = None, heatmap_year = None):
labels, datapoints = [], [] labels, datapoints = [], []
filters = frappe.parse_json(filters) filters = frappe.parse_json(filters)

View File

@ -3,6 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _
from erpnext.controllers.trends import get_columns,get_data from erpnext.controllers.trends import get_columns,get_data
def execute(filters=None): def execute(filters=None):
@ -10,5 +11,31 @@ def execute(filters=None):
data = [] data = []
conditions = get_columns(filters, "Delivery Note") conditions = get_columns(filters, "Delivery Note")
data = get_data(filters, conditions) data = get_data(filters, conditions)
return conditions["columns"], data chart_data = get_chart_data(data)
return conditions["columns"], data, None, chart_data
def get_chart_data(data):
labels, datapoints = [], []
if len(data) > 10:
data = sorted(data, key = lambda i: i[-1],reverse=True)
data = data[:10]
for row in data:
labels.append(row[0])
datapoints.append(row[-1])
return {
"data": {
"labels" : labels,
"datasets" : [
{
"name": _("Total Revenue"),
"values": datapoints
}
]
},
"type" : "bar"
}

View File

@ -3,6 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import frappe import frappe
from frappe import _
from erpnext.controllers.trends import get_columns,get_data from erpnext.controllers.trends import get_columns,get_data
def execute(filters=None): def execute(filters=None):
@ -11,4 +12,31 @@ def execute(filters=None):
conditions = get_columns(filters, "Purchase Receipt") conditions = get_columns(filters, "Purchase Receipt")
data = get_data(filters, conditions) data = get_data(filters, conditions)
return conditions["columns"], data chart_data = get_chart_data(data)
return conditions["columns"], data, None, chart_data
def get_chart_data(data):
labels, datapoints = [], []
if len(data) > 10:
data = sorted(data, key = lambda i: i[-1],reverse=True)
data = data[:10]
for row in data:
labels.append(row[0])
datapoints.append(row[-1])
return {
"data": {
"labels" : labels,
"datasets" : [
{
"name": _("Total Expenditure"),
"values": datapoints
}
]
},
"type" : "bar",
"colors":["#5e64ff"]
}