From 91cad9e985982aa1b86d14a8f554c996fccaa9ae Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 10 Mar 2023 15:48:51 +0530 Subject: [PATCH] fix: exclude cancelled leave ledger entries --- .../hr/doctype/leave_allocation/leave_allocation.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py index 49ece5a23412..c5cf3b43a62a 100755 --- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py +++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py @@ -99,7 +99,7 @@ def on_update_after_submit(self): # run required validations again since total leaves are being updated self.validate_leave_days_and_dates() - leaves_to_be_added = ( + leaves_to_be_added = flt( frappe.db.get_value("Leave Allocation", self.name, "new_leaves_allocated") - self.get_existing_leave_count() ) @@ -123,14 +123,12 @@ def get_existing_leave_count(self): "company": self.company, "leave_type": self.leave_type, "is_carry_forward": 0, + "docstatus": 1, }, - pluck="leaves", + fields=["SUM(leaves) as total_leaves"], ) - total_existing_leaves = 0 - for entry in ledger_entries: - total_existing_leaves += entry - return total_existing_leaves + return ledger_entries[0].total_leaves if ledger_entries else 0 def validate_against_leave_applications(self): leaves_taken = get_approved_leaves_for_period(