Total Stock Summary (#9465)
* Total Stock Summary
* indentation fixes and removed the for loop
* minor fixes in total stock summery report
diff --git a/erpnext/stock/report/total_stock_summary/__init__.py b/erpnext/stock/report/total_stock_summary/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/stock/report/total_stock_summary/__init__.py
diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.js b/erpnext/stock/report/total_stock_summary/total_stock_summary.js
new file mode 100644
index 0000000..223a603
--- /dev/null
+++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.js
@@ -0,0 +1,24 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+/* eslint-disable */
+
+frappe.query_reports["Total Stock Summary"] = {
+ "filters": [
+ {
+ "fieldname":"group_by",
+ "label": __("Group By"),
+ "fieldtype": "Select",
+ "width": "80",
+ "reqd": 1,
+ "options": ["","Warehouse", "Company"],
+ "default": "Warehouse"
+ },
+ {
+ "fieldname": "company",
+ "label": __("Company"),
+ "fieldtype": "Link",
+ "width": "80",
+ "options": "Company"
+ },
+ ]
+}
diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.json b/erpnext/stock/report/total_stock_summary/total_stock_summary.json
new file mode 100644
index 0000000..e675fe4
--- /dev/null
+++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.json
@@ -0,0 +1,32 @@
+{
+ "add_total_row": 0,
+ "apply_user_permissions": 1,
+ "creation": "2017-06-26 14:05:50.256693",
+ "disabled": 0,
+ "docstatus": 0,
+ "doctype": "Report",
+ "idx": 0,
+ "is_standard": "Yes",
+ "modified": "2017-06-26 14:05:50.256693",
+ "modified_by": "Administrator",
+ "module": "Stock",
+ "name": "Total Stock Summary",
+ "owner": "Administrator",
+ "ref_doctype": "Stock Entry",
+ "report_name": "Total Stock Summary",
+ "report_type": "Script Report",
+ "roles": [
+ {
+ "role": "Stock User"
+ },
+ {
+ "role": "Manufacturing User"
+ },
+ {
+ "role": "Manufacturing Manager"
+ },
+ {
+ "role": "Stock Manager"
+ }
+ ]
+}
\ No newline at end of file
diff --git a/erpnext/stock/report/total_stock_summary/total_stock_summary.py b/erpnext/stock/report/total_stock_summary/total_stock_summary.py
new file mode 100644
index 0000000..fafc169
--- /dev/null
+++ b/erpnext/stock/report/total_stock_summary/total_stock_summary.py
@@ -0,0 +1,60 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+
+def execute(filters=None):
+ if not filters: filters = {}
+ validate_filters(filters)
+ columns = get_columns()
+ stock = get_total_stock(filters)
+
+ return columns, stock
+
+def get_columns():
+ columns = [
+ _("Company") + ":Link/Item:250",
+ _("Warehouse") + ":Link/Item:150",
+ _("Item") + ":Link/Item:150",
+ _("Description") + "::300",
+ _("Current Qty") + ":Float:100",
+ ]
+
+ return columns
+
+def get_total_stock(filters):
+ conditions = ""
+ columns = ""
+
+ if filters.get("group_by") == "Warehouse":
+ if filters.get("company"):
+ conditions += " AND warehouse.company = '%s'" % frappe.db.escape(filters.get("company"), percent=False)
+
+ conditions += " GROUP BY ledger.warehouse, item.item_code"
+ columns += "'' as company, ledger.warehouse"
+ else:
+ conditions += " GROUP BY warehouse.company, item.item_code"
+ columns += " warehouse.company, '' as warehouse"
+
+ return frappe.db.sql("""
+ SELECT
+ %s,
+ item.item_code,
+ item.description,
+ sum(ledger.actual_qty) as actual_qty
+ FROM
+ `tabBin` AS ledger
+ INNER JOIN `tabItem` AS item
+ ON ledger.item_code = item.item_code
+ INNER JOIN `tabWarehouse` warehouse
+ ON warehouse.name = ledger.warehouse
+ WHERE
+ actual_qty != 0 %s""" % (columns, conditions))
+
+def validate_filters(filters):
+ if filters.get("group_by") == 'Company' and \
+ filters.get("company"):
+
+ frappe.throw(_("Please set Company filter blank if Group By is 'Company'"))