fix: Consider any kind of exemptions only if tax exemptions are allowed on tax slab (#21474)

This commit is contained in:
Nabin Hait 2020-04-30 11:02:28 +05:30 committed by GitHub
parent 078c95c438
commit 691f69c731
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 41 additions and 46 deletions

View File

@ -93,13 +93,15 @@
], ],
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-04-24 12:28:36.805904", "modified": "2020-04-27 20:10:42.755762",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Income Tax Slab", "name": "Income Tax Slab",
"owner": "Administrator", "owner": "Administrator",
"permissions": [ "permissions": [
{ {
"amend": 1,
"cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
"email": 1, "email": 1,
@ -109,9 +111,11 @@
"report": 1, "report": 1,
"role": "System Manager", "role": "System Manager",
"share": 1, "share": 1,
"submit": 1,
"write": 1 "write": 1
}, },
{ {
"amend": 1,
"cancel": 1, "cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
@ -126,6 +130,7 @@
"write": 1 "write": 1
}, },
{ {
"amend": 1,
"cancel": 1, "cancel": 1,
"create": 1, "create": 1,
"delete": 1, "delete": 1,
@ -138,20 +143,6 @@
"share": 1, "share": 1,
"submit": 1, "submit": 1,
"write": 1 "write": 1
},
{
"cancel": 1,
"create": 1,
"delete": 1,
"email": 1,
"export": 1,
"print": 1,
"read": 1,
"report": 1,
"role": "Administrator",
"share": 1,
"submit": 1,
"write": 1
} }
], ],
"sort_field": "modified", "sort_field": "modified",

View File

@ -227,7 +227,7 @@
{ {
"default": "0", "default": "0",
"depends_on": "eval:doc.type == \"Deduction\" && !doc.variable_based_on_taxable_salary", "depends_on": "eval:doc.type == \"Deduction\" && !doc.variable_based_on_taxable_salary",
"description": "If checked, the full amount will be deducted from taxable income before calculating income tax. Otherwise, it can be exempted via Employee Tax Exemption Declaration.", "description": "If checked, the full amount will be deducted from taxable income before calculating income tax without any declaration or proof submission.",
"fieldname": "exempted_from_income_tax", "fieldname": "exempted_from_income_tax",
"fieldtype": "Check", "fieldtype": "Check",
"label": "Exempted from Income Tax" "label": "Exempted from Income Tax"
@ -235,7 +235,7 @@
], ],
"icon": "fa fa-flag", "icon": "fa fa-flag",
"links": [], "links": [],
"modified": "2020-04-24 14:50:28.994054", "modified": "2020-04-28 15:46:45.252945",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "HR", "module": "HR",
"name": "Salary Component", "name": "Salary Component",

View File

@ -549,15 +549,16 @@ class SalarySlip(TransactionBase):
remaining_sub_periods = get_period_factor(self.employee, remaining_sub_periods = get_period_factor(self.employee,
self.start_date, self.end_date, self.payroll_frequency, payroll_period)[1] self.start_date, self.end_date, self.payroll_frequency, payroll_period)[1]
# get taxable_earnings, paid_taxes for previous period # get taxable_earnings, paid_taxes for previous period
previous_taxable_earnings = self.get_taxable_earnings_for_prev_period(payroll_period.start_date, self.start_date) previous_taxable_earnings = self.get_taxable_earnings_for_prev_period(payroll_period.start_date,
self.start_date, tax_slab.allow_tax_exemption)
previous_total_paid_taxes = self.get_tax_paid_in_period(payroll_period.start_date, self.start_date, tax_component) previous_total_paid_taxes = self.get_tax_paid_in_period(payroll_period.start_date, self.start_date, tax_component)
# get taxable_earnings for current period (all days) # get taxable_earnings for current period (all days)
current_taxable_earnings = self.get_taxable_earnings() current_taxable_earnings = self.get_taxable_earnings(tax_slab.allow_tax_exemption)
future_structured_taxable_earnings = current_taxable_earnings.taxable_earnings * (math.ceil(remaining_sub_periods) - 1) future_structured_taxable_earnings = current_taxable_earnings.taxable_earnings * (math.ceil(remaining_sub_periods) - 1)
# get taxable_earnings, addition_earnings for current actual payment days # get taxable_earnings, addition_earnings for current actual payment days
current_taxable_earnings_for_payment_days = self.get_taxable_earnings(based_on_payment_days=1) current_taxable_earnings_for_payment_days = self.get_taxable_earnings(tax_slab.allow_tax_exemption, based_on_payment_days=1)
current_structured_taxable_earnings = current_taxable_earnings_for_payment_days.taxable_earnings current_structured_taxable_earnings = current_taxable_earnings_for_payment_days.taxable_earnings
current_additional_earnings = current_taxable_earnings_for_payment_days.additional_income current_additional_earnings = current_taxable_earnings_for_payment_days.additional_income
current_additional_earnings_with_full_tax = current_taxable_earnings_for_payment_days.additional_income_with_full_tax current_additional_earnings_with_full_tax = current_taxable_earnings_for_payment_days.additional_income_with_full_tax
@ -616,7 +617,7 @@ class SalarySlip(TransactionBase):
return income_tax_slab_doc return income_tax_slab_doc
def get_taxable_earnings_for_prev_period(self, start_date, end_date): def get_taxable_earnings_for_prev_period(self, start_date, end_date, allow_tax_exemption=False):
taxable_earnings = frappe.db.sql(""" taxable_earnings = frappe.db.sql("""
select sum(sd.amount) select sum(sd.amount)
from from
@ -636,24 +637,26 @@ class SalarySlip(TransactionBase):
}) })
taxable_earnings = flt(taxable_earnings[0][0]) if taxable_earnings else 0 taxable_earnings = flt(taxable_earnings[0][0]) if taxable_earnings else 0
exempted_amount = frappe.db.sql(""" exempted_amount = 0
select sum(sd.amount) if allow_tax_exemption:
from exempted_amount = frappe.db.sql("""
`tabSalary Detail` sd join `tabSalary Slip` ss on sd.parent=ss.name select sum(sd.amount)
where from
sd.parentfield='deductions' `tabSalary Detail` sd join `tabSalary Slip` ss on sd.parent=ss.name
and sd.exempted_from_income_tax=1 where
and is_flexible_benefit=0 sd.parentfield='deductions'
and ss.docstatus=1 and sd.exempted_from_income_tax=1
and ss.employee=%(employee)s and is_flexible_benefit=0
and ss.start_date between %(from_date)s and %(to_date)s and ss.docstatus=1
and ss.end_date between %(from_date)s and %(to_date)s and ss.employee=%(employee)s
""", { and ss.start_date between %(from_date)s and %(to_date)s
"employee": self.employee, and ss.end_date between %(from_date)s and %(to_date)s
"from_date": start_date, """, {
"to_date": end_date "employee": self.employee,
}) "from_date": start_date,
exempted_amount = flt(exempted_amount[0][0]) if exempted_amount else 0 "to_date": end_date
})
exempted_amount = flt(exempted_amount[0][0]) if exempted_amount else 0
return taxable_earnings - exempted_amount return taxable_earnings - exempted_amount
@ -681,7 +684,7 @@ class SalarySlip(TransactionBase):
return total_tax_paid return total_tax_paid
def get_taxable_earnings(self, based_on_payment_days=0): def get_taxable_earnings(self, allow_tax_exemption=False, based_on_payment_days=0):
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"])
@ -715,12 +718,13 @@ class SalarySlip(TransactionBase):
else: else:
taxable_earnings += amount taxable_earnings += amount
for ded in self.deductions: if allow_tax_exemption:
if ded.exempted_from_income_tax: for ded in self.deductions:
amount = ded.amount if ded.exempted_from_income_tax:
if based_on_payment_days: amount = ded.amount
amount = self.get_amount_based_on_payment_days(ded, joining_date, relieving_date)[0] if based_on_payment_days:
taxable_earnings -= flt(amount) amount = self.get_amount_based_on_payment_days(ded, joining_date, relieving_date)[0]
taxable_earnings -= flt(amount)
return frappe._dict({ return frappe._dict({
"taxable_earnings": taxable_earnings, "taxable_earnings": taxable_earnings,