Skip to content

Commit

Permalink
fix: HRA calculation if there are multiple salary structure assignmen…
Browse files Browse the repository at this point in the history
…ts for the current payroll period (backport #2691) (#2693)

Co-authored-by: Nabin Hait <nabinhait@gmail.com>
  • Loading branch information
mergify[bot] and nabinhait authored Jan 24, 2025
1 parent 32ceaee commit 32e5c3b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,17 +535,21 @@ def get_salary_assignments(employee, payroll_period):
order_by="from_date",
)

if not assignments:
if not assignments or getdate(assignments[0].from_date) > getdate(start_date):
# if no assignments found for the given period
# get the last one assigned before the period that is still active
assignments = frappe.get_all(
# or the latest assignment hast started in the middle of the period
# get the last one assigned before the period start date
past_assignment = frappe.get_all(
"Salary Structure Assignment",
filters={"employee": employee, "docstatus": 1, "from_date": ["<=", start_date]},
filters={"employee": employee, "docstatus": 1, "from_date": ["<", start_date]},
fields=["*"],
order_by="from_date desc",
limit=1,
)

if past_assignment:
assignments = past_assignment + assignments

return assignments


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,14 +349,15 @@ def test_india_hra_exemption_with_multiple_assignments(self):
)

# salary structure with base 50000, HRA 3000
# effective from 3 months before payroll period
make_salary_structure(
"Monthly Structure for HRA Exemption 1",
"Monthly",
employee=employee,
company="_Test Company",
currency="INR",
payroll_period=payroll_period.name,
from_date=payroll_period.start_date,
from_date=add_months(payroll_period.start_date, -3),
)

# salary structure with base 70000, HRA = base * 0.2 = 14000
Expand All @@ -379,6 +380,7 @@ def test_india_hra_exemption_with_multiple_assignments(self):

salary_structure.submit()

# effective from 6 months after payroll period
create_salary_structure_assignment(
employee,
salary_structure.name,
Expand Down
2 changes: 1 addition & 1 deletion hrms/regional/india/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def get_custom_fields():
"fieldname": "hra_section",
"label": "HRA Settings",
"fieldtype": "Section Break",
"insert_after": "asset_received_but_not_billed",
"insert_after": "default_payroll_payable_account",
"collapsible": 1,
},
{
Expand Down

0 comments on commit 32e5c3b

Please sign in to comment.