blob: d826613340dec34895f925125be1238b33e952db [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', \
29 'Authorization Rule','Attendance','Account Balance', 'C-Form', 'Form 16A', 'Lease Agreement', \
30 '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'],
65 'Period':'',
66 'Sales Taxes and Charges Master':'',
67 'Letter Head':'',
68 'Leave Type':['Leave Without Pay', 'Privilege Leave', 'Casual Leave', 'PL', 'CL', 'LWP',
69 'Compensatory Off', 'Sick Leave'],
70 'Landed Cost Master':'',
71 'Appraisal Template':'',
72 'Item Group':['All Item Groups', 'Default'],
73 'Item':'',
74 'Holiday List':'',
75 'Grade':'',
76 'Feed':'',
77 'Expense Claim Type':['Travel', 'Medical', 'Calls', 'Food', 'Others'],
78 'Event':'',
79 'Employment Type':'',
80 'Employee':'',
81 'Earning Type':['Basic', 'Conveyance', 'House Rent Allowance', 'Dearness Allowance',
82 'Medical Allowance', 'Telephone'],
83 'Designation':'',
84 'Department':'',
85 'Deduction Type':['Income Tax', 'Professional Tax', 'Provident Fund', 'Leave Deduction'],
86 'Customer Group':['All Customer Groups', 'Default Customer Group'],
87 'Customer':'',
88 'Cost Center':'',
89 'Contact':'',
90 'Campaign':'',
91 'Budget Distribution':'',
92 'Brand':'',
93 'Branch':'',
94 'Batch':'',
95 'Appraisal':'',
96 'Account':'',
97 'BOM': ''
98 }
99 for d in masters.keys():
100 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' \
101 and fieldtype='Table'" % d):
102 webnotes.conn.sql("delete from `tab%s`" % (t))
103 lst = '"'+'","'.join(masters[d])+ '"'
104 webnotes.conn.sql("delete from `tab%s` where name not in (%s)" % (d, lst))
105 webnotes.conn.sql("COMMIT")
106 webnotes.conn.sql("START TRANSACTION")
107 print "Deleted " + d
108
109
110
Nabin Hait82efcc72012-09-18 11:19:34 +0530111def reset_all_series():
112 # Reset master series
113 webnotes.conn.sql("""update tabSeries set current = 0 where name not in
114 ('Ann/', 'BSD', 'DEF', 'DF', 'EV', 'Event Updates/', 'FileData-',
115 'FL', 'FMD/', 'GLM Detail', 'Login Page/', 'MDI', 'MDR', 'MI', 'MIR',
116 'PERM', 'PR', 'SRCH/C/', 'TD', 'TIC/', 'TMD/', 'TW', 'UR', '_FEED',
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530117 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530118 """)
119 print "Series updated"
Nabin Hait82efcc72012-09-18 11:19:34 +0530120
121def reset_transaction_series():
122 webnotes.conn.sql("""update tabSeries set current = 0 where name in
123 ('JV', 'INV', 'BILL', 'SO', 'DN', 'PO', 'LEAD', 'ENQUIRY', 'ENQ', 'CI',
124 'IN', 'PS', 'IDT', 'QAI', 'QTN', 'STE', 'SQTN', 'SUP', 'TDSP', 'SR',
125 'POS', 'LAP', 'LAL', 'EXP')""")
126 print "Series updated"
Nabin Hait1c990352012-07-09 15:25:08 +0530127
128
129def delete_main_masters():
130 main_masters = ['Fiscal Year','Company', 'DefaultValue']
131 for d in main_masters:
132 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
133 webnotes.conn.sql("delete from `tab%s`" % (t))
134 webnotes.conn.sql("delete from `tab%s`" % (d))
135 webnotes.conn.sql("COMMIT")
136 webnotes.conn.sql("START TRANSACTION")
137 print "Deleted " + d
138
139
140
141def reset_global_defaults():
142 flds = {
143 'default_company': '',
144 'default_currency': '',
145 'default_currency_format': 'Lacs',
146 'default_currency_fraction': '',
147 'current_fiscal_year': '',
148 'date_format': 'dd-mm-yyyy',
149 'sms_sender_name': '',
150 'default_item_group': 'Default',
151 'default_stock_uom': 'Nos',
152 'default_valuation_method': 'FIFO',
153 'default_warehouse_type': 'Default Warehouse Type',
154 'tolerance': '',
155 'acc_frozen_upto': '',
156 'bde_auth_role': '',
157 'credit_controller': '',
158 'default_customer_group': 'Default Customer Group',
159 'default_territory': 'Default',
160 'default_price_list': 'Standard',
161 'default_supplier_type': 'Default Supplier Type'
162 }
163
164 from webnotes.model.code import get_obj
165 gd = get_obj('Global Defaults', 'Global Defaults')
166 for d in flds:
167 gd.doc.fields[d] = flds[d]
168 gd.doc.save()
169
170 webnotes.clear_cache()
171
172
173def run():
174 webnotes.connect()
175
176 # Confirmation from user
177 confirm = ''
178 while not confirm:
179 confirm = raw_input("Are you sure you want to delete the data from the system (N/Y)?")
180 if confirm.lower() != 'y':
181 raise Exception
182
183 cleanup_type = ''
184 while cleanup_type not in ['1', '2']:
185 cleanup_type = raw_input("""\nWhat type of cleanup you want ot perform?
186 1. Only Transactions
187 2. Both Masters and Transactions
188
189 Please enter your choice (1/2):
190 """)
191
192 # delete
193 delete_transactions()
194
Nabin Hait82efcc72012-09-18 11:19:34 +0530195 if cleanup_type == '1':
196 reset_transaction_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530197 else:
198 delete_masters()
Nabin Hait82efcc72012-09-18 11:19:34 +0530199 reset_all_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530200 delete_main_masters()
201 reset_global_defaults()
202
203 print "System cleaned up succesfully"
204 webnotes.conn.close()
205
206
207if __name__ == '__main__':
208 run()