blob: bd4742f3015f615ea0ff7884058fe3e3a0dd3acf [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
nabinhaitd6660c02011-07-04 12:32:41 +053016 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'] # bank
nabinhaitec097972011-07-01 13:34:41 +053017 for d in lst:
18 sql("delete from `tabProperty Setter` where select_doctype = '%s'" % d)
19 sql("delete from `tabCustom Script` where dt = '%s'" % d)
20 sql("delete from `tabCustom Field` where dt = '%s'" % d)
21 delete_doc('DocType', d)
22
23 sql("commit")
24 delete_tables(lst)
25
26def delete_tables(lst):
27 for d in lst:
28 for t in ['tab', 'arc']:
29 try:
30 sql("drop table `%s%s`" % (t, d))
31 except:
32 continue
33
34def delete_unwanted_pages():
35 "deletes pages which are not used anymore"
nabinhait963f36b2011-07-01 15:47:42 +053036 lst = ['Transaction Authorization', 'Prduct Display', 'Data Import', 'Partner Home', 'Product Display', 'Module Settings']
nabinhaitec097972011-07-01 13:34:41 +053037 for d in lst:
38 delete_doc('Page', d)
39
40def delete_unwanted_search_criteria():
41 "deletes search criteria which are not used anymore"
42
nabinhaitd72a2012011-07-04 12:39:52 +053043 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']
nabinhaitec097972011-07-01 13:34:41 +053044
45 for d in lst:
nabinhaitd7e69f92011-07-04 12:46:38 +053046 if sql("select name from `tabSearch Criteria` where ifnull(standard, 'Yes') = 'Yes' and name = '%s'" % d):
47 delete_doc('Search Criteria', d)
nabinhaitec097972011-07-01 13:34:41 +053048
49
50def delete_unwanted_mappers():
51 "deletes unwanted mappers"
52
nabinhaitcea316e2011-07-04 12:23:28 +053053 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 +053054 for d in lst:
55 delete_doc('DocType Mapper', d)
56
57def delete_unwanted_modules():
58 "deletes unwanted modules"
nabinhait963f36b2011-07-01 15:47:42 +053059 lst = ['Development', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'System', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
nabinhaitec097972011-07-01 13:34:41 +053060 for d in lst:
61 delete_doc('Module Def', d)
62
63
64#---------------------------------------------
65
66def rename_merge_modules():
67 "Rename module as per users view and merge for removing confusion"
68
69 rename_lst = [['CRM', 'Selling'], ['SRM','Buying'], ['Material Management', 'Stock'], ['Payroll','HR'], ['Maintenance', 'Support']]
70 for d in rename_lst:
71 # create new module manually and export to file???????
nabinhaitd4403c32011-07-01 19:26:59 +053072 reload_doc(d[1].lower(), 'Module Def', d[1])
nabinhaitec097972011-07-01 13:34:41 +053073
74 merge_lst = [['Tools', 'Utilities'], ['Application Internal', 'Utilities'], ['Settings', 'Setup']]
75 # settings hardcoded in my_company
76 # module hardcoded in home_control
77 # material_management hardcoded in installation note
78 # maintenance hardcoded in support_email_settings
79
80 lst = rename_lst + merge_lst
81 for d in lst:
82 update_module(d[0], d[1])
83 delete_doc('Module Def', d[0])
nabinhaitd4403c32011-07-01 19:26:59 +053084 reload_doc('Utilities', 'Module Def', 'Utilities')
nabinhaitec097972011-07-01 13:34:41 +053085
86def update_module(from_mod, to_mod):
87 for t in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
88 sql("update `tab%s` set module='%s' where module = '%s'"% (t, to_mod, from_mod))
89
90#------------------------------------
91def sync_roles():
92 "Put Roles into corresponding module and delete Roles module"
93
94 # roles
95 roles = {
96 'Accounts' : "'Accounts Manager', 'Accounts User'",
97 'Selling' : "'Customer', 'Sales User', 'Sales Manager', 'Sales Master Manager', 'Partner'",
98 'Buying' : "'Supplier', 'Purchase User', 'Purchase Manager', 'Purchase Master Manager'",
99 'Stock' : "'Material User', 'Material Master Manager', 'Material Manager', 'Quality Manager'",
100 'Support' : "'Support Team', 'Support Manager', 'Maintenance User', 'Maintenance Manager'",
101 'Production': "'Production User', 'Production Manager', 'Production Master Manager'",
102 'Setup' : "'System Manager'",
103 'Projects' : "'Projects User'",
104 'HR' : "'HR User', 'HR Manager', 'Employee'",
105 'Core' : "'Administrator', 'All', 'Guest'"
106 }
107 for mod in roles.keys():
108 sql("update `tabRole` set module = '%s' where name in (%s)" % (mod, roles[mod]))
109
110 sql("update `tabDocType` set module = 'Setup' where name = 'Role'")
111 delete_doc('Module Def', 'Roles')
112
113#------------------------------------
114def sync_mapper():
115 "Put mappers into corresponding module"
116
117 mappers = {
118 'Accounts': ('Delivery Note-Receivable Voucher', 'Project-Receivable Voucher', 'Purchase Order-Payable Voucher', 'Purchase Receipt-Payable Voucher', 'Sales Order-Receivable Voucher'),
119 'Selling': ('Delivery Note-Installation Note', 'Enquiry-Quotation', 'Lead-Enquiry', 'Lead-Customer', 'Project-Sales Order', 'Quotation-Sales Order', ),
120 'Buying': ('Indent-Purchase Order', 'Sales Order-Indent'),
121 'Stock': ('Purchase Order-Purchase Receipt', 'Project-Delivery Note', 'Receivable Voucher-Delivery Note', 'Sales Order-Delivery Note'),
122 'Support': ('Customer Issue-Maintenance Visit', 'Sales Order-Maintenance Schedule', 'Sales Order-Maintenance Visit'),
123 'Production': ('Production Forecast-Production Plan', 'Production Forecast-Production Planning Tool', 'Sales Order-Production Plan'),
124 'HR': ('KRA Template-Appraisal', 'Salary Structure-Salary Slip')
125 }
126
127 for mod in mappers.keys():
128 sql("update `tabDocType Mapper` set module = '%s' where name in %s" % (mod, mappers[mod]))
129
130 delete_doc('Module Def', 'Mapper')
131
132# --------------------------------------
nabinhait963f36b2011-07-01 15:47:42 +0530133# function below will be run only in localhost
134'''def export_docs():
nabinhaitec097972011-07-01 13:34:41 +0530135 """
136 Export all documents where module has been changed
137 """
138 for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
139 lst = sql("select name, module from `tab%s`" % dtype)
140 for rec in lst:
141 webnotes.msgprint(rec)
nabinhait963f36b2011-07-01 15:47:42 +0530142 if rec and rec[0] and rec[1]:
143 export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
nabinhaitec097972011-07-01 13:34:41 +0530144
145 #grep test company
nabinhait963f36b2011-07-01 15:47:42 +0530146'''
nabinhaitec097972011-07-01 13:34:41 +0530147
148#---------------------------------------
149def run_patches():
nabinhaitdfb34de2011-07-01 16:49:15 +0530150 # update module
nabinhaitcbbcdb582011-07-04 12:49:56 +0530151 dt_module = {'LC PR Detail':'Stock', 'Landed Cost Detail':'Stock', 'Comment Widget Record': 'Core', 'Tag':'Core', 'Tag Detail': 'Core', 'POS Settings': 'Accounts', 'Salary Structure Details': 'HR'}
nabinhaitdfb34de2011-07-01 16:49:15 +0530152 for d in dt_module.keys():
153 sql("update `tabDocType` set module = '%s' where name = '%s'" % (dt_module[d], d))
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530154 delete_unwanted_mappers()
nabinhaitec097972011-07-01 13:34:41 +0530155 delete_unwanted_doctypes()
156 sql("start transaction")
157 delete_unwanted_pages()
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530158
nabinhaitec097972011-07-01 13:34:41 +0530159 delete_unwanted_search_criteria()
160 delete_unwanted_modules()
161
162 rename_merge_modules()
163 sync_roles()
164 sync_mapper()
165
166
167 # landed cost wizard link in stock
168 reload_doc('stock', 'Module Def', 'stock')
nabinhait963f36b2011-07-01 15:47:42 +0530169
nabinhaitec097972011-07-01 13:34:41 +0530170 sql("commit")