Skip to content

Commit

Permalink
fix: Apply system precision value while validating leave balance (#2482)
Browse files Browse the repository at this point in the history
* fix: Apply system precision value while validating leave balance

* fix: apply precision on leave balance, add fallback value for precision

* fix: remove precision at expired leaves calculation
  • Loading branch information
AyshaHakeem authored Dec 9, 2024
1 parent 7ad5ec0 commit ffa4509
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions hrms/hr/doctype/leave_application/leave_application.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,8 @@ def validate_block_days(self):
frappe.throw(_("You are not authorized to approve leaves on Block Dates"), LeaveDayBlockedError)

def validate_balance_leaves(self):
precision = cint(frappe.db.get_single_value("System Settings", "float_precision")) or 2

if self.from_date and self.to_date:
self.total_leave_days = get_number_of_leave_days(
self.employee,
Expand All @@ -376,9 +378,9 @@ def validate_balance_leaves(self):
consider_all_leaves_in_the_allocation_period=True,
for_consumption=True,
)
self.leave_balance = leave_balance.get("leave_balance")
leave_balance_for_consumption = leave_balance.get("leave_balance_for_consumption")

leave_balance_for_consumption = flt(
leave_balance.get("leave_balance_for_consumption"), precision
)
if self.status != "Rejected" and (
leave_balance_for_consumption < self.total_leave_days or not leave_balance_for_consumption
):
Expand Down Expand Up @@ -848,7 +850,7 @@ def get_number_of_leave_days(
def get_leave_details(employee, date, for_salary_slip=False):
allocation_records = get_leave_allocation_records(employee, date)
leave_allocation = {}
precision = cint(frappe.db.get_single_value("System Settings", "float_precision", cache=True))
precision = cint(frappe.db.get_single_value("System Settings", "float_precision")) or 2

for d in allocation_records:
allocation = allocation_records.get(d, frappe._dict())
Expand Down

0 comments on commit ffa4509

Please sign in to comment.