Skip to content

Commit

Permalink
fix: validate department based on company
Browse files Browse the repository at this point in the history
  • Loading branch information
rs-rethik authored and venkat102 committed Jan 7, 2025
1 parent 50d8041 commit 6880dfc
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions hrms/hr/doctype/expense_claim/expense_claim.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ class ExpenseApproverIdentityError(frappe.ValidationError):
pass


class MismatchError(frappe.ValidationError):
pass


class ExpenseClaim(AccountsController, PWANotificationsMixin):
def onload(self):
self.get("__onload").make_payment_via_journal_entry = frappe.db.get_single_value(
Expand All @@ -47,6 +51,7 @@ def validate(self):
self.set_expense_account(validate=True)
self.calculate_taxes()
self.set_status()
self.validate_company_and_department()
if self.task and not self.project:
self.project = frappe.db.get_value("Task", self.task, "project")

Expand Down Expand Up @@ -83,6 +88,14 @@ def set_status(self, update=False):
else:
self.status = status

def validate_company_and_department(self):
if self.department:
if self.company != frappe.db.get_value("Department", self.department, "company"):
frappe.throw(
_("Department {0} does not belong to company: {1}").format(self.department, self.company),
exc=MismatchError,
)

def on_update(self):
share_doc_with_approver(self, self.expense_approver)
self.publish_update()
Expand Down

0 comments on commit 6880dfc

Please sign in to comment.