diff --git a/hrms/hr/doctype/expense_claim/expense_claim.py b/hrms/hr/doctype/expense_claim/expense_claim.py index 04a02ba5d1..455410d445 100644 --- a/hrms/hr/doctype/expense_claim/expense_claim.py +++ b/hrms/hr/doctype/expense_claim/expense_claim.py @@ -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( @@ -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") @@ -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()