mirror of
https://github.com/frappe/erpnext.git
synced 2026-10-29 22:57:42 +00:00
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:
@@ -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."))
|
||||
|
||||
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user