added observer for employee doctype to update salary structure

This commit is contained in:
Anand Doshi 2013-02-18 19:42:02 +05:30
parent d19e2f56cc
commit ac1985ff68
3 changed files with 28 additions and 0 deletions

0
hr/helpers/__init__.py Normal file
View File

27
hr/helpers/employee.py Normal file
View 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()

View File

@ -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"
}