fix: incorrect tax calculation in case of reduced payment days
This commit is contained in:
@@ -622,7 +622,7 @@ class SalarySlip(TransactionBase):
|
||||
self.add_tax_components(payroll_period)
|
||||
|
||||
def add_structure_components(self, component_type):
|
||||
data = self.get_data_for_eval()
|
||||
data, default_data = self.get_data_for_eval()
|
||||
timesheet_component = frappe.db.get_value(
|
||||
"Salary Structure", self.salary_structure, "salary_component"
|
||||
)
|
||||
@@ -635,7 +635,10 @@ class SalarySlip(TransactionBase):
|
||||
if (
|
||||
amount or (struct_row.amount_based_on_formula and amount is not None)
|
||||
) and struct_row.statistical_component == 0:
|
||||
self.update_component_row(struct_row, amount, component_type, data=data)
|
||||
default_amount = self.eval_condition_and_formula(struct_row, default_data)
|
||||
self.update_component_row(
|
||||
struct_row, amount, component_type, data=data, default_amount=default_amount
|
||||
)
|
||||
|
||||
def get_data_for_eval(self):
|
||||
"""Returns data for evaluating formula"""
|
||||
@@ -679,11 +682,15 @@ class SalarySlip(TransactionBase):
|
||||
for sc in salary_components:
|
||||
data.setdefault(sc.salary_component_abbr, 0)
|
||||
|
||||
# shallow copy of data to store default amounts (without payment days) for tax calculation
|
||||
default_data = data.copy()
|
||||
|
||||
for key in ("earnings", "deductions"):
|
||||
for d in self.get(key):
|
||||
default_data[d.abbr] = d.default_amount
|
||||
data[d.abbr] = d.amount
|
||||
|
||||
return data
|
||||
return data, default_data
|
||||
|
||||
def eval_condition_and_formula(self, d, data):
|
||||
try:
|
||||
@@ -789,7 +796,14 @@ class SalarySlip(TransactionBase):
|
||||
self.update_component_row(tax_row, tax_amount, "deductions")
|
||||
|
||||
def update_component_row(
|
||||
self, component_data, amount, component_type, additional_salary=None, is_recurring=0, data=None
|
||||
self,
|
||||
component_data,
|
||||
amount,
|
||||
component_type,
|
||||
additional_salary=None,
|
||||
is_recurring=0,
|
||||
data=None,
|
||||
default_amount=None,
|
||||
):
|
||||
component_row = None
|
||||
for d in self.get(component_type):
|
||||
@@ -850,7 +864,7 @@ class SalarySlip(TransactionBase):
|
||||
additional_salary.deduct_full_tax_on_selected_payroll_date
|
||||
)
|
||||
else:
|
||||
component_row.default_amount = amount
|
||||
component_row.default_amount = default_amount or amount
|
||||
component_row.additional_amount = 0
|
||||
component_row.deduct_full_tax_on_selected_payroll_date = (
|
||||
component_data.deduct_full_tax_on_selected_payroll_date
|
||||
@@ -1283,7 +1297,7 @@ class SalarySlip(TransactionBase):
|
||||
)[0].total_amount
|
||||
|
||||
def calculate_tax_by_tax_slab(self, annual_taxable_earning, tax_slab):
|
||||
data = self.get_data_for_eval()
|
||||
data, default_data = self.get_data_for_eval()
|
||||
data.update({"annual_taxable_earning": annual_taxable_earning})
|
||||
tax_amount = 0
|
||||
for slab in tax_slab.slabs:
|
||||
|
||||
Reference in New Issue
Block a user