Skip to content

Commit

Permalink
Merge pull request #1719 from frappe/version-15-hotfix
Browse files Browse the repository at this point in the history
chore: release v15
  • Loading branch information
ruchamahabal authored Apr 27, 2024
2 parents 30d010a + eb200bd commit 5a59bc2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 11 deletions.
17 changes: 13 additions & 4 deletions hrms/hr/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,16 +518,25 @@ def check_effective_date(from_date, today, frequency, allocate_on_day):


def get_salary_assignments(employee, payroll_period):
start_date, end_date = frappe.db.get_value(
"Payroll Period", payroll_period, ["start_date", "end_date"]
)
assignments = frappe.db.get_all(
start_date, end_date = frappe.db.get_value("Payroll Period", payroll_period, ["start_date", "end_date"])
assignments = frappe.get_all(
"Salary Structure Assignment",
filters={"employee": employee, "docstatus": 1, "from_date": ["between", (start_date, end_date)]},
fields=["*"],
order_by="from_date",
)

if not assignments:
# if no assignments found for the given period
# get the last one assigned before the period that is still active
assignments = frappe.get_all(
"Salary Structure Assignment",
filters={"employee": employee, "docstatus": 1, "from_date": ["<=", start_date]},
fields=["*"],
order_by="from_date desc",
limit=1,
)

return assignments


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def test_india_hra_exemption(self):
frappe.flags.country = "India"

employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
setup_hra_exemption_prerequisites("Monthly", employee)
# structure assigned before payroll period should still be considered as active
setup_hra_exemption_prerequisites("Monthly", employee, from_date=add_months(PAYROLL_PERIOD_START, -1))

declaration = frappe.get_doc(
{
Expand Down Expand Up @@ -321,7 +322,7 @@ def test_india_hra_exemption_with_bimonthly_payroll_frequency(self):
# reset
frappe.flags.country = current_country

def test_india_hra_exemption_with_multiple_salary_structure_assignments(self):
def test_india_hra_exemption_with_multiple_assignments(self):
from hrms.payroll.doctype.salary_slip.test_salary_slip import create_tax_slab
from hrms.payroll.doctype.salary_structure.test_salary_structure import (
create_salary_structure_assignment,
Expand Down Expand Up @@ -471,7 +472,7 @@ def create_exemption_category():
).insert()


def setup_hra_exemption_prerequisites(frequency, employee=None):
def setup_hra_exemption_prerequisites(frequency, employee=None, from_date=None):
from hrms.payroll.doctype.salary_slip.test_salary_slip import create_tax_slab
from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure

Expand Down Expand Up @@ -499,6 +500,7 @@ def setup_hra_exemption_prerequisites(frequency, employee=None):
company="_Test Company",
currency="INR",
payroll_period=payroll_period,
from_date=from_date,
)

frappe.db.set_value(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ def get_last_salary_slip(self, employee):
"docstatus": 1,
"start_date": ["between", [self.payroll_period_start_date, self.payroll_period_end_date]],
},
["start_date", "end_date", "salary_structure", "payroll_frequency"],
["name", "start_date", "end_date", "salary_structure", "payroll_frequency"],
order_by="start_date desc",
as_dict=1,
)
Expand Down Expand Up @@ -423,9 +423,12 @@ def get_applicable_tax(self):
tax_slab = emp_details.get("income_tax_slab")
if tax_slab:
tax_slab = frappe.get_cached_doc("Income Tax Slab", tax_slab)
employee_dict = frappe.get_doc("Employee", emp).as_dict()
eval_globals, eval_locals = self.get_data_for_eval(emp, emp_details)
tax_amount = calculate_tax_by_tax_slab(
emp_details["total_taxable_amount"], tax_slab, eval_globals=None, eval_locals=employee_dict
emp_details["total_taxable_amount"],
tax_slab,
eval_globals=eval_globals,
eval_locals=eval_locals,
)
else:
tax_amount = 0.0
Expand All @@ -434,6 +437,28 @@ def get_applicable_tax(self):
tax_amount = rounded(tax_amount)
emp_details["applicable_tax"] = tax_amount

def get_data_for_eval(self, emp: str, emp_details: dict) -> tuple:
last_ss = self.get_last_salary_slip(emp)

if last_ss:
salary_slip = frappe.get_cached_doc("Salary Slip", last_ss.name)
else:
salary_slip = frappe.new_doc("Salary Slip")
salary_slip.employee = emp
salary_slip.salary_structure = emp_details.salary_structure
salary_slip.start_date = self.payroll_period_start_date
salary_slip.payroll_frequency = frappe.db.get_value(
"Salary Structure", emp_details.salary_structure, "payroll_frequency"
)
salary_slip.end_date = get_start_end_dates(
salary_slip.payroll_frequency, salary_slip.start_date
).end_date
salary_slip.process_salary_structure()

eval_locals, __ = salary_slip.get_data_for_eval()

return salary_slip.whitelisted_globals, eval_locals

def get_total_deducted_tax(self):
self.add_column("Total Tax Deducted")

Expand Down
8 changes: 7 additions & 1 deletion hrms/regional/india/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@ def calculate_annual_eligible_hra_exemption(doc):
_("Salary Structure must be submitted before submission of {0}").format(doc.doctype)
)

assignment_dates = [assignment.from_date for assignment in assignments]
period_start_date = frappe.db.get_value("Payroll Period", doc.payroll_period, "start_date")

assignment_dates = []
for assignment in assignments:
# if assignment is before payroll period, use period start date to get the correct days
assignment.from_date = max(assignment.from_date, period_start_date)
assignment_dates.append(assignment.from_date)

for idx, assignment in enumerate(assignments):
if has_hra_component(assignment.salary_structure, hra_component):
Expand Down

0 comments on commit 5a59bc2

Please sign in to comment.