Skip to content

Commit

Permalink
fix(UX): validate missing Income Tax Slab in Salary Structure Assignm…
Browse files Browse the repository at this point in the history
…ent (#1912)

* fix: validate missing income tax slab in Salary Structure Assignment

* test(fix): income tax slab mapping

(cherry picked from commit bb8b254)
  • Loading branch information
ruchamahabal authored and mergify[bot] committed Jun 25, 2024
1 parent 87728ca commit 846b8dc
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,8 @@ def create_salary_structure_assignment(
salary_structure_assignment.currency = currency
salary_structure_assignment.payroll_payable_account = get_payable_account(company)
salary_structure_assignment.company = company or erpnext.get_default_company()
salary_structure_assignment.save(ignore_permissions=True)
salary_structure_assignment.income_tax_slab = income_tax_slab
salary_structure_assignment.save(ignore_permissions=True)
salary_structure_assignment.submit()
return salary_structure_assignment

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import flt, getdate
from frappe.utils import cint, flt, get_link_to_form, getdate


class DuplicateAssignment(frappe.ValidationError):
Expand Down Expand Up @@ -90,6 +90,18 @@ def validate_company(self):
)

def validate_income_tax_slab(self):
tax_component = get_tax_component(self.salary_structure)
if tax_component and not self.income_tax_slab:
frappe.throw(
_(
"Income Tax Slab is mandatory since the Salary Structure {0} has a tax component {1}"
).format(
get_link_to_form("Salary Structure", self.salary_structure), frappe.bold(tax_component)
),
exc=frappe.MandatoryError,
title=_("Missing Mandatory Field"),
)

if not self.income_tax_slab:
return

Expand Down Expand Up @@ -216,3 +228,11 @@ def get_employee_currency(employee):
)
)
return employee_currency


def get_tax_component(salary_structure: str) -> str | None:
salary_structure = frappe.get_cached_doc("Salary Structure", salary_structure)
for d in salary_structure.deductions:
if cint(d.variable_based_on_taxable_salary) and not d.formula and not flt(d.amount):
return d.salary_component
return None

0 comments on commit 846b8dc

Please sign in to comment.