blob: a7c25118c3477663d98b4170f2c085395f03cc17 [file] [log] [blame]
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05301# REMEMBER to update this
2# ========================
nabinhaita56fc002011-07-01 16:32:03 +05303
Nabin Haitd3b3eb22011-08-31 11:33:15 +05304
Brahma K3c9a6a12011-08-31 12:55:41 +05305last_patch = 352
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +05306
7#-------------------------------------------
8
9def execute(patch_no):
10 import webnotes
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053011 from webnotes.modules.module_manager import reload_doc
12
13 from webnotes.model.code import get_obj
14 sql = webnotes.conn.sql
15 from webnotes.utils import cint, cstr, flt
16 from webnotes.model.doc import Document
Rushabh Mehta33bce672011-08-25 15:15:25 +053017 from webnotes.model import delete_doc
Pratik Vyasc1e6e4c2011-06-08 14:37:15 +053018
Rushabh Mehta9e6e7fa2011-08-25 16:08:06 +053019 if patch_no == 301:
nabinhait690c6972011-06-28 14:42:07 +053020 from patches.delivery_billing_status_patch import run_patch
21 run_patch()
nabinhaitb3930002011-06-28 16:50:38 +053022 elif patch_no == 302:
23 sql("update `tabDocField` set no_copy = 1 where fieldname = 'naming_series'")
Ravi Dey4c651192011-06-28 19:36:18 +053024 elif patch_no == 303:
Ravi Dey27c5b402011-06-29 18:05:18 +053025 pass
26 elif patch_no == 304:
Rushabh Mehtac71eeb62011-06-30 08:28:36 +053027 sql("delete from `tabDocField` where parent = 'company' and label = 'Trash Company' and fieldtype = 'button'")
Ravi Deyc674e432011-06-29 18:15:12 +053028 reload_doc('setup', 'doctype', 'company')
Ravi Dey79c28652011-06-29 18:55:19 +053029 elif patch_no == 305:
30 sql("update `tabDocField` set options = 'link:Company' where options='link:Company' and fieldname='company' and fieldtype='Select'")
nabinhaitec097972011-07-01 13:34:41 +053031 elif patch_no == 306:
Ravi Dey94a332a2011-07-01 13:50:34 +053032 sql("update `tabDocField` set options = '\nAccount\nCompany\nCustomer\nSupplier\nEmployee\nWarehouse\nItem' where parent = 'Rename Tool' and fieldname = 'select_doctype'")
33 sql("update `tabDocField` set options = 'link:Item' where parent = 'Raw Materials Supplied' and fieldname = 'po_item'")
34 sql("update `tabDocField` set options = 'Sales Order' where parent = 'Indent Detail' and fieldname = 'sales_order_no'")
35 sql("update `tabDocField` set options = 'link:Company', fieldtype = 'Select' where parent = 'Stock Ledger Entry' and fieldname = 'company'")
Nabin Hait31a407d2011-07-28 11:47:45 +053036 reload_doc('utilities', 'doctype', 'rename_tool')
Ravi Dey627d01b2011-07-01 14:05:43 +053037 elif patch_no == 307:
38 sql("delete from `tabDocField` where parent = 'company' and label = 'Trash Company' and fieldtype = 'Button'")
39 reload_doc('setup', 'doctype', 'company')
nabinhaita56fc002011-07-01 16:32:03 +053040 elif patch_no == 308:
Ravi Deyc1886b52011-07-04 16:53:42 +053041 sql("update `tabDocField` set reqd = 0 where fieldname = 'select_item' and parent = 'Property Setter'")
nabinhait1bd56b12011-07-05 14:41:36 +053042 elif patch_no == 309:
43 sql("delete from `tabDocField` where fieldname = 'item_attachments_details' and parent = 'Item'")
nabinhait7f339e02011-07-05 15:43:17 +053044 sql("delete from `tabModule Def Item` where parent = 'Stock' and doc_name = 'Landed Cost Wizard'")
nabinhait5deab242011-07-06 09:23:02 +053045 elif patch_no == 310:
46 from erpnext_structure_cleanup import run_patches
47 run_patches()
nabinhait4bb8bf42011-07-06 10:11:11 +053048 elif patch_no == 311:
49 sql("update `tabDocField` set reqd = 0 where fieldname = 'select_item' and parent = 'Property Setter'")
nabinhait4c38fbb2011-07-06 10:36:53 +053050 #reload_doc('core', 'doctype', 'property_setter')
nabinhait4bb8bf42011-07-06 10:11:11 +053051 elif patch_no == 312:
52 sql("delete from `tabSessions`")
53 sql("delete from `__SessionCache`")
nabinhaitd54ec522011-07-06 12:20:21 +053054 elif patch_no == 313:
55 dt = ['GL Entry', 'Stock Ledger Entry']
56 for t in dt:
57 rec = sql("select voucher_type, voucher_no, ifnull(is_cancelled, 'No') from `tab%s` where modified >= '2011-07-06 10:00:00' group by voucher_no" % t)
58 for d in rec:
nabinhaitfccbb092011-07-06 12:23:27 +053059 sql("update `tab%s` set docstatus = %s where name = '%s'" % (d[0], d[2]=='No' and 1 or 2, d[1]))
Brahma K09307622011-07-27 12:03:34 +053060
nabinhaitd54ec522011-07-06 12:20:21 +053061 other_dt = ['Enquiry', 'Quotation', 'Sales Order', 'Indent', 'Purchase Order', 'Production Order', 'Customer Issue', 'Installation Note']
62 for dt in other_dt:
63 rec = sql("select name, status from `tab%s` where modified >= '2011-07-06 10:00:00'" % dt)
64 for r in rec:
65 sql("update `tab%s` set docstatus = %s where name = '%s'" % (dt, (r[1] in ['Submitted', 'Closed'] and 1 or r[1]=='Cancelled' and 2 or 0), r[0]))
Brahma K09307622011-07-27 12:03:34 +053066
67
nabinhaitd54ec522011-07-06 12:20:21 +053068 dt_list = ['Delivery Note', 'Purchase Receipt']
69 for dt in dt_list:
70 sql("update `tab%s` set status = 'Submitted' where docstatus = 1 and modified >='2011-07-06 10:00:00'" % dt)
71 sql("update `tab%s` set status = 'Cancelled' where docstatus = 2 and modified >='2011-07-06 10:00:00'" % dt)
72
73 dt_list = ['Enquiry', 'Quotation', 'Sales Order', 'Indent', 'Purchase Order', 'Production Order', 'Customer Issue', 'Installation Note', 'Receivable Voucher', 'Payable Voucher', 'Delivery Note', 'Purchase Receipt', 'Journal Voucher', 'Stock Entry']
74 for d in dt_list:
75 tbl = sql("select options from `tabDocField` where fieldtype = 'Table' and parent = '%s'" % d)
76 for t in tbl:
77 sql("update `tab%s` t1, `tab%s` t2 set t1.docstatus = t2.docstatus where t1.parent = t2.name" % (t[0], d))
Brahma K09307622011-07-27 12:03:34 +053078
nabinhait22f7edd2011-07-06 12:45:02 +053079 elif patch_no == 314:
80 # delete double feed
81 sql("delete from tabFeed where subject like 'New %'")
nabinhaiteb315402011-07-06 13:03:31 +053082 elif patch_no == 315:
83 # delete double feed
84 sql("delete from tabFeed where doc_name like 'New %'")
85 reload_doc('core', 'doctype', 'property_setter')
86
87 from webnotes.model.doc import Document
88 m = Document('Module Def Role')
89 m.role = 'All'
90 m.parent = 'Home'
91 m.parenttype = 'Module Def'
92 m.parentfield = 'roles'
93 m.save(1)
Ravi Dey7a6211d2011-07-07 15:49:24 +053094 elif patch_no == 316:
Ravi Dey89822722011-07-07 15:52:35 +053095 pass
96 elif patch_no == 317:
Brahma K09307622011-07-27 12:03:34 +053097 sql("update `tabPage` set name = 'profile-settings' where page_name = 'Profile Settings'")
Anand Doshi56ab7e42011-07-07 18:37:58 +053098 elif patch_no == 318:
Ravi Deycfc5dff2011-07-07 16:48:54 +053099 reload_doc('utilities', 'doctype', 'bulk_rename_tool')
Anand Doshi52b1d5a2011-07-07 18:41:12 +0530100 elif patch_no == 319:
Anand Doshi56ab7e42011-07-07 18:37:58 +0530101 sql("delete from tabFeed where doc_name like 'New %'")
nabinhait63cf2b92011-07-08 13:30:46 +0530102 elif patch_no == 320:
103 reload_doc('setup', 'doctype', 'series_detail')
Ravi Deyfac96e12011-07-08 13:38:16 +0530104 elif patch_no == 321:
Ravi Dey84913842011-07-08 13:46:09 +0530105 reload_doc('hr','doctype','leave_application')
106 elif patch_no == 322:
107 sql("delete from `tabDocField` where parent = 'Leave Application' and fieldname = 'latter_head'")
Nabin Hait2acac4b2011-07-10 13:52:05 +0530108 elif patch_no == 323:
109 reload_doc('stock', 'doctype', 'stock_entry')
Nabin Haite079a6e2011-07-10 14:15:52 +0530110 sql("update `tabDocField` set options = 'get_stock_and_rate' where parent = 'Stock Entry' and label = 'Get Stock and Rate'")
111 sql("delete from `tabDocField` where label = 'Get Current Stock' and parent = 'Stock Entry'")
nabinhait54b0e7d2011-07-13 16:40:03 +0530112 elif patch_no == 324:
113 sql("delete from `tabDocField` where fieldname = 'test_field' and parent = 'Customer'")
Ravi Dey9dd0c0b2011-07-13 18:08:38 +0530114 elif patch_no == 325:
115 sql("update `tabDocField` set fieldtype = 'Data' where parent = 'Salary Slip' and fieldname = 'total_days_in_month'")
116 reload_doc('hr', 'doctype', 'salary_slip')
Rushabh Mehta61790802011-07-17 10:52:47 +0530117 elif patch_no == 326:
118 # load the new billing page
119 if cint(webnotes.conn.get_value('Control Panel',None,'sync_with_gateway')):
120 reload_doc('server_tools','page','billing')
nabinhaite6526362011-07-19 18:09:26 +0530121 elif patch_no == 327:
Rushabh Mehta391aa022011-07-25 14:07:50 +0530122 # patch for support email settings now moved to email settings
123 reload_doc('setup','doctype','email_settings')
Brahma K09307622011-07-27 12:03:34 +0530124
Rushabh Mehta391aa022011-07-25 14:07:50 +0530125 # map fields from support to email settings
126 field_map = {
127 'support_email': 'email',
128 'support_host':'host',
129 'support_username': 'username',
130 'support_password': 'password',
Rushabh Mehtab7186d42011-07-25 14:37:48 +0530131 'support_use_ssl': 'use_ssl',
Rushabh Mehta391aa022011-07-25 14:07:50 +0530132 'sync_support_mails': 'integrate_incoming',
133 'signature': 'support_signature'
134 }
Brahma K09307622011-07-27 12:03:34 +0530135
Rushabh Mehta391aa022011-07-25 14:07:50 +0530136 for key in field_map:
137 webnotes.conn.set_value('Email Settings',None,key, \
138 webnotes.conn.get_value('Support Email Settings',None,field_map[key]))
Brahma K09307622011-07-27 12:03:34 +0530139
Rushabh Mehta391aa022011-07-25 14:07:50 +0530140 # delete support email settings
Rushabh Mehta391aa022011-07-25 14:07:50 +0530141 delete_doc('DocType', 'Support Email Settings')
142
Rushabh Mehta9b8fad22011-07-25 14:45:42 +0530143 reload_doc('support','doctype','support_ticket')
Nabin Hait587ac5c2011-07-26 15:46:10 +0530144 sql("delete from tabDocField where fieldname='problem_description' and parent='Support Ticket'")
145 elif patch_no == 328:
nabinhaite6526362011-07-19 18:09:26 +0530146 if webnotes.conn.get_value('Control Panel', None, 'account_id') != 'axjanak2011':
147 sql("delete from `tabDocField` where fieldname = 'supplier_status' and parent = 'Supplier'")
Nabin Hait587ac5c2011-07-26 15:46:10 +0530148 elif patch_no == 329:
nabinhaitde9826c2011-07-20 18:02:59 +0530149 reload_doc('utilities', 'doctype', 'rename_tool')
150 reload_doc('utilities', 'doctype', 'bulk_rename_tool')
Brahma K09307622011-07-27 12:03:34 +0530151 elif patch_no == 330:
152 reload_doc('accounts', 'doctype', 'lease_agreement')
153 reload_doc('accounts', 'doctype', 'lease_installment')
154
155 reload_doc('accounts', 'search_criteria', 'lease_agreement_list')
156 reload_doc('accounts', 'search_criteria', 'lease_monthly_future_installment_inflows')
157 reload_doc('accounts', 'search_criteria', 'lease_overdue_age_wise')
Nabin Haitf541b742011-07-28 15:33:42 +0530158 reload_doc('accounts', 'search_criteria', 'lease_over_due_list')
Brahma K09307622011-07-27 12:03:34 +0530159 reload_doc('accounts', 'search_criteria', 'lease_receipts_client_wise')
160 reload_doc('accounts', 'search_criteria', 'lease_receipt_summary_year_to_date')
161 reload_doc('accounts', 'search_criteria', 'lease_yearly_future_installment_inflows')
Brahma Kbcdade52011-07-27 12:11:09 +0530162
163 reload_doc('accounts', 'Module Def', 'Accounts')
Brahma K3b1ebe02011-07-27 13:04:11 +0530164 elif patch_no == 331:
165 p = get_obj('Patch Util')
166 # permission
167 p.add_permission('Lease Agreement', 'Accounts Manager', 0, read = 1, write=1,submit=1, cancel=1,amend=1)
168 p.add_permission('Lease Agreement', 'Accounts Manager', 1, read = 1)
Nabin Haitd29916b2011-07-27 14:26:23 +0530169 elif patch_no == 332:
170 sql("update `tabDocField` set permlevel=1, hidden = 1 where parent = 'Bulk Rename Tool' and fieldname = 'file_list'")
Brahma Ke8ec9752011-08-16 12:21:07 +0530171 elif patch_no == 333:
Nabin Haitd31de592011-08-10 14:01:27 +0530172 sql("update `tabDocPerm` set `create` =1 where role = 'Accounts Manager' and parent = 'Lease Agreement'")
Brahma K2eb81012011-08-16 12:27:48 +0530173
Nabin Hait812e7182011-08-05 11:10:30 +0530174 p = get_obj('Patch Util')
175 p.add_permission('DocType Mapper', 'System Manager', 0, read = 1, write=1, create=1)
176 p.add_permission('Role', 'System Manager', 0, read = 1, write=1, create=1)
177 p.add_permission('Print Format', 'System Manager', 0, read = 1, write=1, create=1)
Nabin Haitc4e579c2011-08-05 11:21:35 +0530178 elif patch_no == 334:
179 reload_doc('knowledge_base', 'doctype', 'answer')
Nabin Haitf82b1cc2011-08-05 13:23:14 +0530180 elif patch_no == 335:
Nabin Hait2c0ab732011-08-05 13:40:04 +0530181 for dt in ['Account', 'Cost Center', 'Territory', 'Item Group', 'Customer Group']:
Anand Doshib61abff2011-08-10 11:58:05 +0530182 sql("update `tabDocField` set fieldtype = 'Link', options = %s where fieldname = 'old_parent' and parent = %s", (dt, dt))
183 elif patch_no == 336:
Anand Doshiaabf1742011-08-10 13:27:25 +0530184 reload_doc('server_tools','page','billing')
185 elif patch_no == 337:
Brahma K2eb81012011-08-16 12:27:48 +0530186 item_list = webnotes.conn.sql("""SELECT name, description_html
Anand Doshiaabf1742011-08-10 13:27:25 +0530187 FROM tabItem""")
188 if item_list:
189 for item, html in item_list:
190 if html and "getfile" in html and "acx" in html:
191 ac_id = webnotes.conn.sql("""SELECT value FROM `tabSingles` WHERE doctype='Control Panel' AND field='account_id'""")
192 sp_acx = html.split("acx=")
193 l_acx = len(sp_acx)
Brahma K2eb81012011-08-16 12:27:48 +0530194 if l_acx > 1:
Anand Doshiaabf1742011-08-10 13:27:25 +0530195 for i in range(l_acx-1):
196 sp_quot = sp_acx[i+1].split('"')
197 if len(sp_quot) > 1: sp_quot[0] = str(ac_id[0][0])
198 sp_acx[i+1] = '"'.join(sp_quot)
199 html = "acx=".join(sp_acx)
Nabin Haitd31de592011-08-10 14:01:27 +0530200 webnotes.conn.sql("""UPDATE tabItem SET description_html=%s WHERE name=%s""", (html, item))
Nabin Hait76980b02011-08-10 16:35:25 +0530201 elif patch_no == 338:
202 # Patch for billing status based on amount
203 # reload so and dn
204 reload_doc('selling','doctype','sales_order')
205 reload_doc('stock','doctype','delivery_note')
Brahma K2eb81012011-08-16 12:27:48 +0530206
Nabin Hait76980b02011-08-10 16:35:25 +0530207 # delete billed_qty field
208 sql("delete from `tabDocField` where fieldname = 'billed_qty' and parent in ('Sales Order Detail', 'Delivery Note Detail')")
Brahma K2eb81012011-08-16 12:27:48 +0530209
Nabin Hait76980b02011-08-10 16:35:25 +0530210 # update billed amt in item table in so and dn
211 sql(""" update `tabSales Order Detail` so
212 set billed_amt = (select sum(amount) from `tabRV Detail` where `so_detail`= so.name and docstatus=1 and parent not like 'old%%'), modified = now()""")
Brahma K2eb81012011-08-16 12:27:48 +0530213
Nabin Hait76980b02011-08-10 16:35:25 +0530214 sql(""" update `tabDelivery Note Detail` dn
215 set billed_amt = (select sum(amount) from `tabRV Detail` where `dn_detail`= dn.name and docstatus=1 and parent not like 'old%%'), modified = now()""")
Brahma K2eb81012011-08-16 12:27:48 +0530216
Nabin Hait76980b02011-08-10 16:35:25 +0530217 # calculate % billed based on item table
218 sql(""" update `tabSales Order` so
219 set per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabSales Order Detail` where parent = so.name), modified = now()""")
Brahma K2eb81012011-08-16 12:27:48 +0530220
Nabin Hait76980b02011-08-10 16:35:25 +0530221 sql(""" update `tabDelivery Note` dn
222 set per_billed = (select sum(if(amount > ifnull(billed_amt, 0), billed_amt, amount))/sum(amount)*100 from `tabDelivery Note Detail` where parent = dn.name), modified = now()""")
223
224 # update billing status based on % billed
225 sql("""update `tabSales Order` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
226 if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
227 sql("""update `tabDelivery Note` set billing_status = if(ifnull(per_billed,0) < 0.001, 'Not Billed',
228 if(per_billed >= 99.99, 'Fully Billed', 'Partly Billed'))""")
Rushabh Mehtaab5292a2011-08-16 10:04:29 +0530229
Rushabh Mehtaaf43b742011-08-11 12:37:11 +0530230 # update name of questions page
231 sql("update tabPage set name='questions' where name='Questions'")
Brahma K2eb81012011-08-16 12:27:48 +0530232 sql("update tabPage set name='question-view' where name='Question View'")
Brahma Kfce442e2011-08-16 14:48:46 +0530233 elif patch_no == 339:
Brahma Ke8ec9752011-08-16 12:21:07 +0530234 reload_doc('production','doctype','bill_of_materials')
Nabin Haitcddc2fa2011-08-22 14:55:32 +0530235 elif patch_no == 340:
236 sql("update `tabDocField` set permlevel = 0 where (fieldname in ('process', 'production_order', 'fg_completed_qty') or label = 'Get Items') and parent = 'Stock Entry'")
Nabin Hait3eb37ce2011-08-23 17:21:21 +0530237 elif patch_no == 341:
238 reload_doc('stock','doctype','delivery_note')
239 reload_doc('stock','doctype','item')
240 reload_doc('selling','doctype','quotation')
241 reload_doc('stock','Print Format','Delivery Note Packing List Wise')
242
243 if not sql("select format from `tabDocFormat` where name = 'Delivery Note Packing List Wise' and parent = 'Delivery Note'"):
244 from webnotes.model.doc import addchild
245 dt_obj = get_obj('DocType', 'Delivery Note', with_children = 1)
246 ch = addchild(dt_obj.doc, 'formats', 'DocFormat', 1)
247 ch.format = 'Delivery Note Packing List Wise'
248 ch.save(1)
249 elif patch_no == 342:
Nabin Hait51982622011-08-23 17:29:15 +0530250 sql("update `tabDocField` set permlevel = 0 where parent = 'Stock Entry Detail' and fieldname in ('s_warehouse', 't_warehouse', 'fg_item')")
Nabin Hait7b8f53c2011-08-24 11:23:34 +0530251 elif patch_no == 343:
Brahma Kc735d442011-08-23 18:38:48 +0530252 reload_doc('stock','doctype','item_customer_detail')
Nabin Haitcfe8ee82011-08-25 14:02:01 +0530253 elif patch_no == 344:
Nabin Hait7b8f53c2011-08-24 11:23:34 +0530254 sql("delete from `tabDocFormat` where ifnull(format, '') = '' and parent = 'Delivery Note'")
Rushabh Mehta33bce672011-08-25 15:15:25 +0530255 elif patch_no == 345:
Rushabh Mehta910d9552011-08-30 16:09:01 +0530256 # rerun 343 (merge confict)
257 reload_doc('stock','doctype','item_customer_detail')
Nabin Haitcfe8ee82011-08-25 14:02:01 +0530258 sql("delete from `tabModule Def Item` where display_name = 'Salary Slip Control Panel' and parent = 'HR'")
259 reload_doc('hr','Module Def','HR')
Rushabh Mehta33bce672011-08-25 15:15:25 +0530260 elif patch_no == 346:
Rushabh Mehta96fde952011-08-29 17:54:27 +0530261 pass
Nabin Hait2c030152011-08-25 19:41:24 +0530262 elif patch_no == 347:
263 sql("delete from `tabField Mapper Detail` where from_field = to_field and map = 'Yes' and ifnull(checking_operator, '') = ''")
Nabin Hait1d5cab82011-08-29 13:16:52 +0530264 elif patch_no == 348:
265 sql("update `tabStock Ledger Entry` set is_cancelled = 'No' where voucher_type = 'Serial No'")
Nabin Haite0410da2011-08-29 14:24:19 +0530266 elif patch_no == 349:
267 delete_doc('Custom Script', 'Update Series-Server')
268 delete_doc('Custom Script', 'Profile-Client')
269 delete_doc('Custom Script', 'Event-Client')
270 delete_doc('Custom Script', 'File-Server')
Brahma K3c9a6a12011-08-31 12:55:41 +0530271
Rushabh Mehta96fde952011-08-29 17:54:27 +0530272 # reload profile with new fields for security
273 delete_doc('DocType', 'Profile')
274 reload_doc('core', 'doctype', 'profile')
Nabin Hait7cb1c572011-08-30 17:39:38 +0530275 elif patch_no == 350:
276 reload_doc('stock', 'doctype', 'delivery_note_detail')
277 reload_doc('stock', 'doctype', 'item_customer_detail')
Nabin Hait93592132011-08-31 11:27:51 +0530278 elif patch_no == 351:
279 reload_doc('home', 'page', 'dashboard')
Brahma K3c9a6a12011-08-31 12:55:41 +0530280 elif patch_no == 352:
281 reload_doc('setup', 'doctype','feature_setup')
282 reload_doc('stock','doctype','item')
283 sql("update tabDocField set label='Produced Qty',description='Updated after finished goods are transferred to FG Warehouse through Stock Entry' where parent='Production Order' and fieldname='produced_qty'")
Brahma K8e8c4822011-08-31 15:46:29 +0530284 rs = sql("select fieldname from tabDocField where parent='Features Setup' and fieldname is not null")
285 from webnotes.model.doc import Document
286 m = Document('Features Setup')
287 for d in rs:
288 m.fields[d[0]] = 1
289 m.save()