fix: calculate earned leaves based on annual allocation
diff --git a/erpnext/hr/utils.py b/erpnext/hr/utils.py
index 3accbbb..7ef61e9 100644
--- a/erpnext/hr/utils.py
+++ b/erpnext/hr/utils.py
@@ -296,12 +296,12 @@
if not e_leave_type.earned_leave_frequency == "Monthly":
if not check_frequency_hit(allocation.from_date, today, e_leave_type.earned_leave_frequency):
continue
- annual_allocation = frappe.get_all("Leave Policy Detail", filters={
+ annual_allocation = frappe.db.get_value("Leave Policy Detail", filters={
'parent': leave_policy.name,
'leave_type': e_leave_type.name
- }, fields=['annual_allocation'])
- if annual_allocation and annual_allocation[0]:
- earned_leaves = flt(annual_allocation[0][0]) / divide_by_frequency[e_leave_type.earned_leave_frequency]
+ }, fieldname=['annual_allocation'])
+ if annual_allocation:
+ earned_leaves = flt(annual_allocation) / divide_by_frequency[e_leave_type.earned_leave_frequency]
if e_leave_type.rounding == "0.5":
earned_leaves = round(earned_leaves * 2) / 2
else:
diff --git a/erpnext/patches/v12_0/generate_leave_ledger_entries.py b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
index 38f6883..44b59bf 100644
--- a/erpnext/patches/v12_0/generate_leave_ledger_entries.py
+++ b/erpnext/patches/v12_0/generate_leave_ledger_entries.py
@@ -83,4 +83,4 @@
def get_leave_encashment_records():
return frappe.get_all("Leave Encashment", filters={
"docstatus": 1
- }, fields=['name', 'employee', 'leave_type', 'encashable_days', 'encashment_date'])
+ }, fields=['name', 'employee', 'leave_type', 'encashable_days', 'encashment_date'])
\ No newline at end of file