blob: a9cc5c340e833eeb110a2be21f348fce47e483ec [file] [log] [blame]
Nabin Hait1c990352012-07-09 15:25:08 +05301#!/usr/bin/python
2
3# This script is for cleaning up of all data from system including
4# all transactions and masters (excludes default masters).
5# Basically after running this file, system will reset to it's
6# initial state.
7# This script can be executed from lib/wnf.py using
8# lib/wnf.py --cleanup-data
9
Anand Doshi486f9df2012-07-19 13:40:31 +053010from __future__ import unicode_literals
Nabin Hait1c990352012-07-09 15:25:08 +053011import sys
12sys.path.append("lib/py")
13sys.path.append(".")
14sys.path.append("erpnext")
15
16import webnotes
17
18#--------------------------------
19
20def delete_transactions():
21 print "Deleting transactions..."
22
23 trans = ['Timesheet','Task','Support Ticket','Stock Reconciliation', 'Stock Ledger Entry', \
24 'Stock Entry','Sales Order','Salary Slip','Sales Invoice','Quotation', 'Quality Inspection', \
25 'Purchase Receipt','Purchase Order','Production Order', 'POS Setting','Period Closing Voucher', \
26 'Purchase Invoice','Maintenance Visit','Maintenance Schedule','Leave Application', \
Anand Doshi236cc172013-02-18 13:49:15 +053027 'Leave Allocation', 'Lead', 'Journal Voucher', 'Installation Note','Material Request', \
Nabin Hait1c990352012-07-09 15:25:08 +053028 'GL Entry','Expense Claim','Opportunity','Delivery Note','Customer Issue','Bin', \
Anand Doshi440c1eb2012-09-28 16:03:11 +053029 'Authorization Rule','Attendance', 'C-Form', 'Form 16A', 'Lease Agreement', \
Nabin Hait1c990352012-07-09 15:25:08 +053030 'Lease Installment', 'TDS Payment', 'TDS Return Acknowledgement', 'Appraisal', \
31 'Installation Note', 'Communication'
32 ]
33 for d in trans:
34 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
35 webnotes.conn.sql("delete from `tab%s`" % (t))
36 webnotes.conn.sql("delete from `tab%s`" % (d))
Nabin Hait1c990352012-07-09 15:25:08 +053037 print "Deleted " + d
38
39
40
41def delete_masters():
42 print "Deleting masters...."
43 masters = {
44 'Workstation':['Default Workstation'],
45 'Warehouse Type':['Default Warehouse Type', 'Fixed Asset', 'Rejected', 'Reserved',
46 'Sample', 'Stores', 'WIP Warehouse'],
47 'Warehouse':['Default Warehouse'],
48 'UOM':['Kg', 'Mtr', 'Box', 'Ltr', 'Nos', 'Ft', 'Pair', 'Set'],
49 'Territory':['All Territories', 'Default Territory'],
50 'Terms and Conditions':'',
51 'Tag':'',
52 'Supplier Type':['Default Supplier Type'],
53 'Supplier':'',
54 'Serial No':'',
55 'Sales Person':['All Sales Persons'],
56 'Sales Partner':'',
57 'Sales BOM':'',
58 'Salary Structure':'',
59 'Purchase Taxes and Charges Master':'',
60 'Project':'',
61 'Print Heading':'',
62 'Price List':['Default Price List'],
Nabin Hait1c990352012-07-09 15:25:08 +053063 'Sales Taxes and Charges Master':'',
64 'Letter Head':'',
65 'Leave Type':['Leave Without Pay', 'Privilege Leave', 'Casual Leave', 'PL', 'CL', 'LWP',
66 'Compensatory Off', 'Sick Leave'],
Nabin Hait1c990352012-07-09 15:25:08 +053067 'Appraisal Template':'',
68 'Item Group':['All Item Groups', 'Default'],
69 'Item':'',
70 'Holiday List':'',
71 'Grade':'',
72 'Feed':'',
73 'Expense Claim Type':['Travel', 'Medical', 'Calls', 'Food', 'Others'],
74 'Event':'',
75 'Employment Type':'',
76 'Employee':'',
77 'Earning Type':['Basic', 'Conveyance', 'House Rent Allowance', 'Dearness Allowance',
78 'Medical Allowance', 'Telephone'],
79 'Designation':'',
80 'Department':'',
81 'Deduction Type':['Income Tax', 'Professional Tax', 'Provident Fund', 'Leave Deduction'],
82 'Customer Group':['All Customer Groups', 'Default Customer Group'],
83 'Customer':'',
84 'Cost Center':'',
85 'Contact':'',
86 'Campaign':'',
87 'Budget Distribution':'',
88 'Brand':'',
89 'Branch':'',
90 'Batch':'',
91 'Appraisal':'',
92 'Account':'',
93 'BOM': ''
94 }
95 for d in masters.keys():
96 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' \
97 and fieldtype='Table'" % d):
98 webnotes.conn.sql("delete from `tab%s`" % (t))
99 lst = '"'+'","'.join(masters[d])+ '"'
100 webnotes.conn.sql("delete from `tab%s` where name not in (%s)" % (d, lst))
Nabin Hait1c990352012-07-09 15:25:08 +0530101 print "Deleted " + d
102
103
104
Nabin Hait82efcc72012-09-18 11:19:34 +0530105def reset_all_series():
106 # Reset master series
107 webnotes.conn.sql("""update tabSeries set current = 0 where name not in
108 ('Ann/', 'BSD', 'DEF', 'DF', 'EV', 'Event Updates/', 'FileData-',
109 'FL', 'FMD/', 'GLM Detail', 'Login Page/', 'MDI', 'MDR', 'MI', 'MIR',
110 'PERM', 'PR', 'SRCH/C/', 'TD', 'TIC/', 'TMD/', 'TW', 'UR', '_FEED',
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530111 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530112 """)
113 print "Series updated"
Nabin Hait82efcc72012-09-18 11:19:34 +0530114
115def reset_transaction_series():
116 webnotes.conn.sql("""update tabSeries set current = 0 where name in
117 ('JV', 'INV', 'BILL', 'SO', 'DN', 'PO', 'LEAD', 'ENQUIRY', 'ENQ', 'CI',
118 'IN', 'PS', 'IDT', 'QAI', 'QTN', 'STE', 'SQTN', 'SUP', 'TDSP', 'SR',
119 'POS', 'LAP', 'LAL', 'EXP')""")
120 print "Series updated"
Nabin Hait1c990352012-07-09 15:25:08 +0530121
122
123def delete_main_masters():
124 main_masters = ['Fiscal Year','Company', 'DefaultValue']
125 for d in main_masters:
126 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
127 webnotes.conn.sql("delete from `tab%s`" % (t))
128 webnotes.conn.sql("delete from `tab%s`" % (d))
Nabin Hait1c990352012-07-09 15:25:08 +0530129 print "Deleted " + d
130
131
132
133def reset_global_defaults():
134 flds = {
135 'default_company': '',
136 'default_currency': '',
Nabin Hait1c990352012-07-09 15:25:08 +0530137 'current_fiscal_year': '',
138 'date_format': 'dd-mm-yyyy',
139 'sms_sender_name': '',
140 'default_item_group': 'Default',
141 'default_stock_uom': 'Nos',
142 'default_valuation_method': 'FIFO',
143 'default_warehouse_type': 'Default Warehouse Type',
144 'tolerance': '',
145 'acc_frozen_upto': '',
146 'bde_auth_role': '',
147 'credit_controller': '',
148 'default_customer_group': 'Default Customer Group',
149 'default_territory': 'Default',
150 'default_price_list': 'Standard',
151 'default_supplier_type': 'Default Supplier Type'
152 }
153
154 from webnotes.model.code import get_obj
155 gd = get_obj('Global Defaults', 'Global Defaults')
156 for d in flds:
157 gd.doc.fields[d] = flds[d]
158 gd.doc.save()
159
160 webnotes.clear_cache()
161
162
163def run():
164 webnotes.connect()
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200165 webnotes.conn.begin()
Nabin Hait1c990352012-07-09 15:25:08 +0530166
167 # Confirmation from user
168 confirm = ''
169 while not confirm:
170 confirm = raw_input("Are you sure you want to delete the data from the system (N/Y)?")
171 if confirm.lower() != 'y':
172 raise Exception
173
174 cleanup_type = ''
175 while cleanup_type not in ['1', '2']:
176 cleanup_type = raw_input("""\nWhat type of cleanup you want ot perform?
177 1. Only Transactions
178 2. Both Masters and Transactions
179
180 Please enter your choice (1/2):
181 """)
182
183 # delete
184 delete_transactions()
185
Nabin Hait82efcc72012-09-18 11:19:34 +0530186 if cleanup_type == '1':
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200187 print "Reset Transaction Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530188 reset_transaction_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530189 else:
190 delete_masters()
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200191 print "Reset All Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530192 reset_all_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530193 delete_main_masters()
194 reset_global_defaults()
195
196 print "System cleaned up succesfully"
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200197 webnotes.conn.commit()
Nabin Hait1c990352012-07-09 15:25:08 +0530198 webnotes.conn.close()
199
200
201if __name__ == '__main__':
202 run()