diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py index 8a1e8cdc03..80c9b83626 100644 --- a/hrms/payroll/doctype/salary_slip/salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/salary_slip.py @@ -624,9 +624,11 @@ 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() + # get remaining numbers of sub-period (period for which one salary is processed) + if self.payroll_period: + self.remaining_sub_periods = get_period_factor( + self.employee, self.start_date, self.end_date, self.payroll_frequency, self.payroll_period + )[1] self.gross_pay = self.get_component_totals("earnings", depends_on_payment_days=1) self.base_gross_pay = flt( @@ -703,11 +705,6 @@ def compute_taxable_earnings_for_year(self): ) def compute_current_and_future_taxable_earnings(self): - # get remaining numbers of sub-period (period for which one salary is processed) - self.remaining_sub_periods = get_period_factor( - self.employee, self.start_date, self.end_date, self.payroll_frequency, self.payroll_period - )[1] - # get taxable_earnings for current period (all days) self.current_taxable_earnings = self.get_taxable_earnings(self.tax_slab.allow_tax_exemption) self.future_structured_taxable_earnings = self.current_taxable_earnings.taxable_earnings * ( @@ -747,6 +744,9 @@ def compute_income_tax_breakup(self): if not self.payroll_period: return + self.standard_tax_exemption_amount = 0 + self.tax_exemption_declaration = 0 + self.non_taxable_earnings = self.compute_non_taxable_earnings() self.ctc = self.compute_ctc() @@ -757,13 +757,14 @@ def compute_income_tax_breakup(self): self.deductions_before_tax_calculation = self.compute_annual_deductions_before_tax_calculation() - self.standard_tax_exemption_amount = ( - self.tax_slab.standard_tax_exemption_amount if self.tax_slab.allow_tax_exemption else 0.0 - ) + if hasattr(self, "tax_slab"): + self.standard_tax_exemption_amount = ( + self.tax_slab.standard_tax_exemption_amount if self.tax_slab.allow_tax_exemption else 0.0 + ) - self.tax_exemption_declaration = ( - self.get_total_exemption_amount() - self.standard_tax_exemption_amount - ) + self.tax_exemption_declaration = ( + self.get_total_exemption_amount() - self.standard_tax_exemption_amount + ) self.annual_taxable_amount = self.total_earnings - ( self.non_taxable_earnings @@ -1129,6 +1130,10 @@ def add_tax_components(self): if d.name not in self.other_deduction_components ] + if tax_components and self.payroll_period and self.salary_structure: + self.tax_slab = self.get_income_tax_slabs() + self.compute_taxable_earnings_for_year() + self.component_based_veriable_tax = {} for d in tax_components: self.component_based_veriable_tax.setdefault(d, {}) diff --git a/hrms/payroll/doctype/salary_slip/test_salary_slip.py b/hrms/payroll/doctype/salary_slip/test_salary_slip.py index 969a240b7f..3b7f4444be 100644 --- a/hrms/payroll/doctype/salary_slip/test_salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/test_salary_slip.py @@ -1164,7 +1164,7 @@ def test_salary_slip_generation_against_opening_entries_in_ssa(self): ) for deduction in salary_slip.deductions: if deduction.salary_component == "TDS": - self.assertEqual(deduction.amount, 7732.0) + self.assertEqual(deduction.amount, 7691.0) frappe.db.sql("DELETE FROM `tabPayroll Period` where company = '_Test Company'") frappe.db.sql("DELETE FROM `tabIncome Tax Slab` where currency = 'INR'") @@ -1211,7 +1211,7 @@ def test_income_tax_breakup_fields(self): salary_structure_doc.name, employee=employee_doc.name, posting_date=payroll_period.start_date ) - monthly_tax_amount = 11466.0 + monthly_tax_amount = 11403.6 self.assertEqual(salary_slip.ctc, 1226000.0) self.assertEqual(salary_slip.income_from_other_sources, 10000.0) @@ -1221,10 +1221,10 @@ def test_income_tax_breakup_fields(self): self.assertEqual(salary_slip.tax_exemption_declaration, 100000.0) self.assertEqual(salary_slip.deductions_before_tax_calculation, 2400.0) self.assertEqual(salary_slip.annual_taxable_amount, 1073600.0) - self.assertEqual(flt(salary_slip.income_tax_deducted_till_date, 1), monthly_tax_amount) - self.assertEqual(flt(salary_slip.current_month_income_tax, 1), monthly_tax_amount) - self.assertEqual(flt(salary_slip.future_income_tax_deductions, 1), 126126.0) - self.assertEqual(flt(salary_slip.total_income_tax, 0), 137592) + self.assertEqual(flt(salary_slip.income_tax_deducted_till_date, 2), monthly_tax_amount) + self.assertEqual(flt(salary_slip.current_month_income_tax, 2), monthly_tax_amount) + self.assertEqual(flt(salary_slip.future_income_tax_deductions, 2), 125439.65) + self.assertEqual(flt(salary_slip.total_income_tax, 2), 136843.25) @change_settings("Payroll Settings", {"payroll_based_on": "Leave"}) def test_lwp_calculation_based_on_relieving_date(self):