From 2f3adbebae425d5ee6bc209fa4e5033944aa2c2a Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 15 Mar 2023 16:31:55 +0530 Subject: [PATCH 1/2] fix: get income tax slab only if tax compoents are applicable (cherry picked from commit 563394a9c6febaf88bbab000e2c0558231cc671f) --- .../doctype/salary_slip/salary_slip.py | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py index 8a1e8cdc03..7671ba8eec 100644 --- a/hrms/payroll/doctype/salary_slip/salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/salary_slip.py @@ -624,9 +624,10 @@ 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) + 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 +704,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 +743,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 +756,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 +1129,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, {}) From 784677212d0e2c08054d8ef7833121e252fd5ae9 Mon Sep 17 00:00:00 2001 From: Saurabh Date: Wed, 15 Mar 2023 18:36:11 +0530 Subject: [PATCH 2/2] test: fix test cases (cherry picked from commit b85a4277f19c5b4373c87933ec15b17e0743a4dc) --- hrms/payroll/doctype/salary_slip/salary_slip.py | 7 ++++--- hrms/payroll/doctype/salary_slip/test_salary_slip.py | 12 ++++++------ 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/hrms/payroll/doctype/salary_slip/salary_slip.py b/hrms/payroll/doctype/salary_slip/salary_slip.py index 7671ba8eec..80c9b83626 100644 --- a/hrms/payroll/doctype/salary_slip/salary_slip.py +++ b/hrms/payroll/doctype/salary_slip/salary_slip.py @@ -625,9 +625,10 @@ def calculate_net_pay(self): self.calculate_component_amounts("earnings") # 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] + 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( 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):