From f8ec0b6a86acbee91f26e5961291424350e78a83 Mon Sep 17 00:00:00 2001 From: Frappe PR Bot Date: Wed, 25 Aug 2021 20:05:54 +0530 Subject: [PATCH] feat: provision to create customer from opportunity (#27145) * feat: provision to create customer from opportunity (#27141) * feat: provision to create customer from opportunity * fead: linking of address and contact * revert: create_opportunity_address_contact * enabming print hide and no copy (cherry picked from commit 4d98be2126572a32d13ab76db5954d674d6845b2) # Conflicts: # erpnext/crm/doctype/opportunity/opportunity.js * Update opportunity.js * fix: conflicts Co-authored-by: Anupam Kumar Co-authored-by: Rucha Mahabal --- .../crm/doctype/opportunity/opportunity.js | 19 +++++++++++++++++-- .../crm/doctype/opportunity/opportunity.py | 18 ++++++++++++++++++ .../selling/doctype/customer/customer.json | 11 ++++++++++- 3 files changed, 45 insertions(+), 3 deletions(-) diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js index 875d221efeb..5cc63d4511b 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.js +++ b/erpnext/crm/doctype/opportunity/opportunity.js @@ -95,9 +95,17 @@ frappe.ui.form.on("Opportunity", { }, __('Create')); } - frm.add_custom_button(__('Quotation'), - cur_frm.cscript.create_quotation, __('Create')); + if (frm.doc.opportunity_from != "Customer") { + frm.add_custom_button(__('Customer'), + function() { + frm.trigger("make_customer") + }, __('Create')); + } + frm.add_custom_button(__('Quotation'), + function() { + frm.trigger("create_quotation") + }, __('Create')); } if(!frm.doc.__islocal && frm.perm[0].write && frm.doc.docstatus==0) { @@ -194,6 +202,13 @@ erpnext.crm.Opportunity = frappe.ui.form.Controller.extend({ method: "erpnext.crm.doctype.opportunity.opportunity.make_quotation", frm: cur_frm }) + }, + + make_customer: function() { + frappe.model.open_mapped_doc({ + method: "erpnext.crm.doctype.opportunity.opportunity.make_customer", + frm: cur_frm + }) } }); diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py index 8ce482a3f9f..a74a94afd68 100644 --- a/erpnext/crm/doctype/opportunity/opportunity.py +++ b/erpnext/crm/doctype/opportunity/opportunity.py @@ -287,6 +287,24 @@ def make_request_for_quotation(source_name, target_doc=None): return doclist +@frappe.whitelist() +def make_customer(source_name, target_doc=None): + def set_missing_values(source, target): + if source.opportunity_from == "Lead": + target.lead_name = source.party_name + + doclist = get_mapped_doc("Opportunity", source_name, { + "Opportunity": { + "doctype": "Customer", + "field_map": { + "currency": "default_currency", + "customer_name": "customer_name" + } + } + }, target_doc, set_missing_values) + + return doclist + @frappe.whitelist() def make_supplier_quotation(source_name, target_doc=None): doclist = get_mapped_doc("Opportunity", source_name, { diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json index cd94ee101af..0d839fc8228 100644 --- a/erpnext/selling/doctype/customer/customer.json +++ b/erpnext/selling/doctype/customer/customer.json @@ -20,6 +20,7 @@ "tax_withholding_category", "default_bank_account", "lead_name", + "opportunity_name", "image", "column_break0", "account_manager", @@ -493,6 +494,14 @@ "fieldtype": "Link", "label": "Tax Withholding Category", "options": "Tax Withholding Category" + }, + { + "fieldname": "opportunity_name", + "fieldtype": "Link", + "label": "From Opportunity", + "no_copy": 1, + "options": "Opportunity", + "print_hide": 1 } ], "icon": "fa fa-user", @@ -500,7 +509,7 @@ "image_field": "image", "index_web_pages_for_search": 1, "links": [], - "modified": "2021-01-28 12:54:57.258959", + "modified": "2021-08-25 18:56:09.929905", "modified_by": "Administrator", "module": "Selling", "name": "Customer",