mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-13 10:11:20 +00:00
fix: tax calculation on salary slip for the first month (#24272)
* fix: tax calculation on salary slip for the first month * fix: net pay precision issue * fix: net pay precision issue Co-authored-by: Anurag Mishra <32095923+Anurag810@users.noreply.github.com>
This commit is contained in:
@@ -813,7 +813,7 @@
|
|||||||
"idx": 24,
|
"idx": 24,
|
||||||
"image_field": "image",
|
"image_field": "image",
|
||||||
"links": [],
|
"links": [],
|
||||||
"modified": "2020-10-16 15:02:04.283657",
|
"modified": "2021-01-01 16:54:33.477439",
|
||||||
"modified_by": "Administrator",
|
"modified_by": "Administrator",
|
||||||
"module": "HR",
|
"module": "HR",
|
||||||
"name": "Employee",
|
"name": "Employee",
|
||||||
@@ -855,7 +855,6 @@
|
|||||||
"write": 1
|
"write": 1
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"quick_entry": 1,
|
|
||||||
"search_fields": "employee_name",
|
"search_fields": "employee_name",
|
||||||
"show_name_in_global_search": 1,
|
"show_name_in_global_search": 1,
|
||||||
"sort_field": "modified",
|
"sort_field": "modified",
|
||||||
|
|||||||
@@ -151,7 +151,6 @@ frappe.ui.form.on("Salary Slip", {
|
|||||||
var salary_detail_fields = ["formula", "abbr", "statistical_component", "variable_based_on_taxable_salary"];
|
var salary_detail_fields = ["formula", "abbr", "statistical_component", "variable_based_on_taxable_salary"];
|
||||||
frm.fields_dict['earnings'].grid.set_column_disp(salary_detail_fields, false);
|
frm.fields_dict['earnings'].grid.set_column_disp(salary_detail_fields, false);
|
||||||
frm.fields_dict['deductions'].grid.set_column_disp(salary_detail_fields, false);
|
frm.fields_dict['deductions'].grid.set_column_disp(salary_detail_fields, false);
|
||||||
calculate_totals(frm);
|
|
||||||
frm.trigger("set_dynamic_labels");
|
frm.trigger("set_dynamic_labels");
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|||||||
@@ -143,8 +143,8 @@ class SalarySlip(TransactionBase):
|
|||||||
self.salary_slip_based_on_timesheet = self._salary_structure_doc.salary_slip_based_on_timesheet or 0
|
self.salary_slip_based_on_timesheet = self._salary_structure_doc.salary_slip_based_on_timesheet or 0
|
||||||
self.set_time_sheet()
|
self.set_time_sheet()
|
||||||
self.pull_sal_struct()
|
self.pull_sal_struct()
|
||||||
payroll_based_on, consider_unmarked_attendance_as = frappe.db.get_value("Payroll Settings", None, ["payroll_based_on","consider_unmarked_attendance_as"])
|
ps = frappe.db.get_value("Payroll Settings", None, ["payroll_based_on","consider_unmarked_attendance_as"], as_dict=1)
|
||||||
return [payroll_based_on, consider_unmarked_attendance_as]
|
return [ps.payroll_based_on, ps.consider_unmarked_attendance_as]
|
||||||
|
|
||||||
def set_time_sheet(self):
|
def set_time_sheet(self):
|
||||||
if self.salary_slip_based_on_timesheet:
|
if self.salary_slip_based_on_timesheet:
|
||||||
@@ -424,16 +424,19 @@ class SalarySlip(TransactionBase):
|
|||||||
def calculate_net_pay(self):
|
def calculate_net_pay(self):
|
||||||
if self.salary_structure:
|
if self.salary_structure:
|
||||||
self.calculate_component_amounts("earnings")
|
self.calculate_component_amounts("earnings")
|
||||||
self.gross_pay = self.get_component_totals("earnings")
|
self.gross_pay = self.get_component_totals("earnings", depends_on_payment_days=1)
|
||||||
self.base_gross_pay = flt(flt(self.gross_pay) * flt(self.exchange_rate), self.precision('base_gross_pay'))
|
self.base_gross_pay = flt(flt(self.gross_pay) * flt(self.exchange_rate), self.precision('base_gross_pay'))
|
||||||
|
|
||||||
if self.salary_structure:
|
if self.salary_structure:
|
||||||
self.calculate_component_amounts("deductions")
|
self.calculate_component_amounts("deductions")
|
||||||
self.total_deduction = self.get_component_totals("deductions")
|
|
||||||
self.base_total_deduction = flt(flt(self.total_deduction) * flt(self.exchange_rate), self.precision('base_total_deduction'))
|
|
||||||
|
|
||||||
self.set_loan_repayment()
|
self.set_loan_repayment()
|
||||||
|
self.set_component_amounts_based_on_payment_days()
|
||||||
|
self.set_net_pay()
|
||||||
|
|
||||||
|
def set_net_pay(self):
|
||||||
|
self.total_deduction = self.get_component_totals("deductions")
|
||||||
|
self.base_total_deduction = flt(flt(self.total_deduction) * flt(self.exchange_rate), self.precision('base_total_deduction'))
|
||||||
self.net_pay = flt(self.gross_pay) - (flt(self.total_deduction) + flt(self.total_loan_repayment))
|
self.net_pay = flt(self.gross_pay) - (flt(self.total_deduction) + flt(self.total_loan_repayment))
|
||||||
self.rounded_total = rounded(self.net_pay)
|
self.rounded_total = rounded(self.net_pay)
|
||||||
self.base_net_pay = flt(flt(self.net_pay) * flt(self.exchange_rate), self.precision('base_net_pay'))
|
self.base_net_pay = flt(flt(self.net_pay) * flt(self.exchange_rate), self.precision('base_net_pay'))
|
||||||
@@ -455,8 +458,6 @@ class SalarySlip(TransactionBase):
|
|||||||
else:
|
else:
|
||||||
self.add_tax_components(payroll_period)
|
self.add_tax_components(payroll_period)
|
||||||
|
|
||||||
self.set_component_amounts_based_on_payment_days(component_type)
|
|
||||||
|
|
||||||
def add_structure_components(self, component_type):
|
def add_structure_components(self, component_type):
|
||||||
data = self.get_data_for_eval()
|
data = self.get_data_for_eval()
|
||||||
for struct_row in self._salary_structure_doc.get(component_type):
|
for struct_row in self._salary_structure_doc.get(component_type):
|
||||||
@@ -813,7 +814,7 @@ class SalarySlip(TransactionBase):
|
|||||||
cint(row.depends_on_payment_days) and cint(self.total_working_days) and
|
cint(row.depends_on_payment_days) and cint(self.total_working_days) and
|
||||||
(not self.salary_slip_based_on_timesheet or
|
(not self.salary_slip_based_on_timesheet or
|
||||||
getdate(self.start_date) < joining_date or
|
getdate(self.start_date) < joining_date or
|
||||||
getdate(self.end_date) > relieving_date
|
(relieving_date and getdate(self.end_date) > relieving_date)
|
||||||
)):
|
)):
|
||||||
additional_amount = flt((flt(row.additional_amount) * flt(self.payment_days)
|
additional_amount = flt((flt(row.additional_amount) * flt(self.payment_days)
|
||||||
/ cint(self.total_working_days)), row.precision("additional_amount"))
|
/ cint(self.total_working_days)), row.precision("additional_amount"))
|
||||||
@@ -946,15 +947,21 @@ class SalarySlip(TransactionBase):
|
|||||||
struct_row['variable_based_on_taxable_salary'] = component.variable_based_on_taxable_salary
|
struct_row['variable_based_on_taxable_salary'] = component.variable_based_on_taxable_salary
|
||||||
return struct_row
|
return struct_row
|
||||||
|
|
||||||
def get_component_totals(self, component_type):
|
def get_component_totals(self, component_type, depends_on_payment_days=0):
|
||||||
|
joining_date, relieving_date = frappe.get_cached_value("Employee", self.employee,
|
||||||
|
["date_of_joining", "relieving_date"])
|
||||||
|
|
||||||
total = 0.0
|
total = 0.0
|
||||||
for d in self.get(component_type):
|
for d in self.get(component_type):
|
||||||
if not d.do_not_include_in_total:
|
if not d.do_not_include_in_total:
|
||||||
d.amount = flt(d.amount, d.precision("amount"))
|
if depends_on_payment_days:
|
||||||
total += d.amount
|
amount = self.get_amount_based_on_payment_days(d, joining_date, relieving_date)[0]
|
||||||
|
else:
|
||||||
|
amount = flt(d.amount, d.precision("amount"))
|
||||||
|
total += amount
|
||||||
return total
|
return total
|
||||||
|
|
||||||
def set_component_amounts_based_on_payment_days(self, component_type):
|
def set_component_amounts_based_on_payment_days(self):
|
||||||
joining_date, relieving_date = frappe.get_cached_value("Employee", self.employee,
|
joining_date, relieving_date = frappe.get_cached_value("Employee", self.employee,
|
||||||
["date_of_joining", "relieving_date"])
|
["date_of_joining", "relieving_date"])
|
||||||
|
|
||||||
@@ -964,8 +971,9 @@ class SalarySlip(TransactionBase):
|
|||||||
if not joining_date:
|
if not joining_date:
|
||||||
frappe.throw(_("Please set the Date Of Joining for employee {0}").format(frappe.bold(self.employee_name)))
|
frappe.throw(_("Please set the Date Of Joining for employee {0}").format(frappe.bold(self.employee_name)))
|
||||||
|
|
||||||
for d in self.get(component_type):
|
for component_type in ("earnings", "deductions"):
|
||||||
d.amount = self.get_amount_based_on_payment_days(d, joining_date, relieving_date)[0]
|
for d in self.get(component_type):
|
||||||
|
d.amount = flt(self.get_amount_based_on_payment_days(d, joining_date, relieving_date)[0], d.precision("amount"))
|
||||||
|
|
||||||
def set_loan_repayment(self):
|
def set_loan_repayment(self):
|
||||||
self.total_loan_repayment = 0
|
self.total_loan_repayment = 0
|
||||||
@@ -1089,17 +1097,17 @@ class SalarySlip(TransactionBase):
|
|||||||
self.calculate_net_pay()
|
self.calculate_net_pay()
|
||||||
|
|
||||||
def set_totals(self):
|
def set_totals(self):
|
||||||
self.gross_pay = 0
|
self.gross_pay = 0.0
|
||||||
if self.salary_slip_based_on_timesheet == 1:
|
if self.salary_slip_based_on_timesheet == 1:
|
||||||
self.calculate_total_for_salary_slip_based_on_timesheet()
|
self.calculate_total_for_salary_slip_based_on_timesheet()
|
||||||
else:
|
else:
|
||||||
self.total_deduction = 0
|
self.total_deduction = 0.0
|
||||||
if self.earnings:
|
if self.earnings:
|
||||||
for earning in self.earnings:
|
for earning in self.earnings:
|
||||||
self.gross_pay += flt(earning.amount)
|
self.gross_pay += flt(earning.amount, earning.precision("amount"))
|
||||||
if self.deductions:
|
if self.deductions:
|
||||||
for deduction in self.deductions:
|
for deduction in self.deductions:
|
||||||
self.total_deduction += flt(deduction.amount)
|
self.total_deduction += flt(deduction.amount, deduction.precision("amount"))
|
||||||
self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) - flt(self.total_loan_repayment)
|
self.net_pay = flt(self.gross_pay) - flt(self.total_deduction) - flt(self.total_loan_repayment)
|
||||||
self.set_base_totals()
|
self.set_base_totals()
|
||||||
|
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ class TestSalarySlip(unittest.TestCase):
|
|||||||
|
|
||||||
year_to_date = 0
|
year_to_date = 0
|
||||||
for slip in salary_slips:
|
for slip in salary_slips:
|
||||||
year_to_date += slip.net_pay
|
year_to_date += flt(slip.net_pay)
|
||||||
self.assertEqual(slip.year_to_date, year_to_date)
|
self.assertEqual(slip.year_to_date, year_to_date)
|
||||||
|
|
||||||
def test_tax_for_payroll_period(self):
|
def test_tax_for_payroll_period(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user