fix(vehicle): allow incomplete insurance dates

Do not compare insurance dates until both values are supplied, because absent dates otherwise default to today.

Incomplete policies can now be saved while complete invalid date ranges remain rejected.

Issue: frappe/erpnext-bug-reviews#399 (bug 1)
(cherry picked from commit f5176803ff)

# Conflicts:
#	erpnext/setup/doctype/vehicle/test_vehicle.py
This commit is contained in:
Krishna Shirsath
2026-10-26 21:16:54 +00:00
committed by Mergify
parent ed59ce64f3
commit cc0f7c9077
2 changed files with 30 additions and 17 deletions
+29 -16
View File
@@ -4,28 +4,41 @@
import unittest
import frappe
from frappe.utils import random_string
from frappe.utils import add_days, random_string
# test_records = frappe.get_test_records('Vehicle')
<<<<<<< HEAD
class TestVehicle(unittest.TestCase):
=======
class TestVehicle(ERPNextTestSuite):
def make_vehicle(self, **kwargs):
vehicle_args = {
"doctype": "Vehicle",
"license_plate": random_string(10).upper(),
"make": "Maruti",
"model": "PCM",
"last_odometer": 5000,
"acquisition_date": frappe.utils.nowdate(),
"location": "Mumbai",
"chassis_no": "1234ABCD",
"uom": "Litre",
"vehicle_value": frappe.utils.flt(500000),
}
vehicle_args.update(kwargs)
return frappe.get_doc(vehicle_args)
>>>>>>> f517680 (fix(vehicle): allow incomplete insurance dates)
def test_make_vehicle(self):
vehicle = frappe.get_doc(
{
"doctype": "Vehicle",
"license_plate": random_string(10).upper(),
"make": "Maruti",
"model": "PCM",
"last_odometer": 5000,
"acquisition_date": frappe.utils.nowdate(),
"location": "Mumbai",
"chassis_no": "1234ABCD",
"uom": "Litre",
"vehicle_value": frappe.utils.flt(500000),
}
)
vehicle.insert()
self.make_vehicle().insert()
def test_incomplete_insurance_dates_are_valid(self):
for insurance_dates in (
{"start_date": add_days(frappe.utils.nowdate(), 1)},
{"end_date": add_days(frappe.utils.nowdate(), -1)},
):
self.make_vehicle(**insurance_dates).insert()
def test_renaming_vehicle(self):
license_plate = random_string(10).upper()
+1 -1
View File
@@ -40,7 +40,7 @@ class Vehicle(Document):
# end: auto-generated types
def validate(self):
if getdate(self.start_date) > getdate(self.end_date):
if self.start_date and self.end_date and getdate(self.start_date) > getdate(self.end_date):
frappe.throw(_("Insurance Start date should be less than Insurance End date"))
if getdate(self.carbon_check_date) > getdate():
frappe.throw(_("Last carbon check date cannot be a future date"))