fix: Tax Declaration tests and amount precision
diff --git a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
index c0ef2ee..3d1d965 100644
--- a/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
+++ b/erpnext/payroll/doctype/employee_tax_exemption_declaration/employee_tax_exemption_declaration.py
@@ -33,7 +33,9 @@
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
@@ -41,9 +43,18 @@
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()
diff --git a/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py b/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
index 6986bce..e158cc3 100644
--- a/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
+++ b/erpnext/payroll/doctype/employee_tax_exemption_declaration/test_employee_tax_exemption_declaration.py
@@ -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(),
@@ -48,7 +49,7 @@
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(),
@@ -70,7 +71,7 @@
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(),
@@ -85,7 +86,7 @@
)
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)
@@ -93,7 +94,7 @@
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(),
@@ -116,13 +117,13 @@
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,
@@ -151,13 +152,13 @@
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,
@@ -181,13 +182,13 @@
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,
@@ -211,13 +212,13 @@
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,
@@ -241,13 +242,13 @@
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,
@@ -281,6 +282,7 @@
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(
@@ -295,8 +297,6 @@
"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",
@@ -343,8 +343,8 @@
{
"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,
@@ -435,7 +435,7 @@
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,
diff --git a/erpnext/regional/india/utils.py b/erpnext/regional/india/utils.py
index 2fc1565..5bbd686 100644
--- a/erpnext/regional/india/utils.py
+++ b/erpnext/regional/india/utils.py
@@ -422,8 +422,8 @@
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,
}
)