Merge branch 'warehouse_blank_issue_for_non_stock_account' of https://github.com/rohitwaghchaure/erpnext_develop into rohitwaghchaure-warehouse_blank_issue_for_non_stock_account
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 7d6eba8..6971e0d 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -303,3 +303,4 @@
erpnext.patches.v7_0.remove_administrator_role_in_doctypes
erpnext.patches.v7_0.rename_fee_amount_to_fee_component
erpnext.patches.v7_0.calculate_total_costing_amount
+erpnext.patches.v7_0.fix_nonwarehouse_ledger_gl_entries_for_transactions
diff --git a/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py b/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py
new file mode 100644
index 0000000..af921df
--- /dev/null
+++ b/erpnext/patches/v7_0/fix_nonwarehouse_ledger_gl_entries_for_transactions.py
@@ -0,0 +1,45 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+ frappe.reload_doctype("Account")
+
+ warehouses = frappe.db.sql_list("""select name from tabAccount
+ where ifnull(account_type, '') = 'Stock' and ifnull(is_group, 0) = 0
+ and warehouse is null""")
+ if warehouses:
+ warehouses = set_warehouse_for_stock_account(warehouses)
+
+ stock_vouchers = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no
+ from `tabStock Ledger Entry` sle
+ where sle.warehouse in (%s)
+ order by sle.posting_date""" %
+ ', '.join(['%s']*len(warehouses)), tuple(warehouses))
+
+ rejected = []
+ for voucher_type, voucher_no in stock_vouchers:
+ try:
+ frappe.db.sql("""delete from `tabGL Entry`
+ where voucher_type=%s and voucher_no=%s""", (voucher_type, voucher_no))
+
+ voucher = frappe.get_doc(voucher_type, voucher_no)
+ voucher.make_gl_entries()
+ frappe.db.commit()
+ except Exception, e:
+ print frappe.get_traceback()
+ rejected.append([voucher_type, voucher_no])
+ frappe.db.rollback()
+
+ print rejected
+
+def set_warehouse_for_stock_account(warehouse_account):
+ for account in warehouse_account:
+ if frappe.db.exists('Warehouse', account):
+ frappe.db.set_value("Account", account, "warehouse", account)
+ else:
+ warehouse_account.remove(account)
+
+ return warehouse_account
\ No newline at end of file