Skip to content

Commit

Permalink
fix: Tax Declaration tests and amount precision
Browse files Browse the repository at this point in the history
(cherry picked from commit 00adda7)
  • Loading branch information
ruchamahabal committed May 31, 2022
1 parent c1f6f11 commit 1e728df
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,28 @@ def set_total_declared_amount(self):
self.total_declared_amount += flt(d.amount)

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):
self.salary_structure_hra, self.annual_hra_exemption, self.monthly_hra_exemption = 0, 0, 0
if self.get("monthly_house_rent"):
hra_exemption = calculate_annual_eligible_hra_exemption(self)
if hra_exemption:
self.total_exemption_amount += hra_exemption["annual_exemption"]
self.salary_structure_hra = hra_exemption["hra_amount"]
self.annual_hra_exemption = hra_exemption["annual_exemption"]
self.monthly_hra_exemption = hra_exemption["monthly_exemption"]
self.total_exemption_amount = flt(
self.total_exemption_amount, self.precision("total_exemption_amount")
)
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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@

class TestEmployeeTaxExemptionDeclaration(FrappeTestCase):
def setUp(self):
make_employee("employee@taxexepmtion.com")
make_employee("employee1@taxexepmtion.com")
create_payroll_period()
make_employee("employee@taxexemption.com", company="_Test Company")
make_employee("employee1@taxexemption.com", company="_Test Company")
create_payroll_period(company="_Test Company")
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):
declaration = frappe.get_doc(
{
"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(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
Expand All @@ -48,7 +49,7 @@ def test_duplicate_entry_for_payroll_period(self):
declaration = frappe.get_doc(
{
"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(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
Expand All @@ -70,7 +71,7 @@ def test_duplicate_entry_for_payroll_period(self):
duplicate_declaration = frappe.get_doc(
{
"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(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
Expand All @@ -85,15 +86,15 @@ def test_duplicate_entry_for_payroll_period(self):
)
self.assertRaises(DuplicateDeclarationError, duplicate_declaration.insert)
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)

def test_exemption_amount(self):
declaration = frappe.get_doc(
{
"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(),
"payroll_period": "_Test Payroll Period",
"currency": erpnext.get_default_currency(),
Expand All @@ -116,13 +117,13 @@ def test_exemption_amount(self):

def test_india_hra_exemption(self):
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(
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"company": "_Test Company",
"payroll_period": "_Test Payroll Period 1",
"currency": "INR",
"monthly_house_rent": 50000,
Expand Down Expand Up @@ -151,13 +152,13 @@ def test_india_hra_exemption(self):

def test_india_hra_exemption_with_daily_payroll_frequency(self):
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(
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"company": "_Test Company",
"payroll_period": "_Test Payroll Period 1",
"currency": "INR",
"monthly_house_rent": 170000,
Expand All @@ -181,13 +182,13 @@ def test_india_hra_exemption_with_daily_payroll_frequency(self):

def test_india_hra_exemption_with_weekly_payroll_frequency(self):
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(
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"company": "_Test Company",
"payroll_period": "_Test Payroll Period 1",
"currency": "INR",
"monthly_house_rent": 170000,
Expand All @@ -211,13 +212,13 @@ def test_india_hra_exemption_with_weekly_payroll_frequency(self):

def test_india_hra_exemption_with_fortnightly_payroll_frequency(self):
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(
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"company": "_Test Company",
"payroll_period": "_Test Payroll Period 1",
"currency": "INR",
"monthly_house_rent": 170000,
Expand All @@ -241,13 +242,13 @@ def test_india_hra_exemption_with_fortnightly_payroll_frequency(self):

def test_india_hra_exemption_with_bimonthly_payroll_frequency(self):
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(
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"company": "_Test Company",
"payroll_period": "_Test Payroll Period 1",
"currency": "INR",
"monthly_house_rent": 50000,
Expand Down Expand Up @@ -281,6 +282,7 @@ def test_india_hra_exemption_with_multiple_salary_structure_assignments(self):
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")

create_tax_slab(
Expand All @@ -295,8 +297,6 @@ def test_india_hra_exemption_with_multiple_salary_structure_assignments(self):
"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
make_salary_structure(
"Monthly Structure for HRA Exemption 1",
Expand Down Expand Up @@ -343,8 +343,8 @@ def test_india_hra_exemption_with_multiple_salary_structure_assignments(self):
{
"doctype": "Employee Tax Exemption Declaration",
"employee": employee,
"company": "Test Company",
"payroll_period": "_Test Payroll Period 1",
"company": "_Test Company",
"payroll_period": payroll_period.name,
"currency": "INR",
"monthly_house_rent": 50000,
"rented_in_metro_city": 1,
Expand Down Expand Up @@ -435,7 +435,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@taxexepmtion.com"}, "name"),
employee=frappe.get_value("Employee", {"user_id": "employee@taxexemption.com"}, "name"),
company="_Test Company",
currency="INR",
payroll_period=payroll_period,
Expand Down
4 changes: 2 additions & 2 deletions erpnext/regional/india/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -427,8 +427,8 @@ def calculate_annual_eligible_hra_exemption(doc):
return frappe._dict(
{
"hra_amount": hra_amount,
"annual_exemption": flt(annual_exemption, doc.precision("annual_hra_exemption")),
"monthly_exemption": flt(monthly_exemption, doc.precision("monthly_hra_exemption")),
"annual_exemption": annual_exemption,
"monthly_exemption": monthly_exemption,
}
)

Expand Down

0 comments on commit 1e728df

Please sign in to comment.