From f10f2513fa96409b9bc69435a94efe632857f0a0 Mon Sep 17 00:00:00 2001 From: mayur-patel Date: Tue, 5 Mar 2013 18:20:57 +1100 Subject: [PATCH] Added checks to see if the selected leave type allows negative balance. If it does then warn the user and continue with saving the form else just warn the user and don't save the form data. --- hr/doctype/leave_application/leave_application.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 12e715eb8ed..80504d09c8b 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -124,13 +124,15 @@ class DocType(DocListController): if not is_lwp(self.doc.leave_type): self.doc.leave_balance = get_leave_balance(self.doc.employee, self.doc.leave_type, self.doc.fiscal_year)["leave_balance"] - # Allowing user to add leavs which will result in negative balance. This is needed for Sick Leave and other common exceptional cases. - #System will check and warn but continue with saving the application. - #This may needs to be changed if other ERPNext customer may not want this behaviour. + if self.doc.leave_balance - self.doc.total_leave_days < 0: - msgprint("There is not enough leave balance for Leave Type: %s" % \ - (self.doc.leave_type,)) - # , raise_exception=1) + + # check if this leave type allow the remaining balance to be in negative. If yes then warn the user and continue to save else warn the user and don't save. + if webnotes.conn.get_value("Leave Type", self.doc.leave_type,"allow_negative"): + msgprint("There is not enough leave balance for Leave Type - new: %s" %(self.doc.leave_type,)) + # warn the user but don't save the form. + else: + msgprint("There is not enough leave balance for Leave Type - new: %s" %(self.doc.leave_type,), raise_exception=1) def validate_leave_overlap(self): if not self.doc.name: