blob: df7f4be15934b1a2e742806b58e50a9ee4e6a4d0 [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
Nabin Haitac24d0f2013-07-01 14:03:08 +053023 trans = ['Task', 'Support Ticket', 'Stock Reconciliation', 'Stock Ledger Entry',
Nabin Haitbffbc182013-03-12 10:41:21 +053024 'Stock Entry', 'Sales Order', 'Salary Slip','Sales Invoice', 'Quotation',
25 'Quality Inspection', 'Purchase Receipt', 'Purchase Order', 'Production Order',
26 'POS Setting', 'Period Closing Voucher', 'Purchase Invoice', 'Maintenance Visit',
27 'Maintenance Schedule', 'Leave Application', 'Leave Allocation', 'Lead', 'Journal Voucher',
28 'Installation Note', 'Material Request', 'GL Entry', 'Expense Claim', 'Opportunity',
29 'Delivery Note', 'Customer Issue', 'Bin', 'Authorization Rule', 'Attendance', 'C-Form',
Nabin Haitac24d0f2013-07-01 14:03:08 +053030 'Appraisal', 'Installation Note', 'Communication', "Supplier Quotation", "Newsletter",
31 "Job Applicant", "Web Page", "Website Slideshow", "Blog Post", "Blog Category", "Blogger",
32 "Time Log", "Time Log Batch", "Workflow"]
Nabin Hait1c990352012-07-09 15:25:08 +053033 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 = {
Nabin Haitbffbc182013-03-12 10:41:21 +053044 'Workstation': ['Default Workstation'],
45 'Warehouse Type': ['Default Warehouse Type', 'Fixed Asset', 'Rejected', 'Reserved',
Nabin Hait1c990352012-07-09 15:25:08 +053046 'Sample', 'Stores', 'WIP Warehouse'],
Nabin Haitbffbc182013-03-12 10:41:21 +053047 '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'],
63 'Sales Taxes and Charges Master': '',
64 'Letter Head': '',
65 'Leave Type': ['Leave Without Pay', 'Privilege Leave', 'Casual Leave', 'PL', 'CL', 'LWP',
Nabin Hait1c990352012-07-09 15:25:08 +053066 'Compensatory Off', 'Sick Leave'],
Nabin Haitbffbc182013-03-12 10:41:21 +053067 'Appraisal Template': '',
68 'Item Group': ['All Item Groups', 'Default'],
69 'Item': '',
70 'Holiday List': '',
Nabin Haitac24d0f2013-07-01 14:03:08 +053071 'Activity Type': '',
Nabin Haitbffbc182013-03-12 10:41:21 +053072 'Grade': '',
73 'Feed': '',
74 'Expense Claim Type': ['Travel', 'Medical', 'Calls', 'Food', 'Others'],
75 'Event': '',
76 'Employment Type': '',
77 'Employee': '',
78 'Earning Type': ['Basic', 'Conveyance', 'House Rent Allowance', 'Dearness Allowance',
Nabin Hait1c990352012-07-09 15:25:08 +053079 'Medical Allowance', 'Telephone'],
Nabin Haitbffbc182013-03-12 10:41:21 +053080 'Designation': '',
81 'Department': '',
82 'Deduction Type': ['Income Tax', 'Professional Tax', 'Provident Fund', 'Leave Deduction'],
83 'Customer Group': ['All Customer Groups', 'Default Customer Group'],
84 'Customer': '',
85 'Cost Center': '',
86 'Contact': '',
87 'Campaign': '',
88 'Budget Distribution': '',
89 'Brand': '',
90 'Branch': '',
91 'Batch': '',
92 'Appraisal': '',
93 'Account': '',
Nabin Hait1c990352012-07-09 15:25:08 +053094 'BOM': ''
95 }
96 for d in masters.keys():
97 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' \
98 and fieldtype='Table'" % d):
99 webnotes.conn.sql("delete from `tab%s`" % (t))
100 lst = '"'+'","'.join(masters[d])+ '"'
101 webnotes.conn.sql("delete from `tab%s` where name not in (%s)" % (d, lst))
Nabin Hait1c990352012-07-09 15:25:08 +0530102 print "Deleted " + d
103
104
105
Nabin Hait82efcc72012-09-18 11:19:34 +0530106def reset_all_series():
107 # Reset master series
108 webnotes.conn.sql("""update tabSeries set current = 0 where name not in
109 ('Ann/', 'BSD', 'DEF', 'DF', 'EV', 'Event Updates/', 'FileData-',
110 'FL', 'FMD/', 'GLM Detail', 'Login Page/', 'MDI', 'MDR', 'MI', 'MIR',
111 'PERM', 'PR', 'SRCH/C/', 'TD', 'TIC/', 'TMD/', 'TW', 'UR', '_FEED',
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530112 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530113 """)
114 print "Series updated"
Nabin Hait82efcc72012-09-18 11:19:34 +0530115
116def reset_transaction_series():
117 webnotes.conn.sql("""update tabSeries set current = 0 where name in
118 ('JV', 'INV', 'BILL', 'SO', 'DN', 'PO', 'LEAD', 'ENQUIRY', 'ENQ', 'CI',
Nabin Haitbffbc182013-03-12 10:41:21 +0530119 'IN', 'PS', 'IDT', 'QAI', 'QTN', 'STE', 'SQTN', 'SUP', 'SR',
Nabin Hait82efcc72012-09-18 11:19:34 +0530120 'POS', 'LAP', 'LAL', 'EXP')""")
121 print "Series updated"
Nabin Hait1c990352012-07-09 15:25:08 +0530122
123
124def delete_main_masters():
Nabin Haitbffbc182013-03-12 10:41:21 +0530125 main_masters = ['Fiscal Year', 'Company', 'DefaultValue']
Nabin Hait1c990352012-07-09 15:25:08 +0530126 for d in main_masters:
127 for t in webnotes.conn.sql("select options from tabDocField where parent='%s' and fieldtype='Table'" % d):
128 webnotes.conn.sql("delete from `tab%s`" % (t))
129 webnotes.conn.sql("delete from `tab%s`" % (d))
Nabin Hait1c990352012-07-09 15:25:08 +0530130 print "Deleted " + d
Nabin Hait1c990352012-07-09 15:25:08 +0530131
132def reset_global_defaults():
133 flds = {
Nabin Haitbffbc182013-03-12 10:41:21 +0530134 'default_company': None,
135 'default_currency': None,
136 'current_fiscal_year': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530137 'date_format': 'dd-mm-yyyy',
Nabin Haitbffbc182013-03-12 10:41:21 +0530138 'sms_sender_name': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530139 'default_item_group': 'Default',
140 'default_stock_uom': 'Nos',
141 'default_valuation_method': 'FIFO',
142 'default_warehouse_type': 'Default Warehouse Type',
Nabin Haitbffbc182013-03-12 10:41:21 +0530143 'tolerance': None,
144 'acc_frozen_upto': None,
145 'bde_auth_role': None,
146 'credit_controller': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530147 'default_customer_group': 'Default Customer Group',
148 'default_territory': 'Default',
149 'default_price_list': 'Standard',
Nabin Haitbffbc182013-03-12 10:41:21 +0530150 'default_supplier_type': 'Default Supplier Type',
151 'hide_currency_symbol': None,
152 'default_price_list_currency': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530153 }
154
155 from webnotes.model.code import get_obj
156 gd = get_obj('Global Defaults', 'Global Defaults')
157 for d in flds:
158 gd.doc.fields[d] = flds[d]
159 gd.doc.save()
160
161 webnotes.clear_cache()
162
163
164def run():
165 webnotes.connect()
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200166 webnotes.conn.begin()
Nabin Hait1c990352012-07-09 15:25:08 +0530167
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
Nabin Hait82efcc72012-09-18 11:19:34 +0530187 if cleanup_type == '1':
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200188 print "Reset Transaction Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530189 reset_transaction_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530190 else:
191 delete_masters()
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200192 print "Reset All Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530193 reset_all_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530194 delete_main_masters()
195 reset_global_defaults()
196
197 print "System cleaned up succesfully"
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200198 webnotes.conn.commit()
Nabin Hait1c990352012-07-09 15:25:08 +0530199 webnotes.conn.close()
200
201
202if __name__ == '__main__':
203 run()