Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(UX): validate missing Income Tax Slab in Salary Structure Assignment (backport #1912) #1915

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading