Skip to content

Commit

Permalink
fix: test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
saurabh6790 committed Feb 17, 2023
1 parent 0dfca8d commit dc589d9
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 52 deletions.
44 changes: 26 additions & 18 deletions hrms/payroll/doctype/salary_slip/salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -588,9 +588,11 @@ def add_earning_for_hourly_wages(self, doc, salary_component, amount):

def calculate_net_pay(self):
if self.salary_structure:
self.calculate_component_amounts("earnings")

if self.payroll_period and self.salary_structure:
self.tax_slab = self.get_income_tax_slabs()
self.compute_taxable_earnings_for_year()
self.calculate_component_amounts("earnings")

self.gross_pay = self.get_component_totals("earnings", depends_on_payment_days=1)
self.base_gross_pay = flt(
Expand Down Expand Up @@ -652,17 +654,17 @@ def compute_taxable_earnings_for_year(self):
self.current_taxable_earnings_for_payment_days.additional_income_with_full_tax
)

# Get taxable unclaimed benefits
self.unclaimed_taxable_benefits = 0
if self.deduct_tax_for_unclaimed_employee_benefits:
unclaimed_taxable_benefits = self.calculate_unclaimed_taxable_benefits()
unclaimed_taxable_benefits += self.current_taxable_earnings_for_payment_days.flexi_benefits

# Deduct taxes forcefully for unsubmitted tax exemption proof and unclaimed benefits in the last period
if self.payroll_period.end_date <= getdate(self.end_date):
self.deduct_tax_for_unsubmitted_tax_exemption_proof = 1
self.deduct_tax_for_unclaimed_employee_benefits = 1

# Get taxable unclaimed benefits
self.unclaimed_taxable_benefits = 0
if self.deduct_tax_for_unclaimed_employee_benefits:
self.unclaimed_taxable_benefits = self.calculate_unclaimed_taxable_benefits()
self.unclaimed_taxable_benefits += self.current_taxable_earnings_for_payment_days.flexi_benefits

# Total exemption amount based on tax exemption declaration
self.total_exemption_amount = self.get_total_exemption_amount()

Expand All @@ -686,9 +688,12 @@ def compute_taxable_earnings_for_year(self):
)

def compute_income_tax_breakup(self):
if not self.payroll_period:
return

self.non_taxable_earnings = self.get_non_taxable_earnings()

self.ctc = self.get_ctc()
self.ctc = self.compute_ctc()

self.income_from_other_sources = self.get_income_form_other_sources()

Expand Down Expand Up @@ -718,16 +723,19 @@ def compute_income_tax_breakup(self):
self.total_structured_tax_amount - self.income_tax_deducted_till_date
)

def get_ctc(self):
return (
self.previous_taxable_earnings
+ self.current_structured_taxable_earnings
+ self.future_structured_taxable_earnings
+ self.current_additional_earnings
+ self.other_incomes
+ self.unclaimed_taxable_benefits
+ self.additional_non_taxable_earnings
) or 0.0
def compute_ctc(self):
if hasattr(self, "self.previous_taxable_earnings"):
return (
self.previous_taxable_earnings
+ self.current_structured_taxable_earnings
+ self.future_structured_taxable_earnings
+ self.current_additional_earnings
+ self.other_incomes
+ self.unclaimed_taxable_benefits
+ self.additional_non_taxable_earnings
)
else:
return 0.0

def get_non_taxable_earnings(self):
sal_struc_non_taxable_earnings = 0
Expand Down
71 changes: 37 additions & 34 deletions hrms/payroll/doctype/salary_slip/test_salary_slip.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def test_loan_repayment_salary_slip(self):
repayment_schedule_type="Monthly as per repayment start date",
)

payroll_period = create_payroll_period(name="_Test Payroll Period 1", company="_Test Company")
payroll_period = create_payroll_period(name="_Test Payroll Period", company="_Test Company")

make_salary_structure(
"Test Loan Repayment Salary Structure",
Expand Down Expand Up @@ -712,7 +712,7 @@ def test_year_to_date_computation(self):

applicant = make_employee("[email protected]", 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", company="_Test Company")

create_tax_slab(
payroll_period,
Expand Down Expand Up @@ -756,7 +756,7 @@ def test_component_wise_year_to_date_computation(self):
employee_name = "[email protected]"
applicant = make_employee(employee_name, 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", company="_Test Company")

create_tax_slab(
payroll_period,
Expand Down Expand Up @@ -1085,29 +1085,16 @@ def test_salary_slip_generation_against_opening_entries_in_ssa(self):

from hrms.payroll.doctype.payroll_period.payroll_period import get_period_factor
from hrms.payroll.doctype.salary_structure.test_salary_structure import make_salary_structure
from hrms.payroll.report.income_tax_computation.income_tax_computation import (
IncomeTaxComputationReport,
)

payroll_period = frappe.db.get_value(
"Payroll Period",
{
"company": "_Test Company",
"start_date": ["<=", "2023-03-31"],
"end_date": [">=", "2022-04-01"],
},
"name",
)
frappe.db.sql("DELETE FROM `tabPayroll Period` where company = '_Test Company'")
frappe.db.sql("DELETE FROM `tabIncome Tax Slab` where currency = 'INR'")

if not payroll_period:
payroll_period = create_payroll_period(
name="_Test Payroll Period for Tax",
company="_Test Company",
start_date="2022-04-01",
end_date="2023-03-31",
)
else:
payroll_period = frappe.get_cached_doc("Payroll Period", payroll_period)
payroll_period = create_payroll_period(
name="_Test Payroll Period for Tax",
company="_Test Company",
start_date="2022-04-01",
end_date="2023-03-31",
)

emp = make_employee(
"[email protected]",
Expand All @@ -1116,7 +1103,7 @@ def test_salary_slip_generation_against_opening_entries_in_ssa(self):
)
employee_doc = frappe.get_doc("Employee", emp)

create_tax_slab(payroll_period, allow_tax_exemption=True)
create_tax_slab(payroll_period, effective_date="2022-04-01", allow_tax_exemption=True)

salary_structure_name = "Test Salary Structure for Opening Balance"
if not frappe.db.exists("Salary Structure", salary_structure_name):
Expand Down Expand Up @@ -1155,15 +1142,6 @@ def test_salary_slip_generation_against_opening_entries_in_ssa(self):

prev_period = math.ceil(remaining_sub_periods)

# Set annual and monthly tax amount and earnings
# col, data = IncomeTaxComputationReport(
# {
# "company": "_Test Company",
# "payroll_period": payroll_period.name,
# "employee": employee_doc.name
# }
# ).run()

annual_tax = 93036 # 89220 #data[0].get('applicable_tax')
monthly_tax_amount = 7732.40 # 7435 #annual_tax/12
annual_earnings = 933600 # data[0].get('ctc')
Expand All @@ -1190,6 +1168,9 @@ def test_salary_slip_generation_against_opening_entries_in_ssa(self):
if deduction.salary_component == "TDS":
self.assertEqual(deduction.amount, rounded(monthly_tax_amount))

frappe.db.sql("DELETE FROM `tabPayroll Period` where company = '_Test Company'")
frappe.db.sql("DELETE FROM `tabIncome Tax Slab` where currency = 'INR'")


def get_no_of_days():
no_of_days_in_month = calendar.monthrange(getdate(nowdate()).year, getdate(nowdate()).month)
Expand Down Expand Up @@ -1516,6 +1497,7 @@ def create_tax_slab(
]

income_tax_slab_name = frappe.db.get_value("Income Tax Slab", {"currency": currency})

if not income_tax_slab_name:
income_tax_slab = frappe.new_doc("Income Tax Slab")
income_tax_slab.name = "Tax Slab: " + payroll_period.name + " " + cstr(currency)
Expand Down Expand Up @@ -1640,6 +1622,7 @@ def setup_test():
frappe.db.sql("delete from `tab%s`" % dt)

make_holiday_list()
make_payroll_period()

frappe.db.set_value(
"Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List"
Expand All @@ -1650,6 +1633,26 @@ def setup_test():
frappe.db.set_value("HR Settings", None, "leave_approval_notification_template", None)


def make_payroll_period():
default_company = erpnext.get_default_company()
company_based_payroll_period = {
default_company: f"_Test Payroll Period {default_company}",
"_Test Company": "_Test Payroll Period",
}
for company in company_based_payroll_period:
payroll_period = frappe.db.get_value(
"Payroll Period",
{
"company": company,
"start_date": get_year_start(nowdate()),
"end_date": get_year_ending(nowdate()),
},
)

if not payroll_period:
pp = create_payroll_period(company=company, name=company_based_payroll_period[company])


def make_holiday_list(list_name=None, from_date=None, to_date=None):
fiscal_year = get_fiscal_year(nowdate(), company=erpnext.get_default_company())
name = list_name or "Salary Slip Test Holiday List"
Expand Down

0 comments on commit dc589d9

Please sign in to comment.