From 82d7c0c9eb8bdc75cf46907f393eadfad2d28641 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 29 Sep 2014 15:07:51 +0530 Subject: [PATCH] Patch: Fix gl entries for stock transactions --- .../fix_gl_entries_for_stock_transactions.py | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 erpnext/patches/v4_2/fix_gl_entries_for_stock_transactions.py diff --git a/erpnext/patches/v4_2/fix_gl_entries_for_stock_transactions.py b/erpnext/patches/v4_2/fix_gl_entries_for_stock_transactions.py new file mode 100644 index 0000000000..e065d2d42f --- /dev/null +++ b/erpnext/patches/v4_2/fix_gl_entries_for_stock_transactions.py @@ -0,0 +1,26 @@ +# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors +# License: GNU General Public License v3. See license.txt + +from __future__ import unicode_literals +import frappe + +def execute(): + warehouses_with_account = frappe.db.sql_list("""select master_name from tabAccount + where ifnull(account_type, '') = 'Warehouse'""") + + stock_vouchers_without_gle = frappe.db.sql("""select distinct sle.voucher_type, sle.voucher_no + from `tabStock Ledger Entry` sle + where sle.warehouse in (%s) + and not exists(select name from `tabGL Entry` + where voucher_type=sle.voucher_type and voucher_no=sle.voucher_no) + order by sle.posting_date""" % + ', '.join(['%s']*len(warehouses_with_account)), tuple(warehouses_with_account)) + + for voucher_type, voucher_no in stock_vouchers_without_gle: + print voucher_type, voucher_no + 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()