blob: ecbd85ce399ee3c92aa69d432f76011c0ca8e2de [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
16 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', ]
17 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"
36 lst = ['Transaction Authorization', 'Prduct Display', 'Data Import', 'Partner Home', 'Product Display']
37 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
43 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']
44
45 for d in lst:
46 delete_doc('Search Criteria', d)
47
48
49def delete_unwanted_mappers():
50 "deletes unwanted mappers"
51
52 lst = ['Customer Issue-Maintenance Report', 'Enquiry-Service Quotation', 'Sales Order-Maintenance Report', 'Service Quotation-Service Order', 'Supplier Quotation-Purchase Order', 'Visit Schedule-Maintenance Report']
53 for d in lst:
54 delete_doc('DocType Mapper', d)
55
56def delete_unwanted_modules():
57 "deletes unwanted modules"
58 lst = ['Developent', 'Recycle Bin', 'Testing', 'Testing System', 'Test', 'System', 'Partner Updates', 'My Company', 'Event Updates', 'E-Commerce']
59 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???????
71 reload_doc(d[1], 'module_def', d[1])
72
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])
83
84
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# --------------------------------------
132def export_docs():
133 """
134 Export all documents where module has been changed
135 """
136 for dtype in ['DocType', 'Page', 'Search Criteria', 'DocType Mapper', 'Print Format', 'Role']:
137 lst = sql("select name, module from `tab%s`" % dtype)
138 for rec in lst:
139 webnotes.msgprint(rec)
140 export_to_files(record_list = [[dtype, rec[0]]], record_module = rec[1])
141
142 #grep test company
143
144
145#---------------------------------------
146def run_patches():
147 delete_unwanted_doctypes()
148 sql("start transaction")
149 delete_unwanted_pages()
150 delete_unwanted_mappers()
151 delete_unwanted_search_criteria()
152 delete_unwanted_modules()
153
154 rename_merge_modules()
155 sync_roles()
156 sync_mapper()
157
158
159 # landed cost wizard link in stock
160 reload_doc('stock', 'Module Def', 'stock')
161 sql("update `tabDocType` set module = 'stock' where name in ('LC PR Detail', 'Landed Cost Detail')")
162
163 export_docs()
164 sql("commit")