From 41000ea109f534c93a1d1f3d9b8af9457532adc3 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 3 Jul 2026 11:14:54 +0530 Subject: [PATCH 1/2] test: add coverage for Bank Guarantee --- .../bank_guarantee/test_bank_guarantee.py | 74 ++++++++++++++++++- 1 file changed, 72 insertions(+), 2 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py index c5ad4d20940..b3f17748f79 100644 --- a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py @@ -1,8 +1,78 @@ -# Copyright (c) 2018, Frappe Technologies Pvt. Ltd. and Contributors +# Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt +import unittest + +import frappe +from frappe.utils import flt + +from erpnext.accounts.doctype.bank_guarantee.bank_guarantee import get_voucher_details +from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order from erpnext.tests.utils import ERPNextTestSuite +BANK = "_Test BG Bank" + class TestBankGuarantee(ERPNextTestSuite): - pass + """Bank Guarantee records a guarantee issued/received against a customer or + supplier. validate() needs a party; on_submit() needs the bank details filled in.""" + + def setUp(self): + frappe.set_user("Administrator") + if not frappe.db.exists("Bank", BANK): + frappe.get_doc({"doctype": "Bank", "bank_name": BANK}).insert() + + def make_bg(self, **args): + args = frappe._dict(args) + doc = frappe.new_doc("Bank Guarantee") + doc.bg_type = args.bg_type or "Receiving" + doc.amount = args.amount if args.amount is not None else 1000 + doc.start_date = args.start_date or "2026-06-01" + if args.end_date: + doc.end_date = args.end_date + doc.customer = args.get("customer", "_Test Customer") + doc.supplier = args.get("supplier") + # fields on_submit requires — present by default, cleared per-test to assert the guard + doc.bank_guarantee_number = args.get("bank_guarantee_number", "BG-001") + doc.name_of_beneficiary = args.get("name_of_beneficiary", "Test Beneficiary") + doc.bank = args.get("bank", BANK) + return doc + + def test_validate_requires_customer_or_supplier(self): + doc = self.make_bg(customer=None) + self.assertRaises(frappe.ValidationError, doc.insert) + + def test_submit_requires_guarantee_number(self): + doc = self.make_bg(bank_guarantee_number="") + doc.insert() + self.assertRaises(frappe.ValidationError, doc.submit) + + def test_submit_requires_beneficiary_name(self): + doc = self.make_bg(name_of_beneficiary="") + doc.insert() + self.assertRaises(frappe.ValidationError, doc.submit) + + def test_submit_requires_bank(self): + doc = self.make_bg(bank="") + doc.insert() + self.assertRaises(frappe.ValidationError, doc.submit) + + def test_valid_guarantee_submits(self): + doc = self.make_bg() + doc.insert() + doc.submit() + self.assertEqual(doc.docstatus, 1) + + def test_get_voucher_details_for_receiving(self): + so = make_sales_order() + details = get_voucher_details("Receiving", so.name) + self.assertEqual(details.customer, so.customer) + self.assertEqual(flt(details.grand_total), flt(so.grand_total)) + + @unittest.expectedFailure + def test_end_date_before_start_date_is_rejected(self): + # SUSPECTED BUG: validate() never checks that end_date >= start_date, so a + # guarantee that expires before it starts submits cleanly. This asserts the + # behaviour we'd expect; remove the xfail once validate() enforces it. + doc = self.make_bg(start_date="2026-06-30", end_date="2026-06-01") + self.assertRaises(frappe.ValidationError, doc.insert) From 9980d47524e38ad58c0699f0969373fd3f6c54fb Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Fri, 3 Jul 2026 12:00:45 +0530 Subject: [PATCH 2/2] test: lock current end-date behaviour and assert persisted state --- .../doctype/bank_guarantee/test_bank_guarantee.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py index b3f17748f79..971db6aeddf 100644 --- a/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py +++ b/erpnext/accounts/doctype/bank_guarantee/test_bank_guarantee.py @@ -1,8 +1,6 @@ # Copyright (c) 2026, Frappe Technologies Pvt. Ltd. and Contributors # See license.txt -import unittest - import frappe from frappe.utils import flt @@ -61,7 +59,7 @@ class TestBankGuarantee(ERPNextTestSuite): doc = self.make_bg() doc.insert() doc.submit() - self.assertEqual(doc.docstatus, 1) + self.assertEqual(frappe.db.get_value("Bank Guarantee", doc.name, "docstatus"), 1) def test_get_voucher_details_for_receiving(self): so = make_sales_order() @@ -69,10 +67,10 @@ class TestBankGuarantee(ERPNextTestSuite): self.assertEqual(details.customer, so.customer) self.assertEqual(flt(details.grand_total), flt(so.grand_total)) - @unittest.expectedFailure - def test_end_date_before_start_date_is_rejected(self): + 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 submits cleanly. This asserts the - # behaviour we'd expect; remove the xfail once validate() enforces it. + # guarantee that expires before it starts saves cleanly. Locking the current + # (wrong) behaviour so a future fix that adds the check trips this test. doc = self.make_bg(start_date="2026-06-30", end_date="2026-06-01") - self.assertRaises(frappe.ValidationError, doc.insert) + doc.insert() + self.assertTrue(frappe.db.exists("Bank Guarantee", doc.name))