fix: Tax Declaration tests and amount precision

This commit is contained in:
Rucha Mahabal 2022-05-11 18:26:33 +05:30 committed by Nabin Hait
parent 5e96a46c87
commit 00adda7c8d
3 changed files with 41 additions and 30 deletions

View File

@ -33,7 +33,9 @@ class EmployeeTaxExemptionDeclaration(Document):
self.total_declared_amount += flt(d.amount) self.total_declared_amount += flt(d.amount)
def set_total_exemption_amount(self): def set_total_exemption_amount(self):
self.total_exemption_amount = get_total_exemption_amount(self.declarations) self.total_exemption_amount = flt(
get_total_exemption_amount(self.declarations), self.precision("total_exemption_amount")
)
def calculate_hra_exemption(self): def calculate_hra_exemption(self):
self.salary_structure_hra, self.annual_hra_exemption, self.monthly_hra_exemption = 0, 0, 0 self.salary_structure_hra, self.annual_hra_exemption, self.monthly_hra_exemption = 0, 0, 0
@ -41,9 +43,18 @@ class EmployeeTaxExemptionDeclaration(Document):
hra_exemption = calculate_annual_eligible_hra_exemption(self) hra_exemption = calculate_annual_eligible_hra_exemption(self)
if hra_exemption: if hra_exemption:
self.total_exemption_amount += hra_exemption["annual_exemption"] self.total_exemption_amount += hra_exemption["annual_exemption"]
self.salary_structure_hra = hra_exemption["hra_amount"] self.total_exemption_amount = flt(
self.annual_hra_exemption = hra_exemption["annual_exemption"] self.total_exemption_amount, self.precision("total_exemption_amount")
self.monthly_hra_exemption = hra_exemption["monthly_exemption"] )
self.salary_structure_hra = flt(
hra_exemption["hra_amount"], self.precision("salary_structure_hra")
)
self.annual_hra_exemption = flt(
hra_exemption["annual_exemption"], self.precision("annual_hra_exemption")
)
self.monthly_hra_exemption = flt(
hra_exemption["monthly_exemption"], self.precision("monthly_hra_exemption")
)
@frappe.whitelist() @frappe.whitelist()

View File

@ -14,17 +14,18 @@ from erpnext.hr.utils import DuplicateDeclarationError
class TestEmployeeTaxExemptionDeclaration(FrappeTestCase): class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def setUp(self): def setUp(self):
make_employee("employee@taxexepmtion.com") make_employee("employee@taxexemption.com", company="_Test Company")
make_employee("employee1@taxexepmtion.com") make_employee("employee1@taxexemption.com", company="_Test Company")
create_payroll_period() create_payroll_period(company="_Test Company")
create_exemption_category() create_exemption_category()
frappe.db.sql("""delete from `tabEmployee Tax Exemption Declaration`""") frappe.db.delete("Employee Tax Exemption Declaration")
frappe.db.delete("Salary Structure Assignment")
def test_duplicate_category_in_declaration(self): def test_duplicate_category_in_declaration(self):
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
"company": erpnext.get_default_company(), "company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period", "payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(), "currency": erpnext.get_default_currency(),
@ -48,7 +49,7 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
"company": erpnext.get_default_company(), "company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period", "payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(), "currency": erpnext.get_default_currency(),
@ -70,7 +71,7 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
duplicate_declaration = frappe.get_doc( duplicate_declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
"company": erpnext.get_default_company(), "company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period", "payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(), "currency": erpnext.get_default_currency(),
@ -85,7 +86,7 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
) )
self.assertRaises(DuplicateDeclarationError, duplicate_declaration.insert) self.assertRaises(DuplicateDeclarationError, duplicate_declaration.insert)
duplicate_declaration.employee = frappe.get_value( duplicate_declaration.employee = frappe.get_value(
"Employee", {"user_id": "employee1@taxexepmtion.com"}, "name" "Employee", {"user_id": "employee1@taxexemption.com"}, "name"
) )
self.assertTrue(duplicate_declaration.insert) self.assertTrue(duplicate_declaration.insert)
@ -93,7 +94,7 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name"), "employee": frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
"company": erpnext.get_default_company(), "company": erpnext.get_default_company(),
"payroll_period": "_Test Payroll Period", "payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(), "currency": erpnext.get_default_currency(),
@ -116,13 +117,13 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def test_india_hra_exemption(self): def test_india_hra_exemption(self):
setup_hra_exemption_prerequisites("Monthly") setup_hra_exemption_prerequisites("Monthly")
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name") employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": "_Test Payroll Period 1",
"currency": "INR", "currency": "INR",
"monthly_house_rent": 50000, "monthly_house_rent": 50000,
@ -151,13 +152,13 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def test_india_hra_exemption_with_daily_payroll_frequency(self): def test_india_hra_exemption_with_daily_payroll_frequency(self):
setup_hra_exemption_prerequisites("Daily") setup_hra_exemption_prerequisites("Daily")
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name") employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": "_Test Payroll Period 1",
"currency": "INR", "currency": "INR",
"monthly_house_rent": 170000, "monthly_house_rent": 170000,
@ -181,13 +182,13 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def test_india_hra_exemption_with_weekly_payroll_frequency(self): def test_india_hra_exemption_with_weekly_payroll_frequency(self):
setup_hra_exemption_prerequisites("Weekly") setup_hra_exemption_prerequisites("Weekly")
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name") employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": "_Test Payroll Period 1",
"currency": "INR", "currency": "INR",
"monthly_house_rent": 170000, "monthly_house_rent": 170000,
@ -211,13 +212,13 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def test_india_hra_exemption_with_fortnightly_payroll_frequency(self): def test_india_hra_exemption_with_fortnightly_payroll_frequency(self):
setup_hra_exemption_prerequisites("Fortnightly") setup_hra_exemption_prerequisites("Fortnightly")
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name") employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": "_Test Payroll Period 1",
"currency": "INR", "currency": "INR",
"monthly_house_rent": 170000, "monthly_house_rent": 170000,
@ -241,13 +242,13 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def test_india_hra_exemption_with_bimonthly_payroll_frequency(self): def test_india_hra_exemption_with_bimonthly_payroll_frequency(self):
setup_hra_exemption_prerequisites("Bimonthly") setup_hra_exemption_prerequisites("Bimonthly")
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name") employee = frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name")
declaration = frappe.get_doc( declaration = frappe.get_doc(
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": "_Test Payroll Period 1",
"currency": "INR", "currency": "INR",
"monthly_house_rent": 50000, "monthly_house_rent": 50000,
@ -281,6 +282,7 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
make_salary_structure, make_salary_structure,
) )
employee = make_employee("employee@taxexemption2.com", company="_Test Company")
payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company") payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company")
create_tax_slab( create_tax_slab(
@ -295,8 +297,6 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
"Company", "_Test Company", {"basic_component": "Basic Salary", "hra_component": "HRA"} "Company", "_Test Company", {"basic_component": "Basic Salary", "hra_component": "HRA"}
) )
employee = frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name")
# salary structure with base 50000, HRA 3000 # salary structure with base 50000, HRA 3000
make_salary_structure( make_salary_structure(
"Monthly Structure for HRA Exemption 1", "Monthly Structure for HRA Exemption 1",
@ -343,8 +343,8 @@ class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
{ {
"doctype": "Employee Tax Exemption Declaration", "doctype": "Employee Tax Exemption Declaration",
"employee": employee, "employee": employee,
"company": "Test Company", "company": "_Test Company",
"payroll_period": "_Test Payroll Period 1", "payroll_period": payroll_period.name,
"currency": "INR", "currency": "INR",
"monthly_house_rent": 50000, "monthly_house_rent": 50000,
"rented_in_metro_city": 1, "rented_in_metro_city": 1,
@ -435,7 +435,7 @@ def setup_hra_exemption_prerequisites(frequency):
make_salary_structure( make_salary_structure(
f"{frequency} Structure for HRA Exemption", f"{frequency} Structure for HRA Exemption",
frequency, frequency,
employee=frappe.get_value("Employee", {"user_id": "employee@taxexepmtion.com"}, "name"), employee=frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
company="_Test Company", company="_Test Company",
currency="INR", currency="INR",
payroll_period=payroll_period, payroll_period=payroll_period,

View File

@ -422,8 +422,8 @@ def calculate_annual_eligible_hra_exemption(doc):
return frappe._dict( return frappe._dict(
{ {
"hra_amount": hra_amount, "hra_amount": hra_amount,
"annual_exemption": flt(annual_exemption, doc.precision("annual_hra_exemption")), "annual_exemption": annual_exemption,
"monthly_exemption": flt(monthly_exemption, doc.precision("monthly_hra_exemption")), "monthly_exemption": monthly_exemption,
} }
) )