mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-17 08:28:44 +00:00
fix: reject Bank Guarantee whose end date precedes its start date
This commit is contained in:
@@ -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."))
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user