From 657f8a667737e8a693db113f744a463c6e56e933 Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Thu, 6 Jun 2013 18:33:26 +0530 Subject: [PATCH 1/2] Completed 'Item Prices' Report --- stock/page/stock_home/stock_home.js | 4 + stock/report/item_prices/__init__.py | 0 stock/report/item_prices/item_prices.js | 3 + stock/report/item_prices/item_prices.py | 106 +++++++++++++++++++++++ stock/report/item_prices/item_prices.txt | 21 +++++ 5 files changed, 134 insertions(+) create mode 100644 stock/report/item_prices/__init__.py create mode 100644 stock/report/item_prices/item_prices.js create mode 100644 stock/report/item_prices/item_prices.py create mode 100644 stock/report/item_prices/item_prices.txt diff --git a/stock/page/stock_home/stock_home.js b/stock/page/stock_home/stock_home.js index bc71a4faf5..bd28b94291 100644 --- a/stock/page/stock_home/stock_home.js +++ b/stock/page/stock_home/stock_home.js @@ -213,6 +213,10 @@ wn.module_page["Stock"] = [ "label":wn._("Warehouse-Wise Stock Balance"), route: "query-report/Warehouse-Wise Stock Balance", }, + { + "label":wn._("Item Prices"), + route: "query-report/Item Prices", + }, ] } ] diff --git a/stock/report/item_prices/__init__.py b/stock/report/item_prices/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/stock/report/item_prices/item_prices.js b/stock/report/item_prices/item_prices.js new file mode 100644 index 0000000000..3dfa7cad33 --- /dev/null +++ b/stock/report/item_prices/item_prices.js @@ -0,0 +1,3 @@ +wn.query_reports["Item Prices"] = { + "filters": [] +} \ No newline at end of file diff --git a/stock/report/item_prices/item_prices.py b/stock/report/item_prices/item_prices.py new file mode 100644 index 0000000000..ea0be477df --- /dev/null +++ b/stock/report/item_prices/item_prices.py @@ -0,0 +1,106 @@ +# ERPNext - web based ERP (http://erpnext.com) +# Copyright (C) 2012 Web Notes Technologies Pvt Ltd +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +from __future__ import unicode_literals +import webnotes +from webnotes.utils import flt + +def execute(filters=None): + if not filters: filters = {} + + columns = get_columns(filters) + item_map = get_item_details() + pl = get_price_list() + bom_rate = get_item_bom_rate() + val_rate_map = get_valuation_rate() + + data = [] + for item in sorted(item_map): + data.append([item, item_map[item]["item_name"], + item_map[item]["description"], item_map[item]["stock_uom"], + flt(item_map[item]["last_purchase_rate"]), val_rate_map.get(item, 0), + pl.get(item, {}).get("selling"), pl.get(item, {}).get("buying"), + bom_rate.get(item, 0), flt(item_map[item]["standard_rate"]) + ]) + + 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:80", + "Last Purchase Rate:Currency:90", "Valuation Rate:Currency:80", "Sales Price List::80", + "Purchase Price List::80", "BOM Rate:Currency:90", "Standard Rate:Currency:100"] + + return columns + +def get_item_details(): + """returns all items details""" + + item_map = {} + + for i in webnotes.conn.sql("select name, item_name, description, \ + stock_uom, standard_rate, last_purchase_rate from tabItem \ + order by item_code", as_dict=1): + item_map.setdefault(i.name, i) + + return item_map + +def get_price_list(): + """Get selling & buying price list of every item""" + + rate = {} + + price_list = webnotes.conn.sql("""select parent, selling, buying, + concat(price_list_name, " - ", ref_currency, " ", ref_rate) as price + from `tabItem Price` where docstatus<2""", as_dict=1) + + for j in price_list: + if j.selling: + rate.setdefault(j.parent, {}).setdefault("selling", []).append(j.price) + if j.buying: + rate.setdefault(j.parent, {}).setdefault("buying", []).append(j.price) + + item_rate_map = {} + + for item in rate: + item_rate_map.setdefault(item, {}).setdefault("selling", + ", ".join(rate[item].get("selling", []))) + item_rate_map[item]["buying"] = ", ".join(rate[item].get("buying", [])) + + return item_rate_map + +def get_item_bom_rate(): + """Get BOM rate of an item from BOM""" + + bom_map = {} + + for b in webnotes.conn.sql("""select item, (total_cost/quantity) as bom_rate + from `tabBOM` where is_active=1 and is_default=1""", as_dict=1): + bom_map.setdefault(b.item, flt(b.bom_rate)) + + return bom_map + +def get_valuation_rate(): + """Get an average valuation rate of an item from all warehouses""" + + val_rate_map = {} + + for d in webnotes.conn.sql("""select item_code, avg(valuation_rate) as val_rate + from tabBin group by item_code""", as_dict=1): + val_rate_map.setdefault(d.item_code, d.val_rate) + + return val_rate_map \ No newline at end of file diff --git a/stock/report/item_prices/item_prices.txt b/stock/report/item_prices/item_prices.txt new file mode 100644 index 0000000000..4c49ca1748 --- /dev/null +++ b/stock/report/item_prices/item_prices.txt @@ -0,0 +1,21 @@ +[ + { + "creation": "2013-06-05 11:43:30", + "docstatus": 0, + "modified": "2013-06-05 11:43:30", + "modified_by": "Administrator", + "owner": "Administrator" + }, + { + "doctype": "Report", + "is_standard": "Yes", + "name": "__common__", + "ref_doctype": "Stock Ledger Entry", + "report_name": "Item Prices", + "report_type": "Script Report" + }, + { + "doctype": "Report", + "name": "Item Prices" + } +] \ No newline at end of file From 426b57e1b41feb6f273838097e35e524907364ac Mon Sep 17 00:00:00 2001 From: Akhilesh Darjee Date: Fri, 7 Jun 2013 11:52:15 +0530 Subject: [PATCH 2/2] Deleted item_prices.js --- stock/report/item_prices/item_prices.js | 3 --- 1 file changed, 3 deletions(-) delete mode 100644 stock/report/item_prices/item_prices.js diff --git a/stock/report/item_prices/item_prices.js b/stock/report/item_prices/item_prices.js deleted file mode 100644 index 3dfa7cad33..0000000000 --- a/stock/report/item_prices/item_prices.js +++ /dev/null @@ -1,3 +0,0 @@ -wn.query_reports["Item Prices"] = { - "filters": [] -} \ No newline at end of file