From 04a76285e2e834a51c7f7b146aca9c154ba3a0a8 Mon Sep 17 00:00:00 2001 From: Anupam Kumar Date: Thu, 23 Jul 2020 16:30:56 +0530 Subject: [PATCH] fix: Unable to change link from new lead to existing customer (#22787) * Unable to change link from new lead to existing customer * Unable to change link from new lead to existing customer Co-authored-by: Deepesh Garg <42651287+deepeshgarg007@users.noreply.github.com> --- .../crm/doctype/opportunity/opportunity.js | 19 +++++++------------ .../crm/doctype/opportunity/opportunity.json | 3 ++- 2 files changed, 9 insertions(+), 13 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index 7bae803508..08958b7dd6 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -30,7 +30,6 @@ frappe.ui.form.on("Opportunity", { }, party_name: function(frm) { - frm.toggle_display("contact_info", frm.doc.party_name); frm.trigger('set_contact_link'); if (frm.doc.opportunity_from == "Customer") { @@ -48,10 +47,6 @@ frappe.ui.form.on("Opportunity", { frm.get_field("items").grid.set_multiple_add("item_code", "qty"); }, - with_items: function(frm) { - frm.trigger('toggle_mandatory'); - }, - customer_address: function(frm, cdt, cdn) { erpnext.utils.get_address_display(frm, 'customer_address', 'address_display', false); }, @@ -59,15 +54,19 @@ frappe.ui.form.on("Opportunity", { contact_person: erpnext.utils.get_contact_details, opportunity_from: function(frm) { + frm.trigger('setup_opportunity_from'); + + frm.set_value("party_name", ""); + }, + + setup_opportunity_from: function(frm) { frm.trigger('setup_queries'); - frm.toggle_reqd("party_name", frm.doc.opportunity_from); frm.trigger("set_dynamic_field_label"); }, refresh: function(frm) { var doc = frm.doc; - frm.events.opportunity_from(frm); - frm.trigger('toggle_mandatory'); + frm.trigger('setup_opportunity_from'); erpnext.toggle_naming_series(); if(!doc.__islocal && doc.status!=="Lost") { @@ -118,7 +117,6 @@ frappe.ui.form.on("Opportunity", { }, set_dynamic_field_label: function(frm){ - if (frm.doc.opportunity_from) { frm.set_df_property("party_name", "label", frm.doc.opportunity_from); } @@ -138,9 +136,6 @@ frappe.ui.form.on("Opportunity", { }) }, - toggle_mandatory: function(frm) { - frm.toggle_reqd("items", frm.doc.with_items ? 1:0); - } }) // TODO commonify this code diff --git a/erpnext/crm/doctype/opportunity/opportunity.json b/erpnext/crm/doctype/opportunity/opportunity.json index 6a54c5fc6e..545e2324ac 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.json +++ b/erpnext/crm/doctype/opportunity/opportunity.json @@ -254,6 +254,7 @@ "fieldname": "items", "fieldtype": "Table", "label": "Items", + "mandatory_depends_on": "eval: doc.with_items == 1", "oldfieldname": "enquiry_details", "oldfieldtype": "Table", "options": "Opportunity Item" @@ -423,7 +424,7 @@ "icon": "fa fa-info-sign", "idx": 195, "links": [], - "modified": "2020-04-07 09:05:39.391109", + "modified": "2020-07-14 16:49:15.888503", "modified_by": "Administrator", "module": "CRM", "name": "Opportunity",