From 639392a0b105723db828ff635b05668c19311acd Mon Sep 17 00:00:00 2001 From: mayur-patel Date: Tue, 5 Mar 2013 16:21:00 +1100 Subject: [PATCH 1/4] Allowing user to add leaves which may results in negative leave balance. --- hr/doctype/leave_application/leave_application.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index e8cc446ea5..12e715eb8e 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -124,10 +124,13 @@ 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) + (self.doc.leave_type,)) + # , raise_exception=1) def validate_leave_overlap(self): if not self.doc.name: From f10f2513fa96409b9bc69435a94efe632857f0a0 Mon Sep 17 00:00:00 2001 From: mayur-patel Date: Tue, 5 Mar 2013 18:20:57 +1100 Subject: [PATCH 2/4] 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 12e715eb8e..80504d09c8 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: From 547604cf5af189378fdc46a3c89df91aa99bb027 Mon Sep 17 00:00:00 2001 From: mayur-patel Date: Tue, 5 Mar 2013 19:11:53 +1100 Subject: [PATCH 3/4] Added a new field called allow_negative. This field was added for allowing a negative balance for a particular leave type. --- hr/doctype/leave_type/leave_type.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/hr/doctype/leave_type/leave_type.txt b/hr/doctype/leave_type/leave_type.txt index 5524bcfb14..3087caaa1a 100644 --- a/hr/doctype/leave_type/leave_type.txt +++ b/hr/doctype/leave_type/leave_type.txt @@ -1,8 +1,8 @@ [ { - "creation": "2013-01-10 16:34:15", + "creation": "2013-02-21 09:55:58", "docstatus": 0, - "modified": "2013-01-22 14:47:02", + "modified": "2013-03-05 08:06:43", "modified_by": "Administrator", "owner": "Administrator" }, @@ -91,6 +91,12 @@ "fieldtype": "Check", "label": "Is LWP" }, + { + "doctype": "DocField", + "fieldname": "allow_negative", + "fieldtype": "Check", + "label": "Allow Negative Balance" + }, { "doctype": "DocPerm", "role": "System Manager" From c7e28c7e5d89564bee89ec0021860fa9297fd0c1 Mon Sep 17 00:00:00 2001 From: mayur-patel Date: Tue, 5 Mar 2013 20:14:05 +1100 Subject: [PATCH 4/4] changed the logic to be more elegant. --- hr/doctype/leave_application/leave_application.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/hr/doctype/leave_application/leave_application.py b/hr/doctype/leave_application/leave_application.py index 80504d09c8..f2a58c8dd8 100755 --- a/hr/doctype/leave_application/leave_application.py +++ b/hr/doctype/leave_application/leave_application.py @@ -126,14 +126,11 @@ class DocType(DocListController): self.doc.leave_type, self.doc.fiscal_year)["leave_balance"] if self.doc.leave_balance - self.doc.total_leave_days < 0: - - # 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) - + #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. + msgprint("There is not enough leave balance for Leave Type: %s" % \ + (self.doc.leave_type,), + raise_exception=not(webnotes.conn.get_value("Leave Type", self.doc.leave_type,"allow_negative") or None)) + def validate_leave_overlap(self): if not self.doc.name: self.doc.name = "New Leave Application"