Skip to content

Commit

Permalink
fix: duplicate Additional Salary with Overwrite Salary Structure Amou…
Browse files Browse the repository at this point in the history
…nt enabled

(cherry picked from commit 15c752f)
  • Loading branch information
krantheman authored and mergify[bot] committed Dec 5, 2023
1 parent d529aaa commit 32707e7
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion hrms/payroll/doctype/additional_salary/additional_salary.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import frappe
from frappe import _, bold
from frappe.model.document import Document
from frappe.utils import comma_and, date_diff, formatdate, getdate
from frappe.utils import comma_and, date_diff, formatdate, get_link_to_form, getdate

from hrms.hr.utils import validate_active_employee

Expand All @@ -25,6 +25,7 @@ def validate(self):
self.validate_salary_structure()
self.validate_recurring_additional_salary_overlap()
self.validate_employee_referral()
self.validate_duplicate_additional_salary()

if self.amount < 0:
frappe.throw(_("Amount should not be less than zero"))
Expand Down Expand Up @@ -111,6 +112,26 @@ def validate_employee_referral(self):
).format(frappe.bold("Accepted"))
)

def validate_duplicate_additional_salary(self):
if not self.overwrite_salary_structure_amount:
return
existing_additional_salary = frappe.db.exists(
"Additional Salary",
{
"salary_component": self.salary_component,
"payroll_date": self.payroll_date,
"overwrite_salary_structure_amount": 1,
},
)
if existing_additional_salary:
frappe.throw(
_(
"Additional Salary of Salary Component {0} with 'Overwrite Salary Structure Amount' enabled already exists for this date. Reference: {1}"
).format(
self.salary_component, get_link_to_form("Additional Salary", existing_additional_salary)
)
)

def update_return_amount_in_employee_advance(self):
if self.ref_doctype == "Employee Advance" and self.ref_docname:
return_amount = frappe.db.get_value("Employee Advance", self.ref_docname, "return_amount")
Expand Down

0 comments on commit 32707e7

Please sign in to comment.