From 6a5cf672c162a40d202792256b1288ea6a2e9dfa Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Tue, 30 May 2017 15:34:20 +0530 Subject: [PATCH] Fixed opportunity status (#9062) --- erpnext/controllers/status_updater.py | 4 +-- .../crm/doctype/opportunity/opportunity.js | 34 ++++++++----------- .../crm/doctype/opportunity/opportunity.py | 1 - 3 files changed, 17 insertions(+), 22 deletions(-) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index cede8f4d34..42327b94ac 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -19,10 +19,10 @@ status_map = { ["Converted", "has_customer"], ], "Opportunity": [ - ["Quotation", "has_active_quotation"], - ["Converted", "has_ordered_quotation"], ["Lost", "eval:self.status=='Lost'"], ["Lost", "has_lost_quotation"], + ["Quotation", "has_active_quotation"], + ["Converted", "has_ordered_quotation"], ["Closed", "eval:self.status=='Closed'"] ], "Quotation": [ diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index 974b23e69a..0e14c85b2c 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -35,6 +35,7 @@ frappe.ui.form.on("Opportunity", { var doc = frm.doc; frm.events.enquiry_from(frm); frm.trigger('set_contact_link'); + erpnext.toggle_naming_series(); if(!doc.__islocal && doc.status!=="Lost") { if(doc.with_items){ @@ -53,6 +54,20 @@ frappe.ui.form.on("Opportunity", { frm.add_custom_button(__('Lost'), cur_frm.cscript['Declare Opportunity Lost']); } + }, + + if(!frm.doc.__islocal && frm.perm[0].write && frm.doc.docstatus==0) { + if(frm.doc.status==="Open") { + frm.add_custom_button(__("Close"), function() { + frm.set_value("status", "Closed"); + frm.save(); + }); + } else { + frm.add_custom_button(__("Reopen"), function() { + frm.set_value("status", "Open"); + frm.save(); + }); + } } }, @@ -122,25 +137,6 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({ $.extend(cur_frm.cscript, new erpnext.crm.Opportunity({frm: cur_frm})); -cur_frm.cscript.refresh = function(doc, cdt, cdn) { - erpnext.toggle_naming_series(); - - var frm = cur_frm; - if(!doc.__islocal && frm.perm[0].write && doc.docstatus==0) { - if(frm.doc.status==="Open") { - frm.add_custom_button(__("Close"), function() { - frm.set_value("status", "Closed"); - frm.save(); - }); - } else { - frm.add_custom_button(__("Reopen"), function() { - frm.set_value("status", "Open"); - frm.save(); - }); - } - } -} - cur_frm.cscript.onload_post_render = function(doc, cdt, cdn) { if(doc.enquiry_from == 'Lead' && doc.lead) cur_frm.cscript.lead(doc, cdt, cdn); diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index eebf464047..58f26fe546 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -31,7 +31,6 @@ class Opportunity(TransactionBase): if not self.enquiry_from: frappe.throw(_("Opportunity From field is mandatory")) - self.set_status() self.validate_item_details() self.validate_uom_is_integer("uom", "qty") self.validate_lead_cust()