2013-11-20 07:29:58 +00:00
|
|
|
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
|
2013-08-05 09:29:54 +00:00
|
|
|
# License: GNU General Public License v3. See license.txt
|
|
|
|
|
2012-10-03 10:49:28 +00:00
|
|
|
def execute():
|
|
|
|
import webnotes
|
|
|
|
from webnotes.utils import flt
|
|
|
|
from webnotes.model.code import get_obj
|
2012-10-03 11:28:24 +00:00
|
|
|
from webnotes.utils import money_in_words
|
|
|
|
|
2012-10-03 10:49:28 +00:00
|
|
|
vouchers = webnotes.conn.sql("""
|
|
|
|
select
|
2012-10-03 11:04:53 +00:00
|
|
|
parent, parenttype, modified, docstatus,
|
2012-10-03 10:49:28 +00:00
|
|
|
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',
|
2012-10-03 11:04:53 +00:00
|
|
|
tax_amount, 0)) as tax_ded
|
2012-10-03 10:49:28 +00:00
|
|
|
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'])
|
|
|
|
|
2012-10-03 11:28:24 +00:00
|
|
|
if flt(current_total_tax[0][0]) != correct_total_tax:
|
2012-10-03 10:49:28 +00:00
|
|
|
if d['parenttype'] == 'Purchase Invoice':
|
|
|
|
webnotes.conn.sql("""
|
|
|
|
update `tab%s`
|
|
|
|
set
|
2012-10-03 11:01:45 +00:00
|
|
|
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,
|
2012-10-03 13:11:28 +00:00
|
|
|
grand_total_import = grand_total / conversion_rate,
|
2012-10-03 10:49:28 +00:00
|
|
|
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'),
|
2012-10-03 11:28:24 +00:00
|
|
|
(correct_total_tax, d['tax_added'], d['tax_ded'], d['parent']))
|
2012-10-03 10:49:28 +00:00
|
|
|
|
|
|
|
else:
|
2012-10-03 11:01:45 +00:00
|
|
|
webnotes.conn.sql("""
|
|
|
|
update `tab%s`
|
|
|
|
set
|
|
|
|
total_tax = %s,
|
2012-10-03 13:11:28 +00:00
|
|
|
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,
|
2012-10-03 11:01:45 +00:00
|
|
|
grand_total = net_total + total_tax,
|
2012-10-03 13:11:28 +00:00
|
|
|
grand_total_import = grand_total / conversion_rate,
|
|
|
|
rounded_total = round(grand_total)
|
2012-10-03 11:01:45 +00:00
|
|
|
where
|
|
|
|
name = %s
|
2012-10-03 13:11:28 +00:00
|
|
|
""" % (d['parenttype'], '%s', '%s', '%s', '%s'),
|
|
|
|
(correct_total_tax, d['tax_added'], d['tax_ded'], d['parent']))
|
2012-10-03 11:28:24 +00:00
|
|
|
|
|
|
|
# set in words
|
|
|
|
obj = get_obj(d['parenttype'], d['parent'], with_children=1)
|
|
|
|
|
|
|
|
base_currency = webnotes.conn.get_value('Company', obj.doc.company, 'default_currency')\
|
|
|
|
or get_defaults('default_currency')
|
|
|
|
|
|
|
|
webnotes.conn.set_value(d['parenttype'], d['parent'], \
|
|
|
|
'in_words', money_in_words(obj.doc.grand_total, base_currency))
|
|
|
|
webnotes.conn.set_value(d['parenttype'], d['parent'], \
|
|
|
|
'in_words_import', money_in_words(obj.doc.grand_total_import, obj.doc.currency))
|
|
|
|
|
|
|
|
# fix gl entries
|
|
|
|
if d['parenttype'] == 'Purchase Invoice' and d['docstatus'] == 1:
|
2012-10-03 13:11:28 +00:00
|
|
|
webnotes.conn.sql("""update `tabGL Entry` set is_cancelled = 'Yes'
|
2012-10-03 11:28:24 +00:00
|
|
|
where voucher_type = %s and voucher_no = %s""",
|
|
|
|
(d['parenttype'], d['parent']))
|
|
|
|
|
|
|
|
obj.make_gl_entries()
|