Move related property setters to custom field property
This commit is contained in:
		
							parent
							
								
									f3ded044e0
								
							
						
					
					
						commit
						03463ef73b
					
				
							
								
								
									
										0
									
								
								patches/1401/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								patches/1401/__init__.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,35 @@ | |||||||
|  | # Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors | ||||||
|  | # License: GNU General Public License v3. See license.txt | ||||||
|  | 
 | ||||||
|  | import webnotes | ||||||
|  | from webnotes.model.meta import get_field | ||||||
|  | 
 | ||||||
|  | def execute(): | ||||||
|  | 	webnotes.reload_doc("core", "doctype", "custom_field") | ||||||
|  | 	 | ||||||
|  | 	custom_fields = {} | ||||||
|  | 	for cf in webnotes.conn.sql("""select dt, fieldname from `tabCustom Field`""", as_dict=1): | ||||||
|  | 		custom_fields.setdefault(cf.dt, []).append(cf.fieldname) | ||||||
|  | 		 | ||||||
|  | 	delete_list = [] | ||||||
|  | 	for ps in webnotes.conn.sql("""select * from `tabProperty Setter`""", as_dict=1): | ||||||
|  | 		if ps.field_name in custom_fields.get(ps.doc_type, []): | ||||||
|  | 			 | ||||||
|  | 			if ps.property == "previous_field": | ||||||
|  | 				property_name = "insert_after" | ||||||
|  | 				 | ||||||
|  | 				field_meta = get_field(ps.doc_type, ps.value) | ||||||
|  | 				property_value = field_meta.label if field_meta else "" | ||||||
|  | 			else: | ||||||
|  | 				property_name = ps.property | ||||||
|  | 				property_value  =ps.value | ||||||
|  | 	 | ||||||
|  | 			webnotes.conn.sql("""update `tabCustom Field`  | ||||||
|  | 				set %s=%s where dt=%s and fieldname=%s""" % (property_name,	'%s', '%s', '%s'),  | ||||||
|  | 				(property_value, ps.doc_type, ps.field_name)) | ||||||
|  | 				 | ||||||
|  | 			delete_list.append(ps.name) | ||||||
|  | 			 | ||||||
|  | 	if delete_list: | ||||||
|  | 		webnotes.conn.sql("""delete from `tabProperty Setter` where name in (%s)""" %  | ||||||
|  | 			', '.join(['%s']*len(delete_list)), tuple(delete_list)) | ||||||
| @ -263,4 +263,5 @@ patch_list = [ | |||||||
| 	"patches.1311.p08_email_digest_recipients", | 	"patches.1311.p08_email_digest_recipients", | ||||||
| 	"execute:webnotes.delete_doc('DocType', 'Warehouse Type')", | 	"execute:webnotes.delete_doc('DocType', 'Warehouse Type')", | ||||||
| 	"patches.1312.p02_update_item_details_in_item_price", | 	"patches.1312.p02_update_item_details_in_item_price", | ||||||
|  | 	"patches.1401.p01_move_related_property_setters_to_custom_field", | ||||||
| ] | ] | ||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user