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 (backport #2445) #2449

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Changes from 1 commit
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 @@ -47,7 +47,15 @@ def validate(self):
if not self.get("payroll_cost_centers"):
self.set_payroll_cost_centers()

<<<<<<< HEAD
self.validate_cost_center_distribution()
=======
self.validate_cost_centers()
self.warn_about_missing_opening_entries()
>>>>>>> a3bc4e585 (fix(Salary Structure Assignment): validate cost center company on server-side (#2445))
ruchamahabal marked this conversation as resolved.
Show resolved Hide resolved

def on_update_after_submit(self):
self.validate_cost_centers()

def validate_dates(self):
joining_date, relieving_date = frappe.db.get_value(
Expand Down Expand Up @@ -146,11 +154,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"))

@frappe.whitelist()
def earning_and_deduction_entries_does_not_exists(self):
Expand Down
Loading