Skip to content

Commit 52835d2

Browse files
committed
fix: consider payment days = total working days in the last salary slip while calculating Gratuity
1 parent 78f68f3 commit 52835d2

File tree

1 file changed

+29
-25
lines changed

1 file changed

+29
-25
lines changed

hrms/payroll/doctype/gratuity/gratuity.py

+29-25
Original file line numberDiff line numberDiff line change
@@ -301,25 +301,30 @@ def get_applicable_components(gratuity_rule):
301301

302302

303303
def get_total_applicable_component_amount(employee, applicable_earnings_component, gratuity_rule):
304-
sal_slip = get_last_salary_slip(employee)
305-
if not sal_slip:
306-
frappe.throw(_("No Salary Slip is found for Employee: {0}").format(bold(employee)))
307-
component_and_amounts = frappe.get_all(
308-
"Salary Detail",
309-
filters={
310-
"docstatus": 1,
311-
"parent": sal_slip,
312-
"parentfield": "earnings",
313-
"salary_component": ("in", applicable_earnings_component),
314-
},
315-
fields=["amount"],
316-
)
317-
total_applicable_components_amount = 0
318-
if not len(component_and_amounts):
319-
frappe.throw(_("No Applicable Component is present in last month salary slip"))
320-
for data in component_and_amounts:
321-
total_applicable_components_amount += data.amount
322-
return total_applicable_components_amount
304+
salary_slip = get_last_salary_slip(employee)
305+
if not salary_slip:
306+
frappe.throw(_("No Salary Slip found for Employee: {0}").format(bold(employee)))
307+
308+
# consider full payment days for calculation as last month's salary slip
309+
# might have less payment days as per attendance, making it non-deterministic
310+
salary_slip.payment_days = salary_slip.total_working_days
311+
salary_slip.process_salary_structure()
312+
313+
total_amount = 0
314+
component_found = False
315+
for row in salary_slip.earnings:
316+
if row.salary_component in applicable_earnings_component:
317+
total_amount += flt(row.amount)
318+
component_found = True
319+
320+
if not component_found:
321+
frappe.throw(
322+
_("No applicable Earning component found in last salary slip for Gratuity Rule: {0}").format(
323+
bold(get_link_to_form("Gratuity Rule", gratuity_rule))
324+
)
325+
)
326+
327+
return total_amount
323328

324329

325330
def calculate_amount_based_on_current_slab(
@@ -354,10 +359,9 @@ def get_salary_structure(employee):
354359
)[0].salary_structure
355360

356361

357-
def get_last_salary_slip(employee):
358-
salary_slips = frappe.get_list(
359-
"Salary Slip", filters={"employee": employee, "docstatus": 1}, order_by="start_date desc"
362+
def get_last_salary_slip(employee: str) -> dict | None:
363+
salary_slip = frappe.db.get_value(
364+
"Salary Slip", {"employee": employee, "docstatus": 1}, order_by="start_date desc"
360365
)
361-
if not salary_slips:
362-
return
363-
return salary_slips[0].name
366+
if salary_slip:
367+
return frappe.get_doc("Salary Slip", salary_slip)

0 commit comments

Comments
 (0)