fix(setup): reject reversed driver licence dates

Driver validation previously allowed licences to expire before their issue date. Reject reversed dates while leaving incomplete dates optional.

Issue: frappe/erpnext-bug-reviews#381 (bug 2)
(cherry picked from commit 8573cbb396)
This commit is contained in:
Krishna Shirsath
2026-10-27 22:58:17 +05:30
parent 3e73aa2934
commit c838f2abcc
2 changed files with 20 additions and 2 deletions
+6 -1
View File
@@ -2,7 +2,10 @@
# For license information, please see license.txt
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import getdate
class Driver(Document):
@@ -31,4 +34,6 @@ class Driver(Document):
transporter: DF.Link | None
# end: auto-generated types
pass
def validate(self):
if self.issuing_date and self.expiry_date and getdate(self.expiry_date) < getdate(self.issuing_date):
frappe.throw(_("The licence expiry date cannot precede its issuing date."))
+14 -1
View File
@@ -3,6 +3,19 @@
import unittest
import frappe
class TestDriver(unittest.TestCase):
pass
def test_expiry_cannot_precede_issuing_date(self):
driver = frappe.get_doc(
{
"doctype": "Driver",
"full_name": "Test Driver",
"status": "Active",
"issuing_date": "2025-01-01",
"expiry_date": "2020-01-01",
}
)
with self.assertRaises(frappe.ValidationError):
driver.insert()