Leave Policy - Validate Annual alloction for leave type

This commit is contained in:
Jamsheer 2018-05-08 12:24:39 +05:30
parent d7bfa2303f
commit 62a93533fc
2 changed files with 31 additions and 2 deletions

View File

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

View File

@ -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))