fix: Add test to check if SO can be cancelled after linked Maintenance Visit has been submitted
diff --git a/erpnext/selling/doctype/sales_order/test_sales_order.py b/erpnext/selling/doctype/sales_order/test_sales_order.py
index ff25a3a..57b0c02 100644
--- a/erpnext/selling/doctype/sales_order/test_sales_order.py
+++ b/erpnext/selling/doctype/sales_order/test_sales_order.py
@@ -1320,6 +1320,22 @@
so.load_from_db()
self.assertRaises(frappe.LinkExistsError, so.cancel)
+ def test_so_cancellation_after_maintenance_visit_submission(self):
+ """
+ Expected result: Sales Order should not get cancelled
+ """
+ from erpnext.maintenance.doctype.maintenance_visit.test_maintenance_visit import make_maintenance_visit
+
+ so = make_sales_order()
+ so.submit()
+ mv = make_maintenance_visit()
+ mv.purposes[0].prevdoc_doctype = "Sales Order"
+ mv.purposes[0].prevdoc_docname = so.name
+ mv.submit()
+
+ so.load_from_db()
+ self.assertRaises(frappe.LinkExistsError, so.cancel)
+
def test_payment_terms_are_fetched_when_creating_sales_invoice(self):
from erpnext.accounts.doctype.payment_entry.test_payment_entry import (
create_payment_terms_template,