From 17e1546f48350754afa40324b10d9080a25495b8 Mon Sep 17 00:00:00 2001 From: Rucha Mahabal Date: Fri, 10 Jan 2025 17:14:09 +0530 Subject: [PATCH] fix: rectify and add more info to Leave Ledger validation message (cherry picked from commit 0504c74d2fd47e0e0870369df4027df1f390f35f) --- .../leave_ledger_entry/leave_ledger_entry.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py b/hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py index dd1718aef3..74d467730f 100644 --- a/hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py +++ b/hrms/hr/doctype/leave_ledger_entry/leave_ledger_entry.py @@ -4,13 +4,26 @@ import frappe from frappe import _ from frappe.model.document import Document -from frappe.utils import DATE_FORMAT, flt, get_link_to_form, getdate, today +from frappe.utils import DATE_FORMAT, flt, formatdate, get_link_to_form, getdate, today + + +class InvalidLeaveLedgerEntry(frappe.ValidationError): + pass class LeaveLedgerEntry(Document): def validate(self): if getdate(self.from_date) > getdate(self.to_date): - frappe.throw(_("To date needs to be before from date")) + frappe.throw( + _( + "Leave Ledger Entry's To date needs to be after From date. Currently, From Date is {0} and To Date is {1}" + ).format( + frappe.bold(formatdate(self.from_date)), + frappe.bold(formatdate(self.to_date)), + ), + exc=InvalidLeaveLedgerEntry, + title=_("Invalid Leave Ledger Entry"), + ) def on_cancel(self): # allow cancellation of expiry leaves