Leave Policy - Validate Annual alloction for leave type
diff --git a/erpnext/hr/doctype/leave_policy/leave_policy.js b/erpnext/hr/doctype/leave_policy/leave_policy.js
index 309215e..fdf8e0c 100644
--- a/erpnext/hr/doctype/leave_policy/leave_policy.js
+++ b/erpnext/hr/doctype/leave_policy/leave_policy.js
@@ -2,7 +2,30 @@
// For license information, please see license.txt
frappe.ui.form.on('Leave Policy', {
- refresh: function(frm) {
+});
+frappe.ui.form.on('Leave Policy Detail',{
+ leave_type: function(frm, cdt, cdn) {
+ var child = locals[cdt][cdn];
+ if(child.leave_type){
+ frappe.call({
+ method: "frappe.client.get_value",
+ args: {
+ doctype: "Leave Type",
+ fieldname: "max_leaves_allowed",
+ filters: { name: child.leave_type }
+ },
+ callback: function(r) {
+ if (r.message) {
+ child.annual_allocation = r.message.max_leaves_allowed;
+ refresh_field("leave_policy_details");
+ }
+ }
+ });
+ }
+ else{
+ child.annual_allocation = "";
+ refresh_field("leave_policy_details");
+ }
}
});
diff --git a/erpnext/hr/doctype/leave_policy/leave_policy.py b/erpnext/hr/doctype/leave_policy/leave_policy.py
index 1da84c2..964a5de 100644
--- a/erpnext/hr/doctype/leave_policy/leave_policy.py
+++ b/erpnext/hr/doctype/leave_policy/leave_policy.py
@@ -4,7 +4,13 @@
from __future__ import unicode_literals
import frappe
+from frappe import _
from frappe.model.document import Document
class LeavePolicy(Document):
- pass
+ def validate(self):
+ if self.leave_policy_details:
+ for lp_detail in self.leave_policy_details:
+ max_leaves_allowed = frappe.db.get_value("Leave Type", lp_detail.leave_type, "max_leaves_allowed")
+ if max_leaves_allowed > 0 and lp_detail.annual_allocation > max_leaves_allowed:
+ frappe.throw(_("Maximum leave allowed in the leave type {0} is {1}").format(lp_detail.leave_type, max_leaves_allowed))