Nabin Hait | e263919 | 2012-12-05 10:18:49 +0530 | [diff] [blame] | 1 | def execute(): |
| 2 | import webnotes |
| 3 | from webnotes.model import delete_doc |
| 4 | from webnotes.model.code import get_obj |
| 5 | from webnotes.model.doc import addchild |
| 6 | |
| 7 | # delete doctypes and tables |
| 8 | for dt in ["TDS Payment", "TDS Return Acknowledgement", "Form 16A", |
| 9 | "TDS Rate Chart", "TDS Category", "TDS Control", "TDS Detail", |
| 10 | "TDS Payment Detail", "TDS Rate Detail", "TDS Category Account", |
| 11 | "Form 16A Ack Detail", "Form 16A Tax Detail"]: |
| 12 | delete_doc("DocType", dt) |
| 13 | |
| 14 | webnotes.conn.commit() |
| 15 | webnotes.conn.sql("drop table if exists `tab%s`" % dt) |
| 16 | webnotes.conn.begin() |
| 17 | |
| 18 | delete_doc("Search Criteria", "tds_return") |
| 19 | |
| 20 | # Add tds entry in tax table for purchase invoice |
| 21 | pi_list = webnotes.conn.sql("""select name from `tabPurchase Invoice` |
| 22 | where ifnull(tax_code, '')!='' and ifnull(ded_amount, 0)!=0""") |
| 23 | for pi in pi_list: |
| 24 | piobj = get_obj("Purchase Invoice", pi[0], with_children=1) |
| 25 | ch = addchild(piobj.doc, 'taxes_and_charges', 'Purchase Taxes and Charges') |
| 26 | ch.charge_type = "Actual" |
| 27 | ch.account_head = piobj.doc.tax_code |
| 28 | ch.description = piobj.doc.tax_code |
| 29 | ch.rate = -1*piobj.doc.ded_amount |
| 30 | ch.tax_amount = -1*piobj.doc.ded_amount |
| 31 | ch.category = "Total" |
| 32 | ch.save(1) |
| 33 | |
| 34 | # Add tds entry in entries table for journal voucher |
| 35 | jv_list = webnotes.conn.sql("""select name from `tabJournal Voucher` |
| 36 | where ifnull(tax_code, '')!='' and ifnull(ded_amount, 0)!=0""") |
| 37 | for jv in jv_list: |
| 38 | jvobj = get_obj("Journal Voucher", jv[0], with_children=1) |
| 39 | ch = addchild(jvobj.doc, 'entries', 'Journal Voucher Detail') |
| 40 | ch.account = jvobj.doc.tax_code |
| 41 | ch.credit = jvobj.doc.ded_amount |
| 42 | ch.save(1) |