blob: 14e377c04faf58525cc1aac337a0bcb976d151df [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
nabinhait963f36b2011-07-01 15:47:42 +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'] # 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
nabinhaita42f54a2011-07-01 16:54:01 +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']
nabinhaitec097972011-07-01 13:34:41 +053044
45 for d in lst:
46 delete_doc('Search Criteria', d)
47
48
49def delete_unwanted_mappers():
50 "deletes unwanted mappers"
51
nabinhaitcea316e2011-07-04 12:23:28 +053052 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 +053053 for d in lst:
54 delete_doc('DocType Mapper', d)
55
56def delete_unwanted_modules():
57 "deletes unwanted modules"
nabinhait963f36b2011-07-01 15:47:42 +053058 lst = ['Development', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'System', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
nabinhaitec097972011-07-01 13:34:41 +053059 for d in lst:
60 delete_doc('Module Def', d)
61
62
63#---------------------------------------------
64
65def rename_merge_modules():
66 "Rename module as per users view and merge for removing confusion"
67
68 rename_lst = [['CRM', 'Selling'], ['SRM','Buying'], ['Material Management', 'Stock'], ['Payroll','HR'], ['Maintenance', 'Support']]
69 for d in rename_lst:
70 # create new module manually and export to file???????
nabinhaitd4403c32011-07-01 19:26:59 +053071 reload_doc(d[1].lower(), 'Module Def', d[1])
nabinhaitec097972011-07-01 13:34:41 +053072
73 merge_lst = [['Tools', 'Utilities'], ['Application Internal', 'Utilities'], ['Settings', 'Setup']]
74 # settings hardcoded in my_company
75 # module hardcoded in home_control
76 # material_management hardcoded in installation note
77 # maintenance hardcoded in support_email_settings
78
79 lst = rename_lst + merge_lst
80 for d in lst:
81 update_module(d[0], d[1])
82 delete_doc('Module Def', d[0])
nabinhaitd4403c32011-07-01 19:26:59 +053083 reload_doc('Utilities', 'Module Def', 'Utilities')
nabinhaitec097972011-07-01 13:34:41 +053084
85def update_module(from_mod, to_mod):
86 for t in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
87 sql("update `tab%s` set module='%s' where module = '%s'"% (t, to_mod, from_mod))
88
89#------------------------------------
90def sync_roles():
91 "Put Roles into corresponding module and delete Roles module"
92
93 # roles
94 roles = {
95 'Accounts' : "'Accounts Manager', 'Accounts User'",
96 'Selling' : "'Customer', 'Sales User', 'Sales Manager', 'Sales Master Manager', 'Partner'",
97 'Buying' : "'Supplier', 'Purchase User', 'Purchase Manager', 'Purchase Master Manager'",
98 'Stock' : "'Material User', 'Material Master Manager', 'Material Manager', 'Quality Manager'",
99 'Support' : "'Support Team', 'Support Manager', 'Maintenance User', 'Maintenance Manager'",
100 'Production': "'Production User', 'Production Manager', 'Production Master Manager'",
101 'Setup' : "'System Manager'",
102 'Projects' : "'Projects User'",
103 'HR' : "'HR User', 'HR Manager', 'Employee'",
104 'Core' : "'Administrator', 'All', 'Guest'"
105 }
106 for mod in roles.keys():
107 sql("update `tabRole` set module = '%s' where name in (%s)" % (mod, roles[mod]))
108
109 sql("update `tabDocType` set module = 'Setup' where name = 'Role'")
110 delete_doc('Module Def', 'Roles')
111
112#------------------------------------
113def sync_mapper():
114 "Put mappers into corresponding module"
115
116 mappers = {
117 'Accounts': ('Delivery Note-Receivable Voucher', 'Project-Receivable Voucher', 'Purchase Order-Payable Voucher', 'Purchase Receipt-Payable Voucher', 'Sales Order-Receivable Voucher'),
118 'Selling': ('Delivery Note-Installation Note', 'Enquiry-Quotation', 'Lead-Enquiry', 'Lead-Customer', 'Project-Sales Order', 'Quotation-Sales Order', ),
119 'Buying': ('Indent-Purchase Order', 'Sales Order-Indent'),
120 'Stock': ('Purchase Order-Purchase Receipt', 'Project-Delivery Note', 'Receivable Voucher-Delivery Note', 'Sales Order-Delivery Note'),
121 'Support': ('Customer Issue-Maintenance Visit', 'Sales Order-Maintenance Schedule', 'Sales Order-Maintenance Visit'),
122 'Production': ('Production Forecast-Production Plan', 'Production Forecast-Production Planning Tool', 'Sales Order-Production Plan'),
123 'HR': ('KRA Template-Appraisal', 'Salary Structure-Salary Slip')
124 }
125
126 for mod in mappers.keys():
127 sql("update `tabDocType Mapper` set module = '%s' where name in %s" % (mod, mappers[mod]))
128
129 delete_doc('Module Def', 'Mapper')
130
131# --------------------------------------
nabinhait963f36b2011-07-01 15:47:42 +0530132# function below will be run only in localhost
133'''def export_docs():
nabinhaitec097972011-07-01 13:34:41 +0530134 """
135 Export all documents where module has been changed
136 """
137 for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
138 lst = sql("select name, module from `tab%s`" % dtype)
139 for rec in lst:
140 webnotes.msgprint(rec)
nabinhait963f36b2011-07-01 15:47:42 +0530141 if rec and rec[0] and rec[1]:
142 export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
nabinhaitec097972011-07-01 13:34:41 +0530143
144 #grep test company
nabinhait963f36b2011-07-01 15:47:42 +0530145'''
nabinhaitec097972011-07-01 13:34:41 +0530146
147#---------------------------------------
148def run_patches():
nabinhaitdfb34de2011-07-01 16:49:15 +0530149 # update module
150 dt_module = {'LC PR Detail':'Stock', 'Landed Cost Detail':'Stock', 'Comment Widget Record': 'Core', 'Tag':'Core', 'Tag Detail': 'Core'}
151 for d in dt_module.keys():
152 sql("update `tabDocType` set module = '%s' where name = '%s'" % (dt_module[d], d))
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530153 delete_unwanted_mappers()
nabinhaitec097972011-07-01 13:34:41 +0530154 delete_unwanted_doctypes()
155 sql("start transaction")
156 delete_unwanted_pages()
nabinhaitb0c3bfc2011-07-04 12:18:24 +0530157
nabinhaitec097972011-07-01 13:34:41 +0530158 delete_unwanted_search_criteria()
159 delete_unwanted_modules()
160
161 rename_merge_modules()
162 sync_roles()
163 sync_mapper()
164
165
166 # landed cost wizard link in stock
167 reload_doc('stock', 'Module Def', 'stock')
nabinhait963f36b2011-07-01 15:47:42 +0530168
nabinhaitec097972011-07-01 13:34:41 +0530169 sql("commit")