From efb6482ef64bb53a73eee60458c490935a7ee8ba Mon Sep 17 00:00:00 2001 From: Lokesh Waingankar Date: Thu, 27 Feb 2020 19:08:58 +0530 Subject: [PATCH] fix: user is not able to do 'Set as Lost' for Quotation (#20689) --- erpnext/selling/doctype/quotation/quotation.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext/selling/doctype/quotation/quotation.py b/erpnext/selling/doctype/quotation/quotation.py index d8667f603a..8ec2b76db9 100644 --- a/erpnext/selling/doctype/quotation/quotation.py +++ b/erpnext/selling/doctype/quotation/quotation.py @@ -68,13 +68,19 @@ class Quotation(SellingController): def declare_enquiry_lost(self, lost_reasons_list, detailed_reason=None): if not self.has_sales_order(): + get_lost_reasons = frappe.get_list('Opportunity Lost Reason', + fields = ["name"]) + lost_reasons_lst = [reason.get('name') for reason in get_lost_reasons] frappe.db.set(self, 'status', 'Lost') if detailed_reason: frappe.db.set(self, 'order_lost_reason', detailed_reason) for reason in lost_reasons_list: - self.append('lost_reasons', reason) + if reason.get('lost_reason') in lost_reasons_lst: + self.append('lost_reasons', reason) + else: + frappe.throw(_("Invalid lost reason {0}, please create a new lost reason".format(reason.get('lost_reason')))) self.update_opportunity() self.update_lead()