Skip to content

Commit

Permalink
fix(Salary Structure Assignment): validate cost center company on ser…
Browse files Browse the repository at this point in the history
…ver-side (frappe#2445)
  • Loading branch information
ruchamahabal authored Nov 25, 2024
1 parent f382a94 commit a3bc4e5
Showing 1 changed file with 23 additions and 6 deletions.
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

0 comments on commit a3bc4e5

Please sign in to comment.