From b63e99eb430da3b1e5ad7a0de3f7072c52d39543 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 9 Jun 2014 12:49:09 +0530 Subject: [PATCH] Update tax amount after discount in existing documents --- erpnext/patches.txt | 1 + .../v4_0/update_tax_amount_after_discount.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 erpnext/patches/v4_0/update_tax_amount_after_discount.py diff --git a/erpnext/patches.txt b/erpnext/patches.txt index 13d853845a..bd89582743 100644 --- a/erpnext/patches.txt +++ b/erpnext/patches.txt @@ -52,3 +52,4 @@ erpnext.patches.v4_0.fix_address_template # WATCHOUT: This patch reload's documents erpnext.patches.v4_0.reset_permissions_for_masters +erpnext.patches.v4_0.update_tax_amount_after_discount diff --git a/erpnext/patches/v4_0/update_tax_amount_after_discount.py b/erpnext/patches/v4_0/update_tax_amount_after_discount.py new file mode 100644 index 0000000000..37f082b290 --- /dev/null +++ b/erpnext/patches/v4_0/update_tax_amount_after_discount.py @@ -0,0 +1,19 @@ +# 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(): + docs_with_discount_amount = frappe._dict() + for dt in ["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"]: + records = frappe.db.sql_list("""select name from `tab%s` + where ifnull(discount_amount, 0) > 0 and docstatus=1""" % dt) + docs_with_discount_amount[dt] = records + + for dt, discounted_records in docs_with_discount_amount.items(): + frappe.db.sql("""update `tabSales Taxes and Charges` + set tax_amount_after_discount_amount = tax_amount + where parenttype = %s and parent not in (%s)""" % + ('%s', ', '.join(['%s']*(len(discounted_records)+1))), + tuple([dt, ''] + discounted_records))