blob: 95e1b8406633b2c7be14fadd06af83a690188b25 [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', \
27 'Leave Allocation', 'Lead', 'Journal Voucher', 'Installation Note','Purchase Request', \
28 '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))
37 webnotes.conn.sql("COMMIT")
38 webnotes.conn.sql("START TRANSACTION")
39 print "Deleted " + d
40
41
42
43def delete_masters():
44 print "Deleting masters...."
45 masters = {
46 'Workstation':['Default Workstation'],
47 'Warehouse Type':['Default Warehouse Type', 'Fixed Asset', 'Rejected', 'Reserved',
48 'Sample', 'Stores', 'WIP Warehouse'],
49 'Warehouse':['Default Warehouse'],
50 'UOM':['Kg', 'Mtr', 'Box', 'Ltr', 'Nos', 'Ft', 'Pair', 'Set'],
51 'Territory':['All Territories', 'Default Territory'],
52 'Terms and Conditions':'',
53 'Tag':'',
54 'Supplier Type':['Default Supplier Type'],
55 'Supplier':'',
56 'Serial No':'',
57 'Sales Person':['All Sales Persons'],
58 'Sales Partner':'',
59 'Sales BOM':'',
60 'Salary Structure':'',
61 'Purchase Taxes and Charges Master':'',
62 'Project':'',
63 'Print Heading':'',
64 'Price List':['Default Price List'],
Nabin Hait1c990352012-07-09 15:25:08 +053065 'Sales Taxes and Charges Master':'',
66 'Letter Head':'',
67 'Leave Type':['Leave Without Pay', 'Privilege Leave', 'Casual Leave', 'PL', 'CL', 'LWP',
68 'Compensatory Off', 'Sick Leave'],
69 'Landed Cost Master':'',
70 'Appraisal Template':'',
71 'Item Group':['All Item Groups', 'Default'],
72 'Item':'',
73 'Holiday List':'',
74 'Grade':'',
75 'Feed':'',
76 'Expense Claim Type':['Travel', 'Medical', 'Calls', 'Food', 'Others'],
77 'Event':'',
78 'Employment Type':'',
79 'Employee':'',
80 'Earning Type':['Basic', 'Conveyance', 'House Rent Allowance', 'Dearness Allowance',
81 'Medical Allowance', 'Telephone'],
82 'Designation':'',
83 'Department':'',
84 'Deduction Type':['Income Tax', 'Professional Tax', 'Provident Fund', 'Leave Deduction'],
85 'Customer Group':['All Customer Groups', 'Default Customer Group'],
86 'Customer':'',
87 'Cost Center':'',
88 'Contact':'',
89 'Campaign':'',
90 'Budget Distribution':'',
91 'Brand':'',
92 'Branch':'',
93 'Batch':'',
94 'Appraisal':'',
95 'Account':'',
96 'BOM': ''
97 }
98 for d in masters.keys():
99 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' \
100 and fieldtype='Table'" % d):
101 webnotes.conn.sql("delete from `tab%s`" % (t))
102 lst = '"'+'","'.join(masters[d])+ '"'
103 webnotes.conn.sql("delete from `tab%s` where name not in (%s)" % (d, lst))
104 webnotes.conn.sql("COMMIT")
105 webnotes.conn.sql("START TRANSACTION")
106 print "Deleted " + d
107
108
109
Nabin Hait82efcc72012-09-18 11:19:34 +0530110def reset_all_series():
111 # Reset master series
112 webnotes.conn.sql("""update tabSeries set current = 0 where name not in
113 ('Ann/', 'BSD', 'DEF', 'DF', 'EV', 'Event Updates/', 'FileData-',
114 'FL', 'FMD/', 'GLM Detail', 'Login Page/', 'MDI', 'MDR', 'MI', 'MIR',
115 'PERM', 'PR', 'SRCH/C/', 'TD', 'TIC/', 'TMD/', 'TW', 'UR', '_FEED',
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530116 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530117 """)
118 print "Series updated"
Nabin Hait82efcc72012-09-18 11:19:34 +0530119
120def reset_transaction_series():
121 webnotes.conn.sql("""update tabSeries set current = 0 where name in
122 ('JV', 'INV', 'BILL', 'SO', 'DN', 'PO', 'LEAD', 'ENQUIRY', 'ENQ', 'CI',
123 'IN', 'PS', 'IDT', 'QAI', 'QTN', 'STE', 'SQTN', 'SUP', 'TDSP', 'SR',
124 'POS', 'LAP', 'LAL', 'EXP')""")
125 print "Series updated"
Nabin Hait1c990352012-07-09 15:25:08 +0530126
127
128def delete_main_masters():
129 main_masters = ['Fiscal Year','Company', 'DefaultValue']
130 for d in main_masters:
131 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
132 webnotes.conn.sql("delete from `tab%s`" % (t))
133 webnotes.conn.sql("delete from `tab%s`" % (d))
134 webnotes.conn.sql("COMMIT")
135 webnotes.conn.sql("START TRANSACTION")
136 print "Deleted " + d
137
138
139
140def reset_global_defaults():
141 flds = {
142 'default_company': '',
143 'default_currency': '',
144 'default_currency_format': 'Lacs',
145 'default_currency_fraction': '',
146 'current_fiscal_year': '',
147 'date_format': 'dd-mm-yyyy',
148 'sms_sender_name': '',
149 'default_item_group': 'Default',
150 'default_stock_uom': 'Nos',
151 'default_valuation_method': 'FIFO',
152 'default_warehouse_type': 'Default Warehouse Type',
153 'tolerance': '',
154 'acc_frozen_upto': '',
155 'bde_auth_role': '',
156 'credit_controller': '',
157 'default_customer_group': 'Default Customer Group',
158 'default_territory': 'Default',
159 'default_price_list': 'Standard',
160 'default_supplier_type': 'Default Supplier Type'
161 }
162
163 from webnotes.model.code import get_obj
164 gd = get_obj('Global Defaults', 'Global Defaults')
165 for d in flds:
166 gd.doc.fields[d] = flds[d]
167 gd.doc.save()
168
169 webnotes.clear_cache()
170
171
172def run():
173 webnotes.connect()
174
175 # Confirmation from user
176 confirm = ''
177 while not confirm:
178 confirm = raw_input("Are you sure you want to delete the data from the system (N/Y)?")
179 if confirm.lower() != 'y':
180 raise Exception
181
182 cleanup_type = ''
183 while cleanup_type not in ['1', '2']:
184 cleanup_type = raw_input("""\nWhat type of cleanup you want ot perform?
185 1. Only Transactions
186 2. Both Masters and Transactions
187
188 Please enter your choice (1/2):
189 """)
190
191 # delete
192 delete_transactions()
193
Nabin Hait82efcc72012-09-18 11:19:34 +0530194 if cleanup_type == '1':
195 reset_transaction_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530196 else:
197 delete_masters()
Nabin Hait82efcc72012-09-18 11:19:34 +0530198 reset_all_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530199 delete_main_masters()
200 reset_global_defaults()
201
202 print "System cleaned up succesfully"
203 webnotes.conn.close()
204
205
206if __name__ == '__main__':
207 run()