Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: gratuity calculation for 'Sum of all previous slabs' option #2471

Merged
merged 5 commits into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion hrms/payroll/doctype/gratuity/gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,7 @@ def get_gratuity_amount(self, experience: float) -> float:
years_left * total_component_amount * slab.fraction_of_applicable_earnings
)
slab_found = True
break

if not slab_found:
frappe.throw(
Expand Down Expand Up @@ -311,7 +312,7 @@ def get_gratuity_rule_slabs(self) -> list[dict]:
)

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))
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))
Expand Down
34 changes: 28 additions & 6 deletions hrms/payroll/doctype/gratuity/test_gratuity.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,19 +90,41 @@ def test_gratuity_based_on_current_slab_via_additional_salary(self):
@set_holiday_list("Salary Slip Test Holiday List", "_Test Company")
def test_gratuity_based_on_all_previous_slabs_via_payment_entry(self):
"""
Range | Fraction
0-1 | 0
1-5 | 0.7
5-0 | 1
Range | Fraction
0-3 | 0.5
3-6 | 1.0
6-9 | 1.5
"""
from hrms.overrides.employee_payment_entry import get_payment_entry_for_employee

sal_slip = create_salary_slip(self.employee)

rule = setup_gratuity_rule("Rule Under Limited Contract (UAE)")
rule.gratuity_rule_slabs = []
for slab in [
{"from_year": 0, "to_year": 3, "fraction_of_applicable_earnings": 0.5},
{"from_year": 3, "to_year": 6, "fraction_of_applicable_earnings": 1.0},
{"from_year": 6, "to_year": 9, "fraction_of_applicable_earnings": 1.5},
]:
new_slab = frappe.get_doc(
{
"doctype": "Gratuity Rule Slab",
"from_year": slab["from_year"],
"to_year": slab["to_year"],
"fraction_of_applicable_earnings": slab["fraction_of_applicable_earnings"],
"parent": rule.name,
"parentfield": "gratuity_rule_slabs",
"parenttype": "Gratuity Rule",
}
)
rule.append("gratuity_rule_slabs", new_slab)
rule.save()
rule.reload()

set_mode_of_payment_account()

gratuity = create_gratuity(
expense_account="Payment Account - _TC", mode_of_payment="Cash", employee=self.employee
expense_account="Payment Account - _TC", mode_of_payment="Cash", employee=self.employee, rule=rule
)

# work experience calculation
Expand All @@ -125,7 +147,7 @@ def test_gratuity_based_on_all_previous_slabs_via_payment_entry(self):
limit=1,
)

gratuity_amount = ((0 * 1) + (4 * 0.7) + (1 * 1)) * component_amount[0].amount
gratuity_amount = ((3 * 0.5) + (3 * 1.0)) * component_amount[0].amount
self.assertEqual(flt(gratuity_amount, 2), flt(gratuity.amount, 2))
self.assertEqual(gratuity.status, "Unpaid")

Expand Down
Loading