Compare commits

...

1 Commits

Author SHA1 Message Date
Nabin Hait
db67e4ca0d fix: reject Bank Guarantee whose end date precedes its start date 2026-07-03 14:12:24 +05:30
2 changed files with 6 additions and 6 deletions

View File

@@ -5,6 +5,7 @@
import frappe
from frappe import _
from frappe.model.document import Document
from frappe.utils import getdate
class BankGuarantee(Document):
@@ -46,6 +47,9 @@ class BankGuarantee(Document):
if not (self.customer or self.supplier):
frappe.throw(_("Select the customer or supplier."))
if self.end_date and getdate(self.end_date) < getdate(self.start_date):
frappe.throw(_("End Date cannot be before Start Date."))
def on_submit(self):
if not self.bank_guarantee_number:
frappe.throw(_("Enter the Bank Guarantee Number before submitting."))

View File

@@ -67,10 +67,6 @@ class TestBankGuarantee(ERPNextTestSuite):
self.assertEqual(details.customer, so.customer)
self.assertEqual(flt(details.grand_total), flt(so.grand_total))
def test_end_date_before_start_date_is_not_validated(self):
# SUSPECTED BUG: validate() never checks that end_date >= start_date, so a
# guarantee that expires before it starts saves cleanly. Locking the current
# (wrong) behaviour so a future fix that adds the check trips this test.
def test_end_date_before_start_date_is_rejected(self):
doc = self.make_bg(start_date="2026-06-30", end_date="2026-06-01")
doc.insert()
self.assertTrue(frappe.db.exists("Bank Guarantee", doc.name))
self.assertRaises(frappe.ValidationError, doc.insert)