From 80afee04a4757807e5a36a481cf0cf7a917b09e7 Mon Sep 17 00:00:00 2001 From: Suraj Shetty <13928957+surajshetty3416@users.noreply.github.com> Date: Tue, 13 Aug 2019 10:58:29 +0530 Subject: [PATCH] fix: Set address while creating Opportunity from Lead (#18702) * fix: Set address while creating Opportunity from Lead * fix: Setting of address in opportunity from Lead --- erpnext/crm/doctype/lead/lead.py | 11 +++++------ erpnext/crm/doctype/opportunity/opportunity.js | 9 +-------- 2 files changed, 6 insertions(+), 14 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py index 9292b3a53a2..c9216ee0fa1 100644 --- a/erpnext/crm/doctype/lead/lead.py +++ b/erpnext/crm/doctype/lead/lead.py @@ -146,15 +146,14 @@ def _make_customer(source_name, target_doc=None, ignore_permissions=False): @frappe.whitelist() def make_opportunity(source_name, target_doc=None): def set_missing_values(source, target): - address = frappe.db.exists('Dynamic Link', { - 'link_doctype': target.doctype, - 'link_name': target.name, + address = frappe.get_all('Dynamic Link', { + 'link_doctype': source.doctype, + 'link_name': source.name, 'parenttype': 'Address', - 'disabled': 0 - }) + }, ['parent'], limit=1) if address: - target.customer_address = address + target.customer_address = address[0].parent target_doc = get_mapped_doc("Lead", source_name, {"Lead": { diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index 90a12b7dbd0..ec1762985b5 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -31,9 +31,9 @@ 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") { - frm.trigger('set_contact_link'); erpnext.utils.get_party_details(frm); } else if (frm.doc.opportunity_from == "Lead") { erpnext.utils.map_current_doc({ @@ -48,13 +48,6 @@ frappe.ui.form.on("Opportunity", { frm.get_field("items").grid.set_multiple_add("item_code", "qty"); }, - party_name: function(frm) { - if (frm.doc.opportunity_from == "Customer") { - frm.trigger('set_contact_link'); - erpnext.utils.get_party_details(frm); - } - }, - with_items: function(frm) { frm.trigger('toggle_mandatory'); },