blob: b7b715903934c5d5da3f5329cff7a73f8088e0bd [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
nabinhait5de1b7e2011-07-04 13:41:42 +053016 sql("delete from `tabMenu Item`")
17
18
19 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
nabinhaitec097972011-07-01 13:34:41 +053020 for d in lst:
21 sql("delete from `tabProperty Setter` where select_doctype = '%s'" % d)
22 sql("delete from `tabCustom Script` where dt = '%s'" % d)
23 sql("delete from `tabCustom Field` where dt = '%s'" % d)
24 delete_doc('DocType', d)
25
26 sql("commit")
27 delete_tables(lst)
28
29def delete_tables(lst):
30 for d in lst:
31 for t in ['tab', 'arc']:
32 try:
33 sql("drop table `%s%s`" % (t, d))
34 except:
35 continue
36
37def delete_unwanted_pages():
38 "deletes pages which are not used anymore"
nabinhait0d7056b2011-07-04 13:29:01 +053039 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 +053040 for d in lst:
41 delete_doc('Page', d)
42
43def delete_unwanted_search_criteria():
44 "deletes search criteria which are not used anymore"
45
nabinhaitbcfd0142011-07-04 13:08:39 +053046 sql("update `tabSearch Criteria` set module = 'HR' where name = 'salary_structure_details'")
47
nabinhait0d7056b2011-07-04 13:29:01 +053048 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 +053049
50 for d in lst:
nabinhaitd7e69f92011-07-04 12:46:38 +053051 if sql("select name from `tabSearch Criteria` where ifnull(standard, 'Yes') = 'Yes' and name = '%s'" % d):
52 delete_doc('Search Criteria', d)
nabinhaitec097972011-07-01 13:34:41 +053053
54
55def delete_unwanted_mappers():
56 "deletes unwanted mappers"
57
nabinhaitcea316e2011-07-04 12:23:28 +053058 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 +053059 for d in lst:
60 delete_doc('DocType Mapper', d)
61
62def delete_unwanted_modules():
63 "deletes unwanted modules"
nabinhait963f36b2011-07-01 15:47:42 +053064 lst = ['Development', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'System', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
nabinhaitec097972011-07-01 13:34:41 +053065 for d in lst:
66 delete_doc('Module Def', d)
67
68
69#---------------------------------------------
70
71def rename_merge_modules():
72 "Rename module as per users view and merge for removing confusion"
73
74 rename_lst = [['CRM', 'Selling'], ['SRM','Buying'], ['Material Management', 'Stock'], ['Payroll','HR'], ['Maintenance', 'Support']]
75 for d in rename_lst:
76 # create new module manually and export to file???????
nabinhaitd4403c32011-07-01 19:26:59 +053077 reload_doc(d[1].lower(), 'Module Def', d[1])
nabinhaitec097972011-07-01 13:34:41 +053078
79 merge_lst = [['Tools', 'Utilities'], ['Application Internal', 'Utilities'], ['Settings', 'Setup']]
80 # settings hardcoded in my_company
81 # module hardcoded in home_control
82 # material_management hardcoded in installation note
83 # maintenance hardcoded in support_email_settings
84
85 lst = rename_lst + merge_lst
86 for d in lst:
87 update_module(d[0], d[1])
88 delete_doc('Module Def', d[0])
nabinhaitd4403c32011-07-01 19:26:59 +053089 reload_doc('Utilities', 'Module Def', 'Utilities')
nabinhaitec097972011-07-01 13:34:41 +053090
91def update_module(from_mod, to_mod):
92 for t in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
93 sql("update `tab%s` set module='%s' where module = '%s'"% (t, to_mod, from_mod))
94
95#------------------------------------
96def sync_roles():
97 "Put Roles into corresponding module and delete Roles module"
98
99 # roles
100 roles = {
101 'Accounts' : "'Accounts Manager', 'Accounts User'",
102 'Selling' : "'Customer', 'Sales User', 'Sales Manager', 'Sales Master Manager', 'Partner'",
103 'Buying' : "'Supplier', 'Purchase User', 'Purchase Manager', 'Purchase Master Manager'",
104 'Stock' : "'Material User', 'Material Master Manager', 'Material Manager', 'Quality Manager'",
105 'Support' : "'Support Team', 'Support Manager', 'Maintenance User', 'Maintenance Manager'",
106 'Production': "'Production User', 'Production Manager', 'Production Master Manager'",
107 'Setup' : "'System Manager'",
108 'Projects' : "'Projects User'",
109 'HR' : "'HR User', 'HR Manager', 'Employee'",
110 'Core' : "'Administrator', 'All', 'Guest'"
111 }
112 for mod in roles.keys():
113 sql("update `tabRole` set module = '%s' where name in (%s)" % (mod, roles[mod]))
114
115 sql("update `tabDocType` set module = 'Setup' where name = 'Role'")
116 delete_doc('Module Def', 'Roles')
117
118#------------------------------------
119def sync_mapper():
120 "Put mappers into corresponding module"
121
122 mappers = {
123 'Accounts': ('Delivery Note-Receivable Voucher', 'Project-Receivable Voucher', 'Purchase Order-Payable Voucher', 'Purchase Receipt-Payable Voucher', 'Sales Order-Receivable Voucher'),
124 'Selling': ('Delivery Note-Installation Note', 'Enquiry-Quotation', 'Lead-Enquiry', 'Lead-Customer', 'Project-Sales Order', 'Quotation-Sales Order', ),
125 'Buying': ('Indent-Purchase Order', 'Sales Order-Indent'),
126 'Stock': ('Purchase Order-Purchase Receipt', 'Project-Delivery Note', 'Receivable Voucher-Delivery Note', 'Sales Order-Delivery Note'),
127 'Support': ('Customer Issue-Maintenance Visit', 'Sales Order-Maintenance Schedule', 'Sales Order-Maintenance Visit'),
128 'Production': ('Production Forecast-Production Plan', 'Production Forecast-Production Planning Tool', 'Sales Order-Production Plan'),
129 'HR': ('KRA Template-Appraisal', 'Salary Structure-Salary Slip')
130 }
131
132 for mod in mappers.keys():
133 sql("update `tabDocType Mapper` set module = '%s' where name in %s" % (mod, mappers[mod]))
134
135 delete_doc('Module Def', 'Mapper')
136
137# --------------------------------------
nabinhait963f36b2011-07-01 15:47:42 +0530138# function below will be run only in localhost
139'''def export_docs():
nabinhaitec097972011-07-01 13:34:41 +0530140 """
141 Export all documents where module has been changed
142 """
143 for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
144 lst = sql("select name, module from `tab%s`" % dtype)
145 for rec in lst:
146 webnotes.msgprint(rec)
nabinhait963f36b2011-07-01 15:47:42 +0530147 if rec and rec[0] and rec[1]:
148 export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
nabinhaitec097972011-07-01 13:34:41 +0530149
150 #grep test company
nabinhait963f36b2011-07-01 15:47:42 +0530151'''
nabinhaitec097972011-07-01 13:34:41 +0530152
153#---------------------------------------
154def run_patches():
nabinhaitdfb34de2011-07-01 16:49:15 +0530155 # update module
nabinhait3eb03b22011-07-04 13:21:49 +0530156 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 +0530157 for d in dt_module.keys():
158 sql("update `tabDocType` set module = '%s' where name = '%s'" % (dt_module[d], d))
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530159 delete_unwanted_mappers()
nabinhaitec097972011-07-01 13:34:41 +0530160 delete_unwanted_doctypes()
161 sql("start transaction")
162 delete_unwanted_pages()
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530163
nabinhaitec097972011-07-01 13:34:41 +0530164 delete_unwanted_search_criteria()
165 delete_unwanted_modules()
nabinhaitbcfd0142011-07-04 13:08:39 +0530166
nabinhaitec097972011-07-01 13:34:41 +0530167 rename_merge_modules()
168 sync_roles()
169 sync_mapper()
170
nabinhaitec097972011-07-01 13:34:41 +0530171 # landed cost wizard link in stock
172 reload_doc('stock', 'Module Def', 'stock')
nabinhait963f36b2011-07-01 15:47:42 +0530173
nabinhaitec097972011-07-01 13:34:41 +0530174 sql("commit")