[fix] #11880- Item wise report showing price list and stock available (#11885)
* [fix] #11880 * review comments * codacy fixes
This commit is contained in:
parent
34ed1df9ef
commit
bb7fab52d1
@ -56,7 +56,12 @@ def get_data():
|
|||||||
"name": "Stock Ageing",
|
"name": "Stock Ageing",
|
||||||
"doctype": "Item",
|
"doctype": "Item",
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"type": "report",
|
||||||
|
"is_query_report": True,
|
||||||
|
"name": "Item Price Stock",
|
||||||
|
"doctype": "Item",
|
||||||
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
0
erpnext/stock/report/item_price_stock/__init__.py
Normal file
0
erpnext/stock/report/item_price_stock/__init__.py
Normal file
14
erpnext/stock/report/item_price_stock/item_price_stock.js
Normal file
14
erpnext/stock/report/item_price_stock/item_price_stock.js
Normal file
@ -0,0 +1,14 @@
|
|||||||
|
// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
|
||||||
|
// For license information, please see license.txt
|
||||||
|
/* eslint-disable */
|
||||||
|
|
||||||
|
frappe.query_reports["Item Price Stock"] = {
|
||||||
|
"filters": [
|
||||||
|
{
|
||||||
|
"fieldname":"item_code",
|
||||||
|
"label": __("Item"),
|
||||||
|
"fieldtype": "Link",
|
||||||
|
"options": "Item"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
44
erpnext/stock/report/item_price_stock/item_price_stock.json
Normal file
44
erpnext/stock/report/item_price_stock/item_price_stock.json
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
{
|
||||||
|
"add_total_row": 0,
|
||||||
|
"apply_user_permissions": 1,
|
||||||
|
"creation": "2017-12-06 17:01:48.727970",
|
||||||
|
"disabled": 0,
|
||||||
|
"docstatus": 0,
|
||||||
|
"doctype": "Report",
|
||||||
|
"idx": 0,
|
||||||
|
"is_standard": "Yes",
|
||||||
|
"modified": "2017-12-06 17:01:48.727970",
|
||||||
|
"modified_by": "Administrator",
|
||||||
|
"module": "Stock",
|
||||||
|
"name": "Item Price Stock",
|
||||||
|
"owner": "Administrator",
|
||||||
|
"ref_doctype": "Item",
|
||||||
|
"report_name": "Item Price Stock",
|
||||||
|
"report_type": "Script Report",
|
||||||
|
"roles": [
|
||||||
|
{
|
||||||
|
"role": "Item Manager"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Stock Manager"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Stock User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Sales User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Purchase User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Maintenance User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Accounts User"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"role": "Manufacturing User"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
95
erpnext/stock/report/item_price_stock/item_price_stock.py
Normal file
95
erpnext/stock/report/item_price_stock/item_price_stock.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
# 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):
|
||||||
|
columns, data = [], []
|
||||||
|
columns=get_columns()
|
||||||
|
data=get_data(filters,columns)
|
||||||
|
return columns, data
|
||||||
|
|
||||||
|
def get_columns():
|
||||||
|
return [
|
||||||
|
_("Item Name") + ":Link/Item:150",
|
||||||
|
_("Warehouse") + ":Link/Warehouse:130",
|
||||||
|
_("Stock Available") + ":Float:120",
|
||||||
|
_("Buying Price List") + ":Data:130",
|
||||||
|
_("Buying Rate") + ":Currency:110",
|
||||||
|
_("Selling Price List") + ":Data:130",
|
||||||
|
_("Selling Rate") + ":Currency:110"
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_data(filters, columns):
|
||||||
|
item_price_qty_data = []
|
||||||
|
item_price_qty_data = get_item_price_qty_data(filters)
|
||||||
|
return item_price_qty_data
|
||||||
|
|
||||||
|
def get_item_price_qty_data(filters):
|
||||||
|
item_dicts = []
|
||||||
|
conditions = ""
|
||||||
|
if filters.get("item_code"):
|
||||||
|
conditions += "where a.item_code=%(item_code)s"
|
||||||
|
|
||||||
|
item_results = frappe.db.sql("""select a.item_code as name,a.name as price_list_name,
|
||||||
|
b.warehouse as warehouse,b.actual_qty as actual_qty
|
||||||
|
from `tabItem Price` a left join `tabBin` b
|
||||||
|
ON a.item_code = b.item_code
|
||||||
|
{conditions}"""
|
||||||
|
.format(conditions=conditions),filters,as_dict=1)
|
||||||
|
|
||||||
|
price_list_names = ",".join(['"' + item['price_list_name'] + '"' for item in item_results])
|
||||||
|
|
||||||
|
buying_price_map = get_buying_price_map(price_list_names)
|
||||||
|
selling_price_map = get_selling_price_map(price_list_names)
|
||||||
|
|
||||||
|
item_dicts = [{"Item Name": d['name'],"Item Price List": d['price_list_name'],"Warehouse": d['warehouse'],
|
||||||
|
"Stock Available": d['actual_qty']} for d in item_results]
|
||||||
|
for item_dict in item_dicts:
|
||||||
|
price_list = item_dict["Item Price List"]
|
||||||
|
item_dict["Warehouse"] = item_dict["Warehouse"] or ""
|
||||||
|
item_dict["Stock Available"] = item_dict["Stock Available"] or 0
|
||||||
|
if buying_price_map.get(price_list):
|
||||||
|
item_dict["Buying Price List"] = buying_price_map.get(price_list)["Buying Price List"] or ""
|
||||||
|
item_dict["Buying Rate"] = buying_price_map.get(price_list)["Buying Rate"] or 0
|
||||||
|
if selling_price_map.get(price_list):
|
||||||
|
item_dict["Selling Price List"] = selling_price_map.get(price_list)["Selling Price List"] or ""
|
||||||
|
item_dict["Selling Rate"] = selling_price_map.get(price_list)["Selling Rate"] or 0
|
||||||
|
return item_dicts
|
||||||
|
|
||||||
|
def get_buying_price_map(price_list_names):
|
||||||
|
buying_price = frappe.db.sql("""
|
||||||
|
select
|
||||||
|
name,price_list,price_list_rate
|
||||||
|
from
|
||||||
|
`tabItem Price`
|
||||||
|
where
|
||||||
|
name in ({price_list_names}) and buying=1
|
||||||
|
""".format(price_list_names=price_list_names),as_dict=1)
|
||||||
|
buying_price_map = {}
|
||||||
|
for d in buying_price:
|
||||||
|
name = d["name"]
|
||||||
|
buying_price_map[name] = {
|
||||||
|
"Buying Price List" :d["price_list"],
|
||||||
|
"Buying Rate" :d["price_list_rate"]
|
||||||
|
}
|
||||||
|
return buying_price_map
|
||||||
|
|
||||||
|
def get_selling_price_map(price_list_names):
|
||||||
|
selling_price = frappe.db.sql("""
|
||||||
|
select
|
||||||
|
name,price_list,price_list_rate
|
||||||
|
from
|
||||||
|
`tabItem Price`
|
||||||
|
where
|
||||||
|
name in ({price_list_names}) and selling=1
|
||||||
|
""".format(price_list_names=price_list_names),as_dict=1)
|
||||||
|
selling_price_map = {}
|
||||||
|
for d in selling_price:
|
||||||
|
name = d["name"]
|
||||||
|
selling_price_map[name] = {
|
||||||
|
"Selling Price List" :d["price_list"],
|
||||||
|
"Selling Rate" :d["price_list_rate"]
|
||||||
|
}
|
||||||
|
return selling_price_map
|
Loading…
x
Reference in New Issue
Block a user