[removed merge conflict]

This commit is contained in:
Saurabh
2013-06-07 15:23:56 +05:30
30 changed files with 823 additions and 217 deletions

View File

@@ -506,17 +506,13 @@ class DocType(StockController):
if self.doc.use_multi_level_bom:
# get all raw materials with sub assembly childs
fl_bom_sa_child_item = sql("""select
item_code,ifnull(sum(qty_consumed_per_unit),0)*%s as qty,
description,stock_uom
from ( select distinct fb.name, fb.description, fb.item_code,
fb.qty_consumed_per_unit, fb.stock_uom
from `tabBOM Explosion Item` fb,`tabItem` it
where it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
and ifnull(it.is_sub_contracted_item, 'No') = 'No' and fb.docstatus<2
and fb.parent=%s
) a
group by item_code, stock_uom""" , (qty, self.doc.bom_no), as_dict=1)
fl_bom_sa_child_item = sql("""select fb.item_code,
ifnull(sum(fb.qty_consumed_per_unit),0)*%s as qty, fb.description, fb.stock_uom
from `tabBOM Explosion Item` fb,`tabItem` it
where it.name = fb.item_code and ifnull(it.is_pro_applicable, 'No') = 'No'
and ifnull(it.is_sub_contracted_item, 'No') = 'No' and fb.docstatus < 2
and fb.parent=%s group by item_code, stock_uom""",
(qty, self.doc.bom_no), as_dict=1)
if fl_bom_sa_child_item:
_make_items_dict(fl_bom_sa_child_item)
@@ -524,10 +520,10 @@ class DocType(StockController):
# Get all raw materials considering multi level BOM,
# if multi level bom consider childs of Sub-Assembly items
fl_bom_sa_items = sql("""select item_code,
ifnull(sum(qty_consumed_per_unit), 0) * '%s' as qty,
ifnull(sum(qty_consumed_per_unit), 0) *%s as qty,
description, stock_uom from `tabBOM Item`
where parent = '%s' and docstatus < 2
group by item_code""" % (qty, self.doc.bom_no), as_dict=1)
where parent = %s and docstatus < 2
group by item_code""", (qty, self.doc.bom_no), as_dict=1)
if fl_bom_sa_items:
_make_items_dict(fl_bom_sa_items)

View File

@@ -205,6 +205,19 @@ wn.module_page["Stock"] = [
"label":wn._("Requested Items To Be Transferred"),
route: "query-report/Requested Items To Be Transferred",
},
{
"label":wn._("Batch-Wise Balance History"),
route: "query-report/Batch-Wise Balance History",
},
{
"label":wn._("Warehouse-Wise Stock Balance"),
route: "query-report/Warehouse-Wise Stock Balance",
},
{
"label":wn._("Item Prices"),
route: "query-report/Item Prices",
},
{
"label":wn._("Itemwise Recommended Reorder Level"),
route: "query-report/Itemwise Recommended Reorder Level",

View File

@@ -0,0 +1,39 @@
wn.query_reports["Batch-Wise Balance History"] = {
"filters": [
{
"fieldname":"item_code",
"label": "Item",
"fieldtype": "Link",
"options": "Item",
"width": "80"
},
{
"fieldname":"warehouse",
"label": "Warehouse",
"fieldtype": "Link",
"options": "Warehouse",
"width": "80"
},
{
"fieldname":"batch_no",
"label": "Batch",
"fieldtype": "Link",
"options": "Batch",
"width": "80"
},
{
"fieldname":"from_date",
"label": "From Date",
"fieldtype": "Date",
"width": "80",
"default": sys_defaults.year_start_date,
},
{
"fieldname":"to_date",
"label": "To Date",
"fieldtype": "Date",
"width": "80",
"default": wn.datetime.get_today()
}
]
}

View File

@@ -0,0 +1,109 @@
# 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 <http://www.gnu.org/licenses/>.
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(filters)
iwb_map = get_item_warehouse_batch_map(filters)
data = []
for item in sorted(iwb_map):
for wh in sorted(iwb_map[item]):
for batch in sorted(iwb_map[item][wh]):
qty_dict = iwb_map[item][wh][batch]
data.append([item, item_map[item]["item_name"],
item_map[item]["description"], wh, batch,
qty_dict.opening_qty, qty_dict.in_qty,
qty_dict.out_qty, qty_dict.bal_qty
])
return columns, data
def get_columns(filters):
"""return columns based on filters"""
columns = ["Item:Link/Item:100"] + ["Item Name::150"] + ["Description::150"] + \
["Warehouse:Link/Warehouse:100"] + ["Batch:Link/Batch:100"] + ["Opening Qty::90"] + \
["In Qty::80"] + ["Out Qty::80"] + ["Balance Qty::90"]
return columns
def get_conditions(filters):
conditions = ""
if filters.get("item_code"):
conditions += " and item_code='%s'" % filters["item_code"]
if filters.get("warehouse"):
conditions += " and warehouse='%s'" % filters["warehouse"]
if filters.get("batch_no"):
conditions += " and batch_no='%s'" % filters["batch_no"]
if not filters.get("from_date"):
webnotes.msgprint("Please enter From Date", raise_exception=1)
if filters.get("to_date"):
conditions += " and posting_date <= '%s'" % filters["to_date"]
else:
webnotes.msgprint("Please enter To Date", raise_exception=1)
return conditions
#get all details
def get_stock_ledger_entries(filters):
conditions = get_conditions(filters)
return webnotes.conn.sql("""select item_code, batch_no, warehouse,
posting_date, actual_qty
from `tabStock Ledger Entry`
where ifnull(is_cancelled, 'No') = 'No' %s order by item_code, warehouse""" %
conditions, as_dict=1)
def get_item_warehouse_batch_map(filters):
sle = get_stock_ledger_entries(filters)
iwb_map = {}
for d in sle:
iwb_map.setdefault(d.item_code, {}).setdefault(d.warehouse, {})\
.setdefault(d.batch_no, webnotes._dict({
"opening_qty": 0.0, "in_qty": 0.0, "out_qty": 0.0, "bal_qty": 0.0
}))
qty_dict = iwb_map[d.item_code][d.warehouse][d.batch_no]
if d.posting_date < filters["from_date"]:
qty_dict.opening_qty += flt(d.actual_qty)
elif d.posting_date >= filters["from_date"] and d.posting_date <= filters["to_date"]:
if flt(d.actual_qty) > 0:
qty_dict.in_qty += flt(d.actual_qty)
else:
qty_dict.out_qty += abs(flt(d.actual_qty))
qty_dict.bal_qty += flt(d.actual_qty)
return iwb_map
def get_item_details(filters):
if filters.get("item_code"):
conditions = " and name = '%s'" % filters["item_code"]
item_map = {}
for d in webnotes.conn.sql("select name, item_name, description from tabItem", as_dict=1):
item_map.setdefault(d.name, d)
return item_map

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-04 11:03:47",
"docstatus": 0,
"modified": "2013-06-04 19:32:27",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Stock Ledger Entry",
"report_name": "Batch-Wise Balance History",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Batch-Wise Balance History"
}
]

View File

View File

@@ -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 <http://www.gnu.org/licenses/>.
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

View File

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

View File

@@ -0,0 +1,32 @@
wn.query_reports["Warehouse-Wise Stock Balance"] = {
"filters": [
{
"fieldname":"item_code",
"label": "Item",
"fieldtype": "Link",
"options": "Item",
"width": "80"
},
{
"fieldname":"warehouse",
"label": "Warehouse",
"fieldtype": "Link",
"options": "Warehouse",
"width": "80"
},
{
"fieldname":"from_date",
"label": "From Date",
"fieldtype": "Date",
"width": "80",
"default": sys_defaults.year_start_date,
},
{
"fieldname":"to_date",
"label": "To Date",
"fieldtype": "Date",
"width": "80",
"default": wn.datetime.get_today()
}
]
}

View File

@@ -0,0 +1,104 @@
# 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 <http://www.gnu.org/licenses/>.
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(filters)
iwb_map = get_item_warehouse_map(filters)
data = []
for item in sorted(iwb_map):
for wh in sorted(iwb_map[item]):
qty_dict = iwb_map[item][wh]
data.append([item, item_map[item]["item_name"],
item_map[item]["description"], wh,
qty_dict.opening_qty, qty_dict.in_qty,
qty_dict.out_qty, qty_dict.bal_qty
])
return columns, data
def get_columns(filters):
"""return columns based on filters"""
columns = ["Item:Link/Item:100"] + ["Item Name::150"] + ["Description::150"] + \
["Warehouse:Link/Warehouse:100"] + ["Opening Qty::90"] + \
["In Qty::80"] + ["Out Qty::80"] + ["Balance Qty::90"]
return columns
def get_conditions(filters):
conditions = ""
if filters.get("item_code"):
conditions += " and item_code='%s'" % filters["item_code"]
if filters.get("warehouse"):
conditions += " and warehouse='%s'" % filters["warehouse"]
if not filters.get("from_date"):
webnotes.msgprint("Please enter From Date", raise_exception=1)
if filters.get("to_date"):
conditions += " and posting_date <= '%s'" % filters["to_date"]
else:
webnotes.msgprint("Please enter To Date", raise_exception=1)
return conditions
#get all details
def get_stock_ledger_entries(filters):
conditions = get_conditions(filters)
return webnotes.conn.sql("""select item_code, warehouse,
posting_date, actual_qty
from `tabStock Ledger Entry`
where ifnull(is_cancelled, 'No') = 'No' %s order by item_code, warehouse""" %
conditions, as_dict=1)
def get_item_warehouse_map(filters):
sle = get_stock_ledger_entries(filters)
iwb_map = {}
for d in sle:
iwb_map.setdefault(d.item_code, {}).setdefault(d.warehouse, webnotes._dict({\
"opening_qty": 0.0, "in_qty": 0.0, "out_qty": 0.0, "bal_qty": 0.0
}))
qty_dict = iwb_map[d.item_code][d.warehouse]
if d.posting_date < filters["from_date"]:
qty_dict.opening_qty += flt(d.actual_qty)
elif d.posting_date >= filters["from_date"] and d.posting_date <= filters["to_date"]:
if flt(d.actual_qty) > 0:
qty_dict.in_qty += flt(d.actual_qty)
else:
qty_dict.out_qty += abs(flt(d.actual_qty))
qty_dict.bal_qty += flt(d.actual_qty)
return iwb_map
def get_item_details(filters):
if filters.get("item_code"):
conditions = " and name = '%s'" % filters["item_code"]
item_map = {}
for d in webnotes.conn.sql("select name, item_name, description from tabItem", as_dict=1):
item_map.setdefault(d.name, d)
return item_map

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-05 11:00:31",
"docstatus": 0,
"modified": "2013-06-05 11:00:31",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Stock Ledger Entry",
"report_name": "Warehouse-Wise Stock Balance",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Warehouse-Wise Stock Balance"
}
]