Employee can be reselected but not changed in salary structure
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.js b/erpnext/hr/doctype/salary_structure/salary_structure.js
index ee42d0c..ddaf88c 100644
--- a/erpnext/hr/doctype/salary_structure/salary_structure.js
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.js
@@ -14,8 +14,6 @@
if((!doc.__islocal) && (doc.is_active == 'Yes')){
cur_frm.add_custom_button(__('Make Salary Slip'), cur_frm.cscript['Make Salary Slip']);
}
-
- cur_frm.toggle_enable('employee', doc.__islocal);
}
cur_frm.cscript['Make Salary Slip'] = function() {
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.py b/erpnext/hr/doctype/salary_structure/salary_structure.py
index f3d2eb1..97935e6 100644
--- a/erpnext/hr/doctype/salary_structure/salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.py
@@ -54,18 +54,28 @@
def check_existing(self):
ret = frappe.db.sql("""select name from `tabSalary Structure` where is_active = 'Yes'
and employee = %s and name!=%s""", (self.employee,self.name))
+
if ret and self.is_active=='Yes':
- frappe.throw(_("Another Salary Structure {0} is active for employee {0}. Please make its status 'Inactive' to proceed.").format(cstr(ret), self.employee))
+ frappe.throw(_("Another Salary Structure {0} is active for employee {1}. Please make its status 'Inactive' to proceed.").format(cstr(ret[0][0]), self.employee))
def validate_amount(self):
if flt(self.net_pay) < 0:
frappe.throw(_("Net pay cannot be negative"))
+ def validate_employee(self):
+ old_employee = frappe.db.get_value("Salary Structure", self.name, "employee")
+ print old_employee
+ if old_employee and self.employee != old_employee:
+ frappe.throw(_("Employee can not be changed"))
+
+
def validate(self):
self.check_existing()
self.validate_amount()
+ self.validate_employee()
set_employee_name(self)
+
@frappe.whitelist()
def make_salary_slip(source_name, target_doc=None):
def postprocess(source, target):