From 8b37c5218707ad2d04fad301163396100b7daa79 Mon Sep 17 00:00:00 2001 From: Raffael Meyer <14891507+barredterra@users.noreply.github.com> Date: Mon, 27 Jul 2026 11:20:22 +0200 Subject: [PATCH] fix(crm): align Opportunity status checks with Quotation statuses (#57489) --- .../crm/doctype/opportunity/opportunity.py | 22 +++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 93d35a7facf..5bc1024c4ab 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -286,7 +286,11 @@ class Opportunity(TransactionBase, CRMNote): if not self.get("items", []): return frappe.get_all( "Quotation", - {"opportunity": self.name, "status": ("not in", ["Lost", "Closed"]), "docstatus": 1}, + { + "opportunity": self.name, + "status": ("not in", ["Lost", "Cancelled", "Expired"]), + "docstatus": 1, + }, "name", ) else: @@ -300,7 +304,7 @@ class Opportunity(TransactionBase, CRMNote): .where( (q.docstatus == 1) & (qi.prevdoc_docname == self.name) - & q.status.notin(["Lost", "Closed"]) + & q.status.notin(["Lost", "Cancelled", "Expired"]) ) .run() ) @@ -308,7 +312,13 @@ class Opportunity(TransactionBase, CRMNote): def has_ordered_quotation(self): if not self.get("items", []): return frappe.get_all( - "Quotation", {"opportunity": self.name, "status": "Ordered", "docstatus": 1}, "name" + "Quotation", + { + "opportunity": self.name, + "status": ("in", ["Ordered", "Partially Ordered"]), + "docstatus": 1, + }, + "name", ) else: q = frappe.qb.DocType("Quotation") @@ -318,7 +328,11 @@ class Opportunity(TransactionBase, CRMNote): .inner_join(qi) .on(q.name == qi.parent) .select(q.name) - .where((q.docstatus == 1) & (qi.prevdoc_docname == self.name) & (q.status == "Ordered")) + .where( + (q.docstatus == 1) + & (qi.prevdoc_docname == self.name) + & (q.status.isin(["Ordered", "Partially Ordered"])) + ) .run() )