[fix] Validate Expense Approver

This commit is contained in:
Anand Doshi 2014-09-05 14:41:53 +05:30
parent d42326bf43
commit 0b74b6d98c
3 changed files with 12 additions and 3 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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"),