Skip to content

Commit

Permalink
fix: only fetch required fields from gratuity slabs
Browse files Browse the repository at this point in the history
  • Loading branch information
ruchamahabal committed May 23, 2024
1 parent 4b1437b commit 6ac2da5
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -302,19 +302,21 @@ 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))

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"
Expand Down

0 comments on commit 6ac2da5

Please sign in to comment.