fix: Set Quotation expired if not Ordered or Lost (#20354)

Co-authored-by: Chinmay Pai <chinmaydpai@gmail.com>
diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py
index 9ebef0d..d8667f6 100644
--- a/erpnext/selling/doctype/quotation/quotation.py
+++ b/erpnext/selling/doctype/quotation/quotation.py
@@ -182,8 +182,12 @@
 	return doclist
 
 def set_expired_status():
-	frappe.db.sql("""UPDATE `tabQuotation` SET `status` = 'Expired'
-		WHERE `status` != "Expired" AND `valid_till` < %s""", (nowdate()))
+	frappe.db.sql("""
+		UPDATE
+			`tabQuotation` SET `status` = 'Expired'
+		WHERE
+			`status` not in ('Ordered', 'Expired', 'Lost', 'Cancelled') AND `valid_till` < %s
+		""", (nowdate()))
 
 @frappe.whitelist()
 def make_sales_invoice(source_name, target_doc=None):