diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js index 70984458f7..a4ba2eb7bf 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.js +++ b/erpnext/hr/doctype/expense_claim/expense_claim.js @@ -80,7 +80,7 @@ cur_frm.cscript.refresh = function(doc,cdt,cdn){ cur_frm.cscript.set_help(doc); if(!doc.__islocal) { - cur_frm.toggle_enable("exp_approver", (doc.owner==user && doc.approval_status=="Draft")); + cur_frm.toggle_enable("exp_approver", doc.approval_status=="Draft"); cur_frm.toggle_enable("approval_status", (doc.exp_approver==user && doc.docstatus==0)); if(!doc.__islocal && user!=doc.exp_approver) diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py index fda3cf6aed..560ee02900 100644 --- a/erpnext/hr/doctype/expense_claim/expense_claim.py +++ b/erpnext/hr/doctype/expense_claim/expense_claim.py @@ -4,13 +4,17 @@ from __future__ import unicode_literals import frappe from frappe import _ +from frappe.utils import get_fullname from frappe.model.document import Document from erpnext.hr.utils import set_employee_name +class InvalidExpenseApproverError(frappe.ValidationError): pass + class ExpenseClaim(Document): def validate(self): self.validate_fiscal_year() self.validate_exp_details() + self.validate_expense_approver() set_employee_name(self) def on_submit(self): @@ -24,3 +28,8 @@ class ExpenseClaim(Document): def validate_exp_details(self): if not self.get('expense_voucher_details'): frappe.throw(_("Please add expense voucher details")) + + def validate_expense_approver(self): + if self.exp_approver and "Expense Approver" not in frappe.get_roles(self.exp_approver): + frappe.throw(_("{0} ({1}) must have role 'Expense Approver'")\ + .format(get_fullname(self.exp_approver), self.exp_approver), InvalidExpenseApproverError) diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py index 32c4443261..1751eb128d 100755 --- a/erpnext/hr/doctype/leave_application/leave_application.py +++ b/erpnext/hr/doctype/leave_application/leave_application.py @@ -162,8 +162,8 @@ class LeaveApplication(Document): elif self.leave_approver and not frappe.db.sql("""select name from `tabUserRole` where parent=%s and role='Leave Approver'""", self.leave_approver): - frappe.throw(_("{0} must have role 'Leave Approver'").format(get_fullname(self.leave_approver)), - InvalidLeaveApproverError) + frappe.throw(_("{0} ({1}) must have role 'Leave Approver'")\ + .format(get_fullname(self.leave_approver), self.leave_approver), InvalidLeaveApproverError) elif self.docstatus==1 and len(leave_approvers) and self.leave_approver != frappe.session.user: msgprint(_("Only the selected Leave Approver can submit this Leave Application"),