diff --git a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py index 4326c404fd5..0e76c9dbdf0 100644 --- a/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/bank_guarantee.py @@ -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.")) diff --git a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py index 971db6aeddf..8000e00d48b 100644 --- a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py @@ -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)