From 8a5be5b74726c3ba88200cca033b0f36f884051b Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 3 Oct 2012 16:19:28 +0530 Subject: [PATCH 1/3] fix wrong vouchers due to Valuation charges --- patches/october_2012/find_wrong_voucher.py | 16 ------- patches/october_2012/fix_wrong_vouchers.py | 53 ++++++++++++++++++++++ 2 files changed, 53 insertions(+), 16 deletions(-) delete mode 100644 patches/october_2012/find_wrong_voucher.py create mode 100644 patches/october_2012/fix_wrong_vouchers.py diff --git a/patches/october_2012/find_wrong_voucher.py b/patches/october_2012/find_wrong_voucher.py deleted file mode 100644 index 637ed1d70e..0000000000 --- a/patches/october_2012/find_wrong_voucher.py +++ /dev/null @@ -1,16 +0,0 @@ -def execute(): - import webnotes - from webnotes.utils import flt - vouchers = webnotes.conn.sql(""" - select parent, parenttype, modified, sum(if(add_deduct_tax='Add', tax_amount, -tax_amount)) as tax from `tabPurchase Taxes and Charges` - where modified >= '2012-07-12' - and category in ('Total', 'Valuation and Total') - and parenttype != 'Purchase Taxes and Charges Master' - group by parenttype, parent - """) - - for d in vouchers: - total_tax = webnotes.conn.sql("""select total_tax from `tab%s` where name = %s""" % - (d[1], '%s'), d[0]) - if total_tax and flt(total_tax[0][0]) != flt(d[3]): - print d \ No newline at end of file diff --git a/patches/october_2012/fix_wrong_vouchers.py b/patches/october_2012/fix_wrong_vouchers.py new file mode 100644 index 0000000000..ce47ff7dad --- /dev/null +++ b/patches/october_2012/fix_wrong_vouchers.py @@ -0,0 +1,53 @@ +def execute(): + import webnotes + from webnotes.utils import flt + from webnotes.model.code import get_obj + + vouchers = webnotes.conn.sql(""" + select + parent, parenttype, modified, + sum(if(category in ('Valuation and Total', 'Total') and add_deduct_tax='Add', + tax_amount, 0)) as tax_added, + sum(if(category in ('Valuation and Total', 'Total') and add_deduct_tax='Deduct', + tax_amount, 0)) as tax_ded + from + `tabPurchase Taxes and Charges` + where + modified >= '2012-07-12' + and parenttype != 'Purchase Taxes and Charges Master' + and parent not like 'old_p%' + and docstatus != 2 + group by parenttype, parent + order by modified + """, as_dict=1) + + for d in vouchers: + current_total_tax = webnotes.conn.sql("""select total_tax from `tab%s` where name = %s""" % + (d['parenttype'], '%s'), d['parent']) + correct_total_tax = flt(d['tax_added']) - flt(d['tax_ded']) + + if flt(current_total_tax[0][0]) != correct_total_tax: + if d['parenttype'] == 'Purchase Invoice': + webnotes.conn.sql(""" + update `tab%s` + set + total_tax = %s, other_charges_added = %s, other_charges_deducted = %s, + grand_total = net_tatal + other_charges_added - other_charges_deducted, + total_amount_to_pay = grand_total - total_tds_on_voucher, + outstanding_amount = total_amount_to_pay - total_advance + where + name = %s + """ % (d['parenttype'], '%s', '%s', '%s', '%s'), + (correct_total_tax, d['tax_added'], d['tax_ded'], d['parent'])) + + # post gl entry + webnotes.conn.sql("""update `tabGL Entry` set is_cancelled = 'No' + where voucher_type = %s and voucher_no = %s""", + (d['parenttype'], d['parent'])) + obj = get_obj(d['parenttype'], d['parent'], with_children=1) + obj.make_gl_entries() + + else: + webnotes.conn.sql("""update `tab%s` + set total_tax = %s, grand_total = net_tatal + total_tax + where name = %s""" % (d[1], '%s', '%s'), (correct_total_tax, d['parent'])) \ No newline at end of file From 1e794414571d7fed0c323af29914b419ac9f8b1c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 3 Oct 2012 16:31:45 +0530 Subject: [PATCH 2/3] fix wrong vouchers due to Valuation charges --- patches/october_2012/fix_wrong_vouchers.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/patches/october_2012/fix_wrong_vouchers.py b/patches/october_2012/fix_wrong_vouchers.py index ce47ff7dad..f7ff2b416b 100644 --- a/patches/october_2012/fix_wrong_vouchers.py +++ b/patches/october_2012/fix_wrong_vouchers.py @@ -31,8 +31,13 @@ def execute(): webnotes.conn.sql(""" update `tab%s` set - total_tax = %s, other_charges_added = %s, other_charges_deducted = %s, - grand_total = net_tatal + other_charges_added - other_charges_deducted, + total_tax = %s, + other_charges_added = %s, + other_charges_added_import = other_charges_added / conversion_rate, + other_charges_deducted = %s, + other_charges_deducted_import = other_charges_deducted / conversion_rate, + grand_total = net_total + other_charges_added - other_charges_deducted, + grand_total_import = grand_total / conversion_rate, total_amount_to_pay = grand_total - total_tds_on_voucher, outstanding_amount = total_amount_to_pay - total_advance where @@ -48,6 +53,12 @@ def execute(): obj.make_gl_entries() else: - webnotes.conn.sql("""update `tab%s` - set total_tax = %s, grand_total = net_tatal + total_tax - where name = %s""" % (d[1], '%s', '%s'), (correct_total_tax, d['parent'])) \ No newline at end of file + webnotes.conn.sql(""" + update `tab%s` + set + total_tax = %s, + grand_total = net_total + total_tax, + grand_total_import = grand_total / conversion_rate + where + name = %s + """ % (d[1], '%s', '%s'), (correct_total_tax, d['parent'])) \ No newline at end of file From c09de35ba551cbb1e19fbf7c56392f421801963c Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Wed, 3 Oct 2012 16:34:53 +0530 Subject: [PATCH 3/3] fix wrong vouchers due to Valuation charges --- patches/october_2012/fix_wrong_vouchers.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/patches/october_2012/fix_wrong_vouchers.py b/patches/october_2012/fix_wrong_vouchers.py index f7ff2b416b..62188614d5 100644 --- a/patches/october_2012/fix_wrong_vouchers.py +++ b/patches/october_2012/fix_wrong_vouchers.py @@ -5,11 +5,11 @@ def execute(): vouchers = webnotes.conn.sql(""" select - parent, parenttype, modified, + parent, parenttype, modified, docstatus, sum(if(category in ('Valuation and Total', 'Total') and add_deduct_tax='Add', tax_amount, 0)) as tax_added, sum(if(category in ('Valuation and Total', 'Total') and add_deduct_tax='Deduct', - tax_amount, 0)) as tax_ded + tax_amount, 0)) as tax_ded from `tabPurchase Taxes and Charges` where @@ -46,11 +46,12 @@ def execute(): (correct_total_tax, d['tax_added'], d['tax_ded'], d['parent'])) # post gl entry - webnotes.conn.sql("""update `tabGL Entry` set is_cancelled = 'No' - where voucher_type = %s and voucher_no = %s""", - (d['parenttype'], d['parent'])) - obj = get_obj(d['parenttype'], d['parent'], with_children=1) - obj.make_gl_entries() + if d['docstatus'] == 1: + webnotes.conn.sql("""update `tabGL Entry` set is_cancelled = 'No' + where voucher_type = %s and voucher_no = %s""", + (d['parenttype'], d['parent'])) + obj = get_obj(d['parenttype'], d['parent'], with_children=1) + obj.make_gl_entries() else: webnotes.conn.sql("""