feat: Custom Dashboard 'Warehouse wise Stock Value' with Chart Source

This commit is contained in:
marination 2020-05-14 15:35:18 +05:30
parent 021acd0a01
commit 10bd2417ff
6 changed files with 71 additions and 2 deletions

View File

@ -0,0 +1,14 @@
frappe.provide('frappe.dashboards.chart_sources');
frappe.dashboards.chart_sources["Warehouse wise Stock Value"] = {
method: "erpnext.stock.dashboard_chart_source.warehouse_wise_stock_value.warehouse_wise_stock_value.get",
filters: [
{
fieldname: "company",
label: __("Company"),
fieldtype: "Link",
options: "Company",
default: frappe.defaults.get_user_default("Company")
}
]
};

View File

@ -0,0 +1,13 @@
{
"creation": "2020-05-14 14:27:44.108017",
"docstatus": 0,
"doctype": "Dashboard Chart Source",
"idx": 0,
"modified": "2020-05-14 14:27:44.108017",
"modified_by": "Administrator",
"module": "Stock",
"name": "Warehouse wise Stock Value",
"owner": "Administrator",
"source_name": "Warehouse wise Stock Value ",
"timeseries": 0
}

View File

@ -0,0 +1,44 @@
# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import frappe, json
from frappe import _
from frappe.utils.dashboard import cache_source
from erpnext.stock.utils import get_stock_value_from_bin
@frappe.whitelist()
@cache_source
def get(chart_name = None, chart = None, no_cache = None, filters = None, from_date = None,
to_date = None, timespan = None, time_interval = None):
labels, datapoints = [], []
filters = frappe.parse_json(filters)
warehouse_filters = [['is_group', '=', 0]]
if filters and filters.get("company"):
warehouse_filters.append(['company', '=', filters.get("company")])
warehouses = frappe.get_list("Warehouse", fields=['name'], filters=warehouse_filters, order_by='name')
for wh in warehouses:
balance = get_stock_value_from_bin(warehouse=wh.name)
wh["balance"] = balance[0][0]
warehouses = [x for x in warehouses if not (x.get('balance') == None)]
sorted_warehouse_map = sorted(warehouses, key = lambda i: i['balance'],reverse=True)
if len(sorted_warehouse_map) > 10:
sorted_warehouse_map = sorted_warehouse_map[:10]
for warehouse in sorted_warehouse_map:
labels.append(_(warehouse.get("name")))
datapoints.append(warehouse.get("balance"))
return{
"labels": labels,
"datasets": [{
"name": _("Stock Value"),
"values": datapoints
}],
"type": "bar"
}

View File

@ -246,8 +246,6 @@ def get_chart_data(data, filters):
labels.append(row[0])
datapoints.append(row[6])
print(labels)
print(datapoints)
return {
"data" : {
"labels": labels,