From ad9870acc1b72fe3e7736e45cbe3bef7ca8a9eb9 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Mon, 27 Jul 2026 12:22:35 +0200 Subject: [PATCH] fix(crm): align Opportunity status checks with Quotation statuses (backport #57489) (#57491) Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com> --- erpnext/crm/doctype/opportunity/opportunity.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 7368a800003..b93ee7674d8 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -285,7 +285,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: @@ -294,14 +298,20 @@ class Opportunity(TransactionBase, CRMNote): select q.name from `tabQuotation` q, `tabQuotation Item` qi where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s - and q.status not in ('Lost', 'Closed')""", + and q.status not in ('Lost', 'Cancelled', 'Expired')""", self.name, ) 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: return frappe.db.sql( @@ -309,7 +319,7 @@ class Opportunity(TransactionBase, CRMNote): select q.name from `tabQuotation` q, `tabQuotation Item` qi where q.name = qi.parent and q.docstatus=1 and qi.prevdoc_docname =%s - and q.status = 'Ordered'""", + and q.status in ('Ordered', 'Partially Ordered')""", self.name, )