Total Stock Summary (#9465)

* Total Stock Summary

* indentation fixes and removed the for loop

* minor fixes in total stock summery report
This commit is contained in:
Doridel Cahanap 2017-07-05 13:19:09 +08:00 committed by Makarand Bauskar
parent 3ceab64bfa
commit 5ad4a6e161
4 changed files with 116 additions and 0 deletions

View File

@ -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"
},
]
}

View File

@ -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"
}
]
}

View File

@ -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'"))