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>
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index 7bae803..08958b7 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -30,7 +30,6 @@
},
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 @@
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 @@
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 @@
},
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 @@
})
},
- 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 6a54c5f..545e232 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",