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()