blob: e78a82ef180d7c8a6ffd9c55b380262cd9147931 [file] [log] [blame]
nabinhaitec097972011-07-01 13:34:41 +05301#Cleanup all unwanted documents and restructure of moduloes
2#----------------------------------------------------------
3
4import webnotes
5from webnotes.model import delete_doc
6from webnotes.modules.module_manager import reload_doc
7from webnotes.modules.export_module import export_to_files
8sql = webnotes.conn.sql
9
10
11#----------------------------
12
13def delete_unwanted_doctypes():
14 "deletes doctypes which are not used anymore"
15
nabinhait6727a9c2011-07-06 10:27:35 +053016 try:
17 sql("delete from `tabMenu Item`")
18 sql("delete from tabDocField where fieldname = 'site_map_details' and parent ='Control Panel'")
19 except:
20 pass
21
nabinhait5773efd2011-07-06 10:23:03 +053022 lst = ['Zone', 'WN Account Control', 'Wiki Page', 'Wiki History', 'Wiki Control', 'While You Were Out', 'Web Visitor', 'Tweet', 'Transfer Utility', 'Transfer Module', 'Transfer Control', 'Transfer Account', 'Tips Common', 'TestTabDT', 'TestDT', 'Test Type', 'Test Run', 'Test Record Detail', 'Test Record', 'Test Case', 'Supplier TDS Category Detail', 'Shopping Cart Control', 'Service Series', 'Series Detail', 'Rule Engine', 'RFQ', 'Report Filter Detail', 'Report Field Detail','Report Control', 'Rating Widget Record', 'Rating Widget Control', 'Rating Template Detail', 'Rating Template', 'PV Ded Tax Detail', 'PV Add Tax Detail', 'Product Variant', 'Product Variance', 'Product Group', 'Product Feature', 'Payroll Tips Common', 'Payroll Rule', 'Password Control', 'Page Visit', 'Patch', 'Multiple Transfer', 'Module Tip Control', 'Module Setter', 'Module Manager', 'Module Import', 'Module Detail', 'Message Control', 'Message', 'Mail Participant Details', 'Mail', 'Leave Type Detail', 'Leave Detail', 'Leave Applicable Detail', 'Lead Item Detail', 'Lead Attachment Detail', 'Item Attachments Detail', 'Instant Message', 'Impact Analysis', 'Forum Topic', 'Forum Control', 'Form Settings', 'Follower', 'ERP Setup', 'Enquiry Attachment Detail', 'Documentation', 'Condition Detail', 'Complaint Note', 'Code History', 'Code Editor', 'Code Backup Control', 'Code Backup', 'City', 'Change Log', 'Business Letter Type', 'Business Letter Template', 'Business Letter', 'Badge Settings Detail', 'Application Type', 'Application', 'Action Detail', 'Accounts Setup', 'Stock Common', 'Job Application', 'Service Schedule', 'Comment Control', 'Bank', 'Tag Widget Control', 'Feature Update', 'RFQ Detail', 'Supplier Quotation Detail', 'Supplier Quotation', 'Year Closing Voucher', 'Approval Structure', 'Site Map Detail', 'Menu Control', 'Menu Item', 'Menu Item Role'] # bank
23 for d in lst:
24 try:
nabinhait41534b32011-07-04 14:27:33 +053025 sql("delete from `tabProperty Setter` where select_doctype = '%s'" % d)
26 sql("delete from `tabCustom Script` where dt = '%s'" % d)
27 sql("delete from `tabCustom Field` where dt = '%s'" % d)
28 delete_doc('DocType', d)
nabinhait5773efd2011-07-06 10:23:03 +053029 except:
30 pass
nabinhait5de1b7e2011-07-04 13:41:42 +053031
nabinhaitec097972011-07-01 13:34:41 +053032
33 sql("commit")
34 delete_tables(lst)
35
36def delete_tables(lst):
37 for d in lst:
38 for t in ['tab', 'arc']:
39 try:
40 sql("drop table `%s%s`" % (t, d))
41 except:
42 continue
43
44def delete_unwanted_pages():
45 "deletes pages which are not used anymore"
nabinhait0d7056b2011-07-04 13:29:01 +053046 lst = ['Transaction Authorization', 'Prduct Display', 'Data Import', 'Partner Home', 'Product Display', 'Module Settings', 'About Us', 'Custom Reports', 'MIS', 'MIS - Comparison Report', 'Monthly MIS', 'MyReports', 'Navigation Page', 'Point Race', 'Tag Widget', 'Widget Test', 'Yearly MIS']
nabinhaitec097972011-07-01 13:34:41 +053047 for d in lst:
nabinhait01389822011-07-06 10:30:19 +053048 try:
49 delete_doc('Page', d)
50 except:
51 pass
52
53
nabinhaitec097972011-07-01 13:34:41 +053054def delete_unwanted_search_criteria():
55 "deletes search criteria which are not used anymore"
56
nabinhaitbcfd0142011-07-04 13:08:39 +053057 sql("update `tabSearch Criteria` set module = 'HR' where name = 'salary_structure_details'")
58
nabinhait0d7056b2011-07-04 13:29:01 +053059 lst = ['_SRCH00002', '_SRCH00001', 'warranty-amc_summary1', 'test_so4', 'test_so3', 'test_so2', 'test_so1', 'test_so', 'test5', 'target_variance_report1', 'STDSRCH/00006', 'STDSRCH/00005', 'STDSRCH/00004', 'STDSRCH/00003', 'STDSRCH/00002', 'STDSRCH/00001', 'so_pending_items_6', 'so_pending_items_5', 'so_pending_items_3', 'so_pending_items_34', 'scrap', 'sales_report_test', 'salary_structure_details1', 'salary_structure_details2', 'salary_structure_details3', 'salary_slips1', 'projectwise_pending_qty_and_costs2', 'projectwise_pending_qty_and_costs1', 'projectwise_delivered_qty_and_costs1', 'projectwise_delivered_qty_and_costs2', 'New Search Criteria 1', 'monthly_salary_register2', 'monthly_salary_register1', 'installed_items','follow_up_history', 'follow_up_report', 'employee_in_company_experience2', 'employee_in_company_experience1', 'employee_in_company_experience', 'employee_details', 'employee_details1', 'employee_details2', 'employees_birthday1', 'draft_so_pending_items', 'draft_sales_orders', 'delivery_notewise_pending_qty_to_install', 'datewise_leave_report2', 'datewise_leave_report1', 'datewise_leave_report', 'customer_issues1', 'cancelled_so_pending_items1', 'cancelled_so_pending_items', 'budget_variance_report3', 'budget_variance_report1', 'account_-_inputs_rg_23_a_-_part_ii_wrong_one', 'territory_item_group_wise_gp', 'sales_orderwise_pending_packing_item_summary', 'itemwise_trend', 'monthly_attendance_details_old', 'projectwise_contribution_report', 'projectwise_delivery_and_material_cost', 'projectwise_delivery_and_mat_cost_report', 'territorywise_trend', 'test_dn', 'rfq', 'rfq1']
nabinhaitec097972011-07-01 13:34:41 +053060
61 for d in lst:
nabinhaitd7e69f92011-07-04 12:46:38 +053062 if sql("select name from `tabSearch Criteria` where ifnull(standard, 'Yes') = 'Yes' and name = '%s'" % d):
nabinhait01389822011-07-06 10:30:19 +053063 try:
64 delete_doc('Search Criteria', d)
65 except:
66 pass
nabinhaitec097972011-07-01 13:34:41 +053067
68
69def delete_unwanted_mappers():
70 "deletes unwanted mappers"
71
nabinhaitcea316e2011-07-04 12:23:28 +053072 lst = ['Customer Issue-Maintenance Report', 'Enquiry-Service Quotation', 'Sales Order-Maintenance Report', 'Service Quotation-Service Order', 'Supplier Quotation-Purchase Order', 'Visit Schedule-Maintenance Report', 'RFQ-Supplier Quotation', 'Indent-RFQ']
nabinhaitec097972011-07-01 13:34:41 +053073 for d in lst:
nabinhait01389822011-07-06 10:30:19 +053074 try:
75 delete_doc('DocType Mapper', d)
76 except:
77 pass
78
nabinhaitec097972011-07-01 13:34:41 +053079def delete_unwanted_modules():
80 "deletes unwanted modules"
nabinhaitb2041c42011-07-04 13:51:08 +053081 lst = ['Development', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
nabinhaitec097972011-07-01 13:34:41 +053082 for d in lst:
nabinhait01389822011-07-06 10:30:19 +053083 try:
84 delete_doc('Module Def', d)
85 except:
86 pass
nabinhaitec097972011-07-01 13:34:41 +053087
88#---------------------------------------------
89
90def rename_merge_modules():
91 "Rename module as per users view and merge for removing confusion"
92
93 rename_lst = [['CRM', 'Selling'], ['SRM','Buying'], ['Material Management', 'Stock'], ['Payroll','HR'], ['Maintenance', 'Support']]
94 for d in rename_lst:
95 # create new module manually and export to file???????
nabinhaitd4403c32011-07-01 19:26:59 +053096 reload_doc(d[1].lower(), 'Module Def', d[1])
nabinhaitec097972011-07-01 13:34:41 +053097
98 merge_lst = [['Tools', 'Utilities'], ['Application Internal', 'Utilities'], ['Settings', 'Setup']]
99 # settings hardcoded in my_company
100 # module hardcoded in home_control
101 # material_management hardcoded in installation note
102 # maintenance hardcoded in support_email_settings
103
104 lst = rename_lst + merge_lst
105 for d in lst:
106 update_module(d[0], d[1])
nabinhait33ed7092011-07-06 10:33:31 +0530107 try:
108 delete_doc('Module Def', d[0])
109 except:
110 pass
nabinhaitd4403c32011-07-01 19:26:59 +0530111 reload_doc('Utilities', 'Module Def', 'Utilities')
nabinhaitec097972011-07-01 13:34:41 +0530112
113def update_module(from_mod, to_mod):
114 for t in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
115 sql("update `tab%s` set module='%s' where module = '%s'"% (t, to_mod, from_mod))
116
117#------------------------------------
118def sync_roles():
119 "Put Roles into corresponding module and delete Roles module"
120
121 # roles
122 roles = {
nabinhait301e3c32011-07-04 13:47:28 +0530123 'Accounts' : "'Accounts Manager', 'Accounts User', 'Auditor'",
nabinhaitec097972011-07-01 13:34:41 +0530124 'Selling' : "'Customer', 'Sales User', 'Sales Manager', 'Sales Master Manager', 'Partner'",
125 'Buying' : "'Supplier', 'Purchase User', 'Purchase Manager', 'Purchase Master Manager'",
126 'Stock' : "'Material User', 'Material Master Manager', 'Material Manager', 'Quality Manager'",
127 'Support' : "'Support Team', 'Support Manager', 'Maintenance User', 'Maintenance Manager'",
128 'Production': "'Production User', 'Production Manager', 'Production Master Manager'",
129 'Setup' : "'System Manager'",
130 'Projects' : "'Projects User'",
131 'HR' : "'HR User', 'HR Manager', 'Employee'",
132 'Core' : "'Administrator', 'All', 'Guest'"
133 }
134 for mod in roles.keys():
135 sql("update `tabRole` set module = '%s' where name in (%s)" % (mod, roles[mod]))
136
137 sql("update `tabDocType` set module = 'Setup' where name = 'Role'")
nabinhait33ed7092011-07-06 10:33:31 +0530138 try:
139
140 delete_doc('Module Def', 'Roles')
141 except:
142 pass
nabinhaitec097972011-07-01 13:34:41 +0530143#------------------------------------
144def sync_mapper():
145 "Put mappers into corresponding module"
146
147 mappers = {
148 'Accounts': ('Delivery Note-Receivable Voucher', 'Project-Receivable Voucher', 'Purchase Order-Payable Voucher', 'Purchase Receipt-Payable Voucher', 'Sales Order-Receivable Voucher'),
149 'Selling': ('Delivery Note-Installation Note', 'Enquiry-Quotation', 'Lead-Enquiry', 'Lead-Customer', 'Project-Sales Order', 'Quotation-Sales Order', ),
150 'Buying': ('Indent-Purchase Order', 'Sales Order-Indent'),
151 'Stock': ('Purchase Order-Purchase Receipt', 'Project-Delivery Note', 'Receivable Voucher-Delivery Note', 'Sales Order-Delivery Note'),
152 'Support': ('Customer Issue-Maintenance Visit', 'Sales Order-Maintenance Schedule', 'Sales Order-Maintenance Visit'),
153 'Production': ('Production Forecast-Production Plan', 'Production Forecast-Production Planning Tool', 'Sales Order-Production Plan'),
154 'HR': ('KRA Template-Appraisal', 'Salary Structure-Salary Slip')
155 }
156
157 for mod in mappers.keys():
158 sql("update `tabDocType Mapper` set module = '%s' where name in %s" % (mod, mappers[mod]))
nabinhait33ed7092011-07-06 10:33:31 +0530159 try:
160 delete_doc('Module Def', 'Mapper')
161 except:
162 pass
nabinhaitec097972011-07-01 13:34:41 +0530163# --------------------------------------
nabinhait963f36b2011-07-01 15:47:42 +0530164# function below will be run only in localhost
165'''def export_docs():
nabinhaitec097972011-07-01 13:34:41 +0530166 """
167 Export all documents where module has been changed
168 """
169 for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
170 lst = sql("select name, module from `tab%s`" % dtype)
171 for rec in lst:
172 webnotes.msgprint(rec)
nabinhait963f36b2011-07-01 15:47:42 +0530173 if rec and rec[0] and rec[1]:
174 export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
nabinhaitec097972011-07-01 13:34:41 +0530175
176 #grep test company
nabinhait963f36b2011-07-01 15:47:42 +0530177'''
nabinhaitec097972011-07-01 13:34:41 +0530178
179#---------------------------------------
180def run_patches():
nabinhaitdfb34de2011-07-01 16:49:15 +0530181 # update module
nabinhait3eb03b22011-07-04 13:21:49 +0530182 dt_module = {'LC PR Detail':'Stock', 'Landed Cost Detail':'Stock', 'Comment Widget Record': 'Core', 'Tag':'Core', 'Tag Detail': 'Core', 'POS Settings': 'Accounts', 'Menu Item': 'Setup', 'Menu Item Role': 'Setup'}
nabinhaitdfb34de2011-07-01 16:49:15 +0530183 for d in dt_module.keys():
184 sql("update `tabDocType` set module = '%s' where name = '%s'" % (dt_module[d], d))
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530185 delete_unwanted_mappers()
nabinhaitec097972011-07-01 13:34:41 +0530186 delete_unwanted_doctypes()
187 sql("start transaction")
188 delete_unwanted_pages()
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530189
nabinhaitec097972011-07-01 13:34:41 +0530190 delete_unwanted_search_criteria()
nabinhait059a0512011-07-04 13:44:05 +0530191
nabinhaitbcfd0142011-07-04 13:08:39 +0530192
nabinhaitec097972011-07-01 13:34:41 +0530193 rename_merge_modules()
194 sync_roles()
195 sync_mapper()
nabinhait059a0512011-07-04 13:44:05 +0530196 delete_unwanted_modules()
nabinhaitec097972011-07-01 13:34:41 +0530197 # landed cost wizard link in stock
Nabin Haita74f12a2011-07-27 13:11:39 +0530198 reload_doc('stock', 'Module Def', 'Stock')
nabinhait963f36b2011-07-01 15:47:42 +0530199
nabinhaitec097972011-07-01 13:34:41 +0530200 sql("commit")