blob: 328eed1296e51e1489f7545787482781b0e1f3a9 [file] [log] [blame]
Rushabh Mehtaad45e312013-11-20 12:59:58 +05301# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302# License: GNU General Public License v3. See license.txt
3
Nabin Hait1c990352012-07-09 15:25:08 +05304#!/usr/bin/python
5
6# This script is for cleaning up of all data from system including
7# all transactions and masters (excludes default masters).
8# Basically after running this file, system will reset to it's
9# initial state.
10# This script can be executed from lib/wnf.py using
11# lib/wnf.py --cleanup-data
12
Anand Doshi486f9df2012-07-19 13:40:31 +053013from __future__ import unicode_literals
Nabin Hait1c990352012-07-09 15:25:08 +053014import sys
15sys.path.append("lib/py")
16sys.path.append(".")
17sys.path.append("erpnext")
18
Rushabh Mehta793ba6b2014-02-14 15:47:51 +053019import frappe
Nabin Hait1c990352012-07-09 15:25:08 +053020
21#--------------------------------
22
23def delete_transactions():
24 print "Deleting transactions..."
25
Nabin Haitac24d0f2013-07-01 14:03:08 +053026 trans = ['Task', 'Support Ticket', 'Stock Reconciliation', 'Stock Ledger Entry',
Nabin Haitbffbc182013-03-12 10:41:21 +053027 'Stock Entry', 'Sales Order', 'Salary Slip','Sales Invoice', 'Quotation',
28 'Quality Inspection', 'Purchase Receipt', 'Purchase Order', 'Production Order',
29 'POS Setting', 'Period Closing Voucher', 'Purchase Invoice', 'Maintenance Visit',
30 'Maintenance Schedule', 'Leave Application', 'Leave Allocation', 'Lead', 'Journal Voucher',
31 'Installation Note', 'Material Request', 'GL Entry', 'Expense Claim', 'Opportunity',
32 'Delivery Note', 'Customer Issue', 'Bin', 'Authorization Rule', 'Attendance', 'C-Form',
Nabin Haitac24d0f2013-07-01 14:03:08 +053033 'Appraisal', 'Installation Note', 'Communication', "Supplier Quotation", "Newsletter",
34 "Job Applicant", "Web Page", "Website Slideshow", "Blog Post", "Blog Category", "Blogger",
35 "Time Log", "Time Log Batch", "Workflow"]
Nabin Hait1c990352012-07-09 15:25:08 +053036 for d in trans:
Nabin Hait4d713ac2014-03-03 15:51:13 +053037 for t in frappe.db.sql("select options from tabDocField \
38 where parent=%s and fieldtype='Table'", d):
Anand Doshie9baaa62014-02-26 12:35:33 +053039 frappe.db.sql("delete from `tab%s`" % (t))
40 frappe.db.sql("delete from `tab%s`" % (d))
Nabin Hait1c990352012-07-09 15:25:08 +053041 print "Deleted " + d
42
43
44
45def delete_masters():
46 print "Deleting masters...."
47 masters = {
Nabin Haitbffbc182013-03-12 10:41:21 +053048 'Workstation': ['Default Workstation'],
Nabin Haitbffbc182013-03-12 10:41:21 +053049 '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': '',
Nabin Haitcfecd2b2013-07-11 17:49:18 +053057 'Sales Person': ['Sales Team'],
Nabin Haitbffbc182013-03-12 10:41:21 +053058 '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 'Sales Taxes and Charges Master': '',
66 'Letter Head': '',
67 'Leave Type': ['Leave Without Pay', 'Privilege Leave', 'Casual Leave', 'PL', 'CL', 'LWP',
Nabin Hait1c990352012-07-09 15:25:08 +053068 'Compensatory Off', 'Sick Leave'],
Nabin Haitbffbc182013-03-12 10:41:21 +053069 'Appraisal Template': '',
70 'Item Group': ['All Item Groups', 'Default'],
71 'Item': '',
72 'Holiday List': '',
Nabin Haitac24d0f2013-07-01 14:03:08 +053073 'Activity Type': '',
Nabin Haitbffbc182013-03-12 10:41:21 +053074 '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',
Nabin Hait1c990352012-07-09 15:25:08 +053081 'Medical Allowance', 'Telephone'],
Nabin Haitbffbc182013-03-12 10:41:21 +053082 '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': '',
Nabin Hait1c990352012-07-09 15:25:08 +053096 'BOM': ''
97 }
98 for d in masters.keys():
Nabin Hait4d713ac2014-03-03 15:51:13 +053099 for t in frappe.db.sql("select options from tabDocField where parent=%s \
100 and fieldtype='Table'", d):
101 frappe.db.sql("delete from `tab%s`" % (t))
102 frappe.db.sql("delete from `tab%s` where name not in (%s)" %
103 (d, ', '.join(['%s']*len(masters[d]), masters[d])))
Nabin Hait1c990352012-07-09 15:25:08 +0530104 print "Deleted " + d
105
106
107
Nabin Hait82efcc72012-09-18 11:19:34 +0530108def reset_all_series():
109 # Reset master series
Anand Doshie9baaa62014-02-26 12:35:33 +0530110 frappe.db.sql("""update tabSeries set current = 0 where name not in
Nabin Hait82efcc72012-09-18 11:19:34 +0530111 ('Ann/', 'BSD', 'DEF', 'DF', 'EV', 'Event Updates/', 'FileData-',
112 'FL', 'FMD/', 'GLM Detail', 'Login Page/', 'MDI', 'MDR', 'MI', 'MIR',
113 'PERM', 'PR', 'SRCH/C/', 'TD', 'TIC/', 'TMD/', 'TW', 'UR', '_FEED',
Nabin Hait94a6c7e2012-07-09 16:06:53 +0530114 '_SRCH', '_TRIGGER', '__NSO', 'CustomField', 'Letter')
Nabin Hait1c990352012-07-09 15:25:08 +0530115 """)
116 print "Series updated"
Nabin Hait82efcc72012-09-18 11:19:34 +0530117
118def reset_transaction_series():
Anand Doshie9baaa62014-02-26 12:35:33 +0530119 frappe.db.sql("""update tabSeries set current = 0 where name in
Nabin Hait82efcc72012-09-18 11:19:34 +0530120 ('JV', 'INV', 'BILL', 'SO', 'DN', 'PO', 'LEAD', 'ENQUIRY', 'ENQ', 'CI',
Nabin Haitbffbc182013-03-12 10:41:21 +0530121 'IN', 'PS', 'IDT', 'QAI', 'QTN', 'STE', 'SQTN', 'SUP', 'SR',
Nabin Hait82efcc72012-09-18 11:19:34 +0530122 'POS', 'LAP', 'LAL', 'EXP')""")
123 print "Series updated"
Nabin Hait1c990352012-07-09 15:25:08 +0530124
125
126def delete_main_masters():
Nabin Haitbffbc182013-03-12 10:41:21 +0530127 main_masters = ['Fiscal Year', 'Company', 'DefaultValue']
Nabin Hait1c990352012-07-09 15:25:08 +0530128 for d in main_masters:
Nabin Hait4d713ac2014-03-03 15:51:13 +0530129 for t in frappe.db.sql("select options from tabDocField \
130 where parent=%s and fieldtype='Table'", d):
Anand Doshie9baaa62014-02-26 12:35:33 +0530131 frappe.db.sql("delete from `tab%s`" % (t))
132 frappe.db.sql("delete from `tab%s`" % (d))
Nabin Hait1c990352012-07-09 15:25:08 +0530133 print "Deleted " + d
Nabin Hait1c990352012-07-09 15:25:08 +0530134
135def reset_global_defaults():
136 flds = {
Nabin Haitbffbc182013-03-12 10:41:21 +0530137 'default_company': None,
138 'default_currency': None,
139 'current_fiscal_year': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530140 'date_format': 'dd-mm-yyyy',
Nabin Haitbffbc182013-03-12 10:41:21 +0530141 'sms_sender_name': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530142 'default_item_group': 'Default',
143 'default_stock_uom': 'Nos',
144 'default_valuation_method': 'FIFO',
Nabin Haitbffbc182013-03-12 10:41:21 +0530145 'tolerance': None,
146 'acc_frozen_upto': None,
147 'bde_auth_role': None,
148 'credit_controller': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530149 'default_customer_group': 'Default Customer Group',
150 'default_territory': 'Default',
151 'default_price_list': 'Standard',
Nabin Haitbffbc182013-03-12 10:41:21 +0530152 'default_supplier_type': 'Default Supplier Type',
153 'hide_currency_symbol': None,
154 'default_price_list_currency': None,
Nabin Hait1c990352012-07-09 15:25:08 +0530155 }
156
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530157 from frappe.model.code import get_obj
Nabin Hait1c990352012-07-09 15:25:08 +0530158 gd = get_obj('Global Defaults', 'Global Defaults')
159 for d in flds:
Anand Doshif78d1ae2014-03-28 13:55:00 +0530160 gd.set(d, flds[d])
161 gd.save()
Nabin Hait1c990352012-07-09 15:25:08 +0530162
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530163 frappe.clear_cache()
Nabin Hait1c990352012-07-09 15:25:08 +0530164
165
166def run():
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530167 frappe.connect()
Anand Doshie9baaa62014-02-26 12:35:33 +0530168 frappe.db.begin()
Nabin Hait1c990352012-07-09 15:25:08 +0530169
170 # Confirmation from user
171 confirm = ''
172 while not confirm:
173 confirm = raw_input("Are you sure you want to delete the data from the system (N/Y)?")
174 if confirm.lower() != 'y':
175 raise Exception
176
177 cleanup_type = ''
178 while cleanup_type not in ['1', '2']:
179 cleanup_type = raw_input("""\nWhat type of cleanup you want ot perform?
180 1. Only Transactions
181 2. Both Masters and Transactions
182
183 Please enter your choice (1/2):
184 """)
185
186 # delete
187 delete_transactions()
188
Nabin Hait82efcc72012-09-18 11:19:34 +0530189 if cleanup_type == '1':
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200190 print "Reset Transaction Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530191 reset_transaction_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530192 else:
193 delete_masters()
Rushabh Mehta4b41afd2012-10-09 15:19:59 +0200194 print "Reset All Series"
Nabin Hait82efcc72012-09-18 11:19:34 +0530195 reset_all_series()
Nabin Hait1c990352012-07-09 15:25:08 +0530196 delete_main_masters()
197 reset_global_defaults()
198
199 print "System cleaned up succesfully"
Anand Doshie9baaa62014-02-26 12:35:33 +0530200 frappe.db.commit()
201 frappe.db.close()
Nabin Hait1c990352012-07-09 15:25:08 +0530202
203
204if __name__ == '__main__':
205 run()