Skip to content

Commit

Permalink
fix: exclude cancelled leave ledger entries
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed Mar 14, 2023
1 parent 7b9784c commit 91cad9e
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions erpnext/hr/doctype/leave_allocation/leave_allocation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
)
Expand All @@ -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(
Expand Down

0 comments on commit 91cad9e

Please sign in to comment.