diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 6e84b7bb6d..60df4ce6d9 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -96,4 +96,5 @@ erpnext.patches.v4_2.set_item_has_batch erpnext.patches.v4_2.update_stock_uom_for_dn_in_sle erpnext.patches.v4_2.repost_reserved_qty erpnext.patches.v4_2.repost_sle_for_si_with_no_warehouse -erpnext.patches.v4_2.fix_recurring_orders \ No newline at end of file +erpnext.patches.v4_2.fix_recurring_orders +erpnext.patches.v4_2.delete_gl_entries_for_cancelled_invoices diff --git a/erpnext/patches/v4_2/delete_gl_entries_for_cancelled_invoices.py b/erpnext/patches/v4_2/delete_gl_entries_for_cancelled_invoices.py new file mode 100644 index 0000000000..0e7796a666 --- /dev/null +++ b/erpnext/patches/v4_2/delete_gl_entries_for_cancelled_invoices.py @@ -0,0 +1,13 @@ +# 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(): + cancelled_invoices = frappe.db.sql_list("""select name from `tabSales Invoice` + where docstatus = 2 and ifnull(update_stock, 0) = 1""") + + frappe.db.sql("""delete from `tabGL Entry` + where voucher_type = 'Sales Invoice' and voucher_no in (%s)""" + % (', '.join(['%s']*len(cancelled_invoices))), tuple(cancelled_invoices)) \ No newline at end of file