[report] item-wise consumption in buying module
This commit is contained in:
parent
dacdc8d855
commit
4fb848d3c4
@ -155,6 +155,11 @@ wn.module_page["Buying"] = [
|
||||
route: "query-report/Supplier Addresses and Contacts",
|
||||
doctype: "Supplier"
|
||||
},
|
||||
{
|
||||
"label":wn._("Item-Wise Consumption"),
|
||||
route: "query-report/Item-wise Consumption",
|
||||
doctype: "Stock Ledger Entry"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
|
0
stock/report/item_wise_consumption/__init__.py
Normal file
0
stock/report/item_wise_consumption/__init__.py
Normal file
28
stock/report/item_wise_consumption/item_wise_consumption.js
Normal file
28
stock/report/item_wise_consumption/item_wise_consumption.js
Normal file
@ -0,0 +1,28 @@
|
||||
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
// License: GNU General Public License v3. See license.txt
|
||||
|
||||
wn.query_reports["Item-wise Consumption"] = {
|
||||
"filters": [
|
||||
{
|
||||
"fieldname":"supplier",
|
||||
"label": wn._("Supplier"),
|
||||
"fieldtype": "Link",
|
||||
"options": "Supplier",
|
||||
"width": "80"
|
||||
},
|
||||
{
|
||||
"fieldname":"from_date",
|
||||
"label": wn._("From Date"),
|
||||
"fieldtype": "Date",
|
||||
"width": "80",
|
||||
"default": wn.datetime.month_start()
|
||||
},
|
||||
{
|
||||
"fieldname":"to_date",
|
||||
"label": wn._("To Date"),
|
||||
"fieldtype": "Date",
|
||||
"width": "80",
|
||||
"default": wn.datetime.month_end()
|
||||
},
|
||||
]
|
||||
}
|
81
stock/report/item_wise_consumption/item_wise_consumption.py
Normal file
81
stock/report/item_wise_consumption/item_wise_consumption.py
Normal file
@ -0,0 +1,81 @@
|
||||
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
||||
# License: GNU General Public License v3. See license.txt
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import webnotes
|
||||
from webnotes.utils import flt
|
||||
|
||||
def execute(filters=None):
|
||||
columns = get_columns(filters)
|
||||
consumed_details = get_consumed_details(filters)
|
||||
supplier_details = get_suppliers_details(filters)
|
||||
material_transfer_vouchers = get_material_transfer_vouchers()
|
||||
data = []
|
||||
|
||||
for item_code, suppliers in supplier_details.items():
|
||||
consumed_qty = consumed_amount = 0.0
|
||||
if consumed_details.get(item_code):
|
||||
for cd in consumed_details.get(item_code):
|
||||
if cd.voucher_no not in material_transfer_vouchers:
|
||||
consumed_qty += abs(flt(cd.actual_qty))
|
||||
consumed_amount += abs(flt(cd.stock_value_difference))
|
||||
if consumed_qty or consumed_amount:
|
||||
row = [cd.item_code, cd.item_name, cd.description, cd.stock_uom, \
|
||||
consumed_qty, consumed_amount, list(set(suppliers))]
|
||||
data.append(row)
|
||||
|
||||
return columns, data
|
||||
|
||||
def get_columns(filters):
|
||||
"""return columns based on filters"""
|
||||
|
||||
columns = ["Item:Link/Item:100"] + ["Item Name::150"] + ["Description::150"] + \
|
||||
["UOM:Link/UOM:100"] + ["Consumed Qty:Float:130"] + ["Consumed Amount:Currency:130"] + \
|
||||
["Supplier(s)::250"]
|
||||
|
||||
return columns
|
||||
|
||||
def get_conditions(filters):
|
||||
conditions = ""
|
||||
values = []
|
||||
|
||||
if filters.get('from_date') and filters.get('to_date'):
|
||||
conditions = "and sle.posting_date>=%s and sle.posting_date<=%s"
|
||||
values = [filters.get('from_date'), filters.get('to_date')]
|
||||
|
||||
return conditions, values
|
||||
|
||||
def get_consumed_details(filters):
|
||||
conditions, values = get_conditions(filters)
|
||||
consumed_details = {}
|
||||
|
||||
for d in webnotes.conn.sql("""select sle.item_code, i.item_name, i.description,
|
||||
i.stock_uom, sle.actual_qty, sle.stock_value_difference, sle.voucher_no
|
||||
from `tabStock Ledger Entry` sle, `tabItem` i
|
||||
where sle.item_code=i.name and sle.actual_qty < 0 %s""" % conditions, values, as_dict=1, debug=1):
|
||||
consumed_details.setdefault(d.item_code, []).append(d)
|
||||
|
||||
return consumed_details
|
||||
|
||||
def get_suppliers_details(filters):
|
||||
item_supplier_map = {}
|
||||
conditions = ""
|
||||
values = []
|
||||
|
||||
if (filters.get('supplier')):
|
||||
conditions = "and pr.supplier=%s"
|
||||
values = [filters.get('supplier')]
|
||||
|
||||
for d in webnotes.conn.sql("""select pr.supplier, pri.item_code from
|
||||
`tabPurchase Receipt` pr, `tabPurchase Receipt Item` pri
|
||||
where pr.name=pri.parent and pr.docstatus=1 and
|
||||
pri.item_code=(select name from `tabItem` where
|
||||
ifnull(is_stock_item, 'Yes')='Yes' and name=pri.item_code) %s""" % conditions,
|
||||
values, as_dict=1):
|
||||
item_supplier_map.setdefault(d.item_code, []).append(d.supplier)
|
||||
|
||||
return item_supplier_map
|
||||
|
||||
def get_material_transfer_vouchers():
|
||||
return webnotes.conn.sql_list("""select name from `tabStock Entry` where
|
||||
purpose='Material Transfer' and docstatus=1""")
|
22
stock/report/item_wise_consumption/item_wise_consumption.txt
Normal file
22
stock/report/item_wise_consumption/item_wise_consumption.txt
Normal file
@ -0,0 +1,22 @@
|
||||
[
|
||||
{
|
||||
"creation": "2013-11-29 10:58:23",
|
||||
"docstatus": 0,
|
||||
"modified": "2013-11-29 12:26:49",
|
||||
"modified_by": "Administrator",
|
||||
"owner": "Administrator"
|
||||
},
|
||||
{
|
||||
"add_total_row": 1,
|
||||
"doctype": "Report",
|
||||
"is_standard": "Yes",
|
||||
"name": "__common__",
|
||||
"ref_doctype": "Stock Ledger Entry",
|
||||
"report_name": "Item-wise Consumption",
|
||||
"report_type": "Script Report"
|
||||
},
|
||||
{
|
||||
"doctype": "Report",
|
||||
"name": "Item-wise Consumption"
|
||||
}
|
||||
]
|
Loading…
x
Reference in New Issue
Block a user