added observer for employee doctype to update salary structure
This commit is contained in:
		
							parent
							
								
									d19e2f56cc
								
							
						
					
					
						commit
						ac1985ff68
					
				
							
								
								
									
										0
									
								
								hr/helpers/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										0
									
								
								hr/helpers/__init__.py
									
									
									
									
									
										Normal file
									
								
							
							
								
								
									
										27
									
								
								hr/helpers/employee.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								hr/helpers/employee.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,27 @@ | ||||
| # ERPNext - web based ERP (http://erpnext.com) | ||||
| # For license information, please see license.txt | ||||
| 
 | ||||
| from __future__ import unicode_literals | ||||
| import webnotes | ||||
| 
 | ||||
| def update_employee_details(controller, method=None): | ||||
| 	"""update employee details in linked doctypes""" | ||||
| 	if method == "on_update" and controller.doc.doctype == "Employee": | ||||
| 		# update salary structure | ||||
| 		active_salary_structure = webnotes.conn.get_value("Salary Structure",  | ||||
| 			{"is_active": "Yes", "employee": controller.doc.name}) | ||||
| 		if not active_salary_structure: | ||||
| 			return | ||||
| 		 | ||||
| 		ss = webnotes.model_wrapper("Salary Structure", active_salary_structure) | ||||
| 		ss_doctype = webnotes.get_doctype("Salary Structure") | ||||
| 		update = False | ||||
| 		for fieldname, value in controller.doc.fields.items(): | ||||
| 			if ss_doctype.get_field(fieldname) and ss.doc.fields[fieldname] != value: | ||||
| 				ss.doc.fields[fieldname] = value | ||||
| 				update = True | ||||
| 				 | ||||
| 		if update: | ||||
| 			ss.save() | ||||
| 		 | ||||
| 	 | ||||
| @ -17,5 +17,6 @@ | ||||
| observer_map = { | ||||
| 	"*:on_update": "home.update_feed", | ||||
| 	"*:on_submit": "home.update_feed", | ||||
| 	"Employee:on_update": "hr.helpers.employee.update_employee_details" | ||||
| #	"*:on_update": "webnotes.widgets.moduleview.update_count" | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user