test: HRA Exemption in Proof Submission
This commit is contained in:
parent
cfe2f8cac1
commit
ed1ba677d6
@ -460,11 +460,13 @@ def create_exemption_category():
|
||||
).insert()
|
||||
|
||||
|
||||
def setup_hra_exemption_prerequisites(frequency):
|
||||
def setup_hra_exemption_prerequisites(frequency, employee=None):
|
||||
from erpnext.payroll.doctype.salary_slip.test_salary_slip import create_tax_slab
|
||||
from erpnext.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
|
||||
|
||||
payroll_period = create_payroll_period(name="_Test Payroll Period", company="_Test Company")
|
||||
if not employee:
|
||||
employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
|
||||
|
||||
create_tax_slab(
|
||||
payroll_period,
|
||||
@ -477,7 +479,7 @@ def setup_hra_exemption_prerequisites(frequency):
|
||||
make_salary_structure(
|
||||
f"{frequency} Structure for HRA Exemption",
|
||||
frequency,
|
||||
employee=frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
|
||||
employee=employee,
|
||||
company="_Test Company",
|
||||
currency="INR",
|
||||
payroll_period=payroll_period,
|
||||
|
@ -4,22 +4,26 @@
|
||||
import unittest
|
||||
|
||||
import frappe
|
||||
from frappe.tests.utils import FrappeTestCase
|
||||
|
||||
from erpnext.hr.doctype.employee.test_employee import make_employee
|
||||
from erpnext.payroll.doctype.employee_tax_exemption_declaration.test_employee_tax_exemption_declaration import (
|
||||
create_exemption_category,
|
||||
create_payroll_period,
|
||||
setup_hra_exemption_prerequisites,
|
||||
)
|
||||
|
||||
|
||||
class TestEmployeeTaxExemptionProofSubmission(unittest.TestCase):
|
||||
def setup(self):
|
||||
make_employee("employee@proofsubmission.com")
|
||||
create_payroll_period()
|
||||
class TestEmployeeTaxExemptionProofSubmission(FrappeTestCase):
|
||||
def setUp(self):
|
||||
make_employee("employee@proofsubmission.com", company="_Test Company")
|
||||
create_payroll_period(company="_Test Company")
|
||||
create_exemption_category()
|
||||
frappe.db.sql("""delete from `tabEmployee Tax Exemption Proof Submission`""")
|
||||
frappe.db.delete("Employee Tax Exemption Proof Submission")
|
||||
frappe.db.delete("Salary Structure Assignment")
|
||||
|
||||
def test_exemption_amount_lesser_than_category_max(self):
|
||||
declaration = frappe.get_doc(
|
||||
proof = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee Tax Exemption Proof Submission",
|
||||
"employee": frappe.get_value("Employee", {"user_id": "employee@proofsubmission.com"}, "name"),
|
||||
@ -34,8 +38,8 @@ class TestEmployeeTaxExemptionProofSubmission(unittest.TestCase):
|
||||
],
|
||||
}
|
||||
)
|
||||
self.assertRaises(frappe.ValidationError, declaration.save)
|
||||
declaration = frappe.get_doc(
|
||||
self.assertRaises(frappe.ValidationError, proof.save)
|
||||
proof = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee Tax Exemption Proof Submission",
|
||||
"payroll_period": "Test Payroll Period",
|
||||
@ -50,11 +54,11 @@ class TestEmployeeTaxExemptionProofSubmission(unittest.TestCase):
|
||||
],
|
||||
}
|
||||
)
|
||||
self.assertTrue(declaration.save)
|
||||
self.assertTrue(declaration.submit)
|
||||
self.assertTrue(proof.save)
|
||||
self.assertTrue(proof.submit)
|
||||
|
||||
def test_duplicate_category_in_proof_submission(self):
|
||||
declaration = frappe.get_doc(
|
||||
proof = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee Tax Exemption Proof Submission",
|
||||
"employee": frappe.get_value("Employee", {"user_id": "employee@proofsubmission.com"}, "name"),
|
||||
@ -74,4 +78,59 @@ class TestEmployeeTaxExemptionProofSubmission(unittest.TestCase):
|
||||
],
|
||||
}
|
||||
)
|
||||
self.assertRaises(frappe.ValidationError, declaration.save)
|
||||
self.assertRaises(frappe.ValidationError, proof.save)
|
||||
|
||||
def test_india_hra_exemption(self):
|
||||
# set country
|
||||
current_country = frappe.flags.country
|
||||
frappe.flags.country = "India"
|
||||
|
||||
employee = frappe.get_value("Employee", {"user_id": "employee@proofsubmission.com"}, "name")
|
||||
setup_hra_exemption_prerequisites("Monthly", employee)
|
||||
payroll_period = frappe.db.get_value(
|
||||
"Payroll Period", "_Test Payroll Period", ["start_date", "end_date"], as_dict=True
|
||||
)
|
||||
|
||||
proof = frappe.get_doc(
|
||||
{
|
||||
"doctype": "Employee Tax Exemption Proof Submission",
|
||||
"employee": employee,
|
||||
"company": "_Test Company",
|
||||
"payroll_period": "_Test Payroll Period",
|
||||
"currency": "INR",
|
||||
"house_rent_payment_amount": 600000,
|
||||
"rented_in_metro_city": 1,
|
||||
"rented_from_date": payroll_period.start_date,
|
||||
"rented_to_date": payroll_period.end_date,
|
||||
"tax_exemption_proofs": [
|
||||
dict(
|
||||
exemption_sub_category="_Test Sub Category",
|
||||
exemption_category="_Test Category",
|
||||
type_of_proof="Test Proof",
|
||||
amount=100000,
|
||||
),
|
||||
dict(
|
||||
exemption_sub_category="_Test1 Sub Category",
|
||||
exemption_category="_Test Category",
|
||||
type_of_proof="Test Proof",
|
||||
amount=50000,
|
||||
),
|
||||
],
|
||||
}
|
||||
).insert()
|
||||
|
||||
self.assertEqual(proof.monthly_house_rent, 50000)
|
||||
|
||||
# Monthly HRA received = 3000
|
||||
# should set HRA exemption as per actual annual HRA because that's the minimum
|
||||
self.assertEqual(proof.monthly_hra_exemption, 3000)
|
||||
self.assertEqual(proof.total_eligible_hra_exemption, 36000)
|
||||
|
||||
# total exemptions + house rent payment amount
|
||||
self.assertEqual(proof.total_actual_amount, 750000)
|
||||
|
||||
# 100000 Standard Exemption + 36000 HRA exemption
|
||||
self.assertEqual(proof.exemption_amount, 136000)
|
||||
|
||||
# reset
|
||||
frappe.flags.country = current_country
|
||||
|
Loading…
x
Reference in New Issue
Block a user