blob: 60b54eca42bccf67e226314879c6bbb2f9abdc30 [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
10import sys
11sys.path.append("lib/py")
12sys.path.append(".")
13sys.path.append("erpnext")
14
15import webnotes
16
17#--------------------------------
18
19def delete_transactions():
20 print "Deleting transactions..."
21
22 trans = ['Timesheet','Task','Support Ticket','Stock Reconciliation', 'Stock Ledger Entry', \
23 'Stock Entry','Sales Order','Salary Slip','Sales Invoice','Quotation', 'Quality Inspection', \
24 'Purchase Receipt','Purchase Order','Production Order', 'POS Setting','Period Closing Voucher', \
25 'Purchase Invoice','Maintenance Visit','Maintenance Schedule','Leave Application', \
26 'Leave Allocation', 'Lead', 'Journal Voucher', 'Installation Note','Purchase Request', \
27 'GL Entry','Expense Claim','Opportunity','Delivery Note','Customer Issue','Bin', \
28 'Authorization Rule','Attendance','Account Balance', 'C-Form', 'Form 16A', 'Lease Agreement', \
29 'Lease Installment', 'TDS Payment', 'TDS Return Acknowledgement', 'Appraisal', \
30 'Installation Note', 'Communication'
31 ]
32 for d in trans:
33 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
34 webnotes.conn.sql("delete from `tab%s`" % (t))
35 webnotes.conn.sql("delete from `tab%s`" % (d))
36 webnotes.conn.sql("COMMIT")
37 webnotes.conn.sql("START TRANSACTION")
38 print "Deleted " + d
39
40
41
42def delete_masters():
43 print "Deleting masters...."
44 masters = {
45 'Workstation':['Default Workstation'],
46 'Warehouse Type':['Default Warehouse Type', 'Fixed Asset', 'Rejected', 'Reserved',
47 'Sample', 'Stores', 'WIP Warehouse'],
48 'Warehouse':['Default Warehouse'],
49 'UOM':['Kg', 'Mtr', 'Box', 'Ltr', 'Nos', 'Ft', 'Pair', 'Set'],
50 'Territory':['All Territories', 'Default Territory'],
51 'Terms and Conditions':'',
52 'Tag':'',
53 'Supplier Type':['Default Supplier Type'],
54 'Supplier':'',
55 'Serial No':'',
56 'Sales Person':['All Sales Persons'],
57 'Sales Partner':'',
58 'Sales BOM':'',
59 'Salary Structure':'',
60 'Purchase Taxes and Charges Master':'',
61 'Project':'',
62 'Print Heading':'',
63 'Price List':['Default Price List'],
64 'Period':'',
65 '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
110def reset_series():
111 # Reset series
112 webnotes.conn.sql("""update tabSeries set current = 0 where name not in \
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530113 ('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', \
116 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530117 """)
118 print "Series updated"
119
120
121def delete_main_masters():
122 main_masters = ['Fiscal Year','Company', 'DefaultValue']
123 for d in main_masters:
124 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
125 webnotes.conn.sql("delete from `tab%s`" % (t))
126 webnotes.conn.sql("delete from `tab%s`" % (d))
127 webnotes.conn.sql("COMMIT")
128 webnotes.conn.sql("START TRANSACTION")
129 print "Deleted " + d
130
131
132
133def reset_global_defaults():
134 flds = {
135 'default_company': '',
136 'default_currency': '',
137 'default_currency_format': 'Lacs',
138 'default_currency_fraction': '',
139 'current_fiscal_year': '',
140 'date_format': 'dd-mm-yyyy',
141 'sms_sender_name': '',
142 'default_item_group': 'Default',
143 'default_stock_uom': 'Nos',
144 'default_valuation_method': 'FIFO',
145 'default_warehouse_type': 'Default Warehouse Type',
146 'tolerance': '',
147 'acc_frozen_upto': '',
148 'bde_auth_role': '',
149 'credit_controller': '',
150 'default_customer_group': 'Default Customer Group',
151 'default_territory': 'Default',
152 'default_price_list': 'Standard',
153 'default_supplier_type': 'Default Supplier Type'
154 }
155
156 from webnotes.model.code import get_obj
157 gd = get_obj('Global Defaults', 'Global Defaults')
158 for d in flds:
159 gd.doc.fields[d] = flds[d]
160 gd.doc.save()
161
162 webnotes.clear_cache()
163
164
165def run():
166 webnotes.connect()
167
168 # Confirmation from user
169 confirm = ''
170 while not confirm:
171 confirm = raw_input("Are you sure you want to delete the data from the system (N/Y)?")
172 if confirm.lower() != 'y':
173 raise Exception
174
175 cleanup_type = ''
176 while cleanup_type not in ['1', '2']:
177 cleanup_type = raw_input("""\nWhat type of cleanup you want ot perform?
178 1. Only Transactions
179 2. Both Masters and Transactions
180
181 Please enter your choice (1/2):
182 """)
183
184 # delete
185 delete_transactions()
186
187 if cleanup_type == '1':
188 print '\n', '*' * 10 + 'NOTE' + '*' * 10, '\n'
189 print "To reset series of the transactions go to Setup --> Numbering Series\n"
190 else:
191 delete_masters()
192 reset_series()
193 delete_main_masters()
194 reset_global_defaults()
195
196 print "System cleaned up succesfully"
197 webnotes.conn.close()
198
199
200if __name__ == '__main__':
201 run()