From 6ac2da5c1504fd419fbb4a561ad066d598204307 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Thu, 23 May 2024 21:25:02 +0530 Subject: [PATCH] fix: only fetch required fields from gratuity slabs --- hrms/payroll/doctype/gratuity/gratuity.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/hrms/payroll/doctype/gratuity/gratuity.py b/hrms/payroll/doctype/gratuity/gratuity.py index d3d5ac2c2b..19fb552240 100644 --- a/hrms/payroll/doctype/gratuity/gratuity.py +++ b/hrms/payroll/doctype/gratuity/gratuity.py @@ -212,7 +212,7 @@ def get_gratuity_amount(self, experience: float) -> float: calculate_amount_based_on = self.gratuity_settings.calculate_gratuity_amount_based_on gratuity_amount = 0 - slabs = get_gratuity_rule_slabs(self.gratuity_rule) + slabs = self.get_gratuity_rule_slabs() slab_found = False years_left = experience @@ -302,6 +302,14 @@ def get_applicable_components(self) -> list[str]: return applicable_earning_components + def get_gratuity_rule_slabs(self) -> list[dict]: + return frappe.get_all( + "Gratuity Rule Slab", + filters={"parent": self.gratuity_rule}, + fields=["from_year", "to_year", "fraction_of_applicable_earnings"], + order_by="idx", + ) + def _is_experience_within_slab(self, slab: dict, experience: float) -> bool: return bool(slab.from_year <= experience and (experience < slab.to_year or slab.to_year == 0)) @@ -309,12 +317,6 @@ def _is_experience_beyond_slab(self, slab: dict, experience: float) -> bool: return bool(slab.from_year < experience and (slab.to_year < experience and slab.to_year != 0)) -def get_gratuity_rule_slabs(gratuity_rule): - return frappe.get_all( - "Gratuity Rule Slab", filters={"parent": gratuity_rule}, fields=["*"], order_by="idx" - ) - - def get_last_salary_slip(employee: str) -> dict | None: salary_slip = frappe.db.get_value( "Salary Slip", {"employee": employee, "docstatus": 1}, order_by="start_date desc"