[patch] [minor] perpetual inventory stock transfer utility

This commit is contained in:
Nabin Hait
2013-10-04 14:30:33 +05:30
parent b4212a5672
commit b646b3b3e6

View File

@@ -3,7 +3,7 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import nowdate, nowtime from webnotes.utils import nowdate, nowtime, cstr
from accounts.utils import get_fiscal_year from accounts.utils import get_fiscal_year
def execute(): def execute():
@@ -12,7 +12,8 @@ def execute():
item_map.setdefault(item.name, item) item_map.setdefault(item.name, item)
warehouse_map = get_warehosue_map() warehouse_map = get_warehosue_map()
# naming_series = naming_series = "STE/13/"
for company in webnotes.conn.sql("select name from tabCompany"): for company in webnotes.conn.sql("select name from tabCompany"):
stock_entry = [{ stock_entry = [{
"doctype": "Stock Entry", "doctype": "Stock Entry",
@@ -22,16 +23,28 @@ def execute():
"purpose": "Material Transfer", "purpose": "Material Transfer",
"company": company[0], "company": company[0],
"remarks": "Material Transfer to activate perpetual inventory", "remarks": "Material Transfer to activate perpetual inventory",
"fiscal_year": get_fiscal_year(nowdate()) "fiscal_year": get_fiscal_year(nowdate())[0]
}] }]
expense_account = "Cost of Goods Sold - NISL" expense_account = "Cost of Goods Sold - NISL"
cost_center = "Default CC Ledger - NISL" cost_center = "Default CC Ledger - NISL"
for bin in webnotes.conn.sql("select * from tabBin where company=%s", company[0] as_dict=1): for bin in webnotes.conn.sql("""select * from tabBin bin where ifnull(item_code, '')!=''
new_warehouse = warehouse_map[bin.warehouse].get("fixed_asset_warehouse") \ and ifnull(warehouse, '')!='' and ifnull(actual_qty, 0) != 0
if cstr(item_map[bin.item_code]) == "Yes" else wh.get("current_asset_warehouse") and (select company from tabWarehouse where name=bin.warehouse)=%s""",
company[0], as_dict=1):
item_details = item_map[bin.item_code] item_details = item_map[bin.item_code]
new_warehouse = warehouse_map[bin.warehouse].get("fixed_asset_warehouse") \
if cstr(item_details.is_asset_item) == "Yes" \
else warehouse_map[bin.warehouse].get("current_asset_warehouse")
if item_details.has_serial_no == "Yes":
serial_no = "\n".join([d[0] for d in webnotes.conn.sql("""select name
from `tabSerial No` where item_code = %s and warehouse = %s""",
(bin.item_code, bin.warehouse))])
print serial_no
else:
serial_no = None
stock_entry.append({ stock_entry.append({
"doctype": "Stock Entry Detail", "doctype": "Stock Entry Detail",
"parentfield": "mtn_details", "parentfield": "mtn_details",
@@ -45,7 +58,8 @@ def execute():
"stock_uom": item_details.stock_uom, "stock_uom": item_details.stock_uom,
"conversion_factor": 1, "conversion_factor": 1,
"expense_account": expense_account, "expense_account": expense_account,
"cost_center": cost_center "cost_center": cost_center,
"serial_no": serial_no
}) })
webnotes.bean(stock_entry).insert() webnotes.bean(stock_entry).insert()
@@ -64,7 +78,7 @@ def get_warehosue_map():
"current_asset_warehouse": "Transit-New - NISL", "current_asset_warehouse": "Transit-New - NISL",
"fixed_asset_warehouse": "" "fixed_asset_warehouse": ""
}, },
"ASSET-MAHAPE": { "ASSET - MAHAPE": {
"current_asset_warehouse": "", "current_asset_warehouse": "",
"fixed_asset_warehouse": "Assets-New - NISL" "fixed_asset_warehouse": "Assets-New - NISL"
} }