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(Salary Structure Assignment): validate cost center company on server-side #2445

Merged
merged 1 commit into from
Nov 25, 2024
Merged
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 @@ -24,9 +24,12 @@ def validate(self):
if not self.get("payroll_cost_centers"):
self.set_payroll_cost_centers()

self.validate_cost_center_distribution()
self.validate_cost_centers()
self.warn_about_missing_opening_entries()

def on_update_after_submit(self):
self.validate_cost_centers()

def validate_dates(self):
joining_date, relieving_date = frappe.db.get_value(
"Employee", self.employee, ["date_of_joining", "relieving_date"]
Expand Down Expand Up @@ -124,11 +127,25 @@ def get_payroll_cost_center(self):

return payroll_cost_center

def validate_cost_center_distribution(self):
if self.get("payroll_cost_centers"):
total_percentage = sum([flt(d.percentage) for d in self.get("payroll_cost_centers", [])])
if total_percentage != 100:
frappe.throw(_("Total percentage against cost centers should be 100"))
def validate_cost_centers(self):
if not self.get("payroll_cost_centers"):
return

total_percentage = 0
for entry in self.payroll_cost_centers:
company = frappe.db.get_value("Cost Center", entry.cost_center, "company")
if company != self.company:
frappe.throw(
_("Row {0}: Cost Center {1} does not belong to Company {2}").format(
entry.idx, frappe.bold(entry.cost_center), frappe.bold(self.company)
),
title=_("Invalid Cost Center"),
)

total_percentage += flt(entry.percentage)

if total_percentage != 100:
frappe.throw(_("Total percentage against cost centers should be 100"))

def warn_about_missing_opening_entries(self):
if (
Expand Down
Loading