From 95dc4e4dc5be9894c149b45fabad820a0d43bca2 Mon Sep 17 00:00:00 2001 From: deepeshgarg007 Date: Thu, 30 May 2019 15:28:15 +0530 Subject: [PATCH] fix: Use make methods to override --- erpnext/crm/doctype/lead/lead.js | 38 +++++++------------- erpnext/public/js/utils.js | 10 ++++++ erpnext/selling/doctype/customer/customer.js | 37 +++++++------------ 3 files changed, 34 insertions(+), 51 deletions(-) diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js index de87100eb51..f5ee366d2f4 100644 --- a/erpnext/crm/doctype/lead/lead.js +++ b/erpnext/crm/doctype/lead/lead.js @@ -6,6 +6,18 @@ cur_frm.email_field = "email_id"; erpnext.LeadController = frappe.ui.form.Controller.extend({ setup: function () { + + this.frm.make_methods = { + 'Quotation': () => erpnext.utils.create_new_doc('Quotation', { + 'quotation_to': this.frm.doc.doctype, + 'party_name': this.frm.doc.name + }), + 'Opportunity': () => erpnext.utils.create_new_doc('Opportunity', { + 'opportunity_from': this.frm.doc.doctype, + 'party_name': this.frm.doc.name + }) + } + this.frm.fields_dict.customer.get_query = function (doc, cdt, cdn) { return { query: "erpnext.controllers.queries.customer_query" } } @@ -40,32 +52,6 @@ erpnext.LeadController = frappe.ui.form.Controller.extend({ if (!this.frm.doc.__islocal) { frappe.contacts.render_address_and_contact(cur_frm); - - let make_quotation = this.frm.dashboard.transactions_area.find('.btn-new[data-doctype="Quotation"]').unbind('click'); - let make_opportunity = this.frm.dashboard.transactions_area.find('.btn-new[data-doctype="Opportunity"]').unbind('click'); - - make_quotation.on('click', function() { - let doctype = $(this).attr('data-doctype'); - - frappe.model.with_doctype(doctype, function() { - var new_doc = frappe.model.get_new_doc(doctype); - new_doc['quotation_to'] = doc.doctype; - new_doc['party_name'] = doc.name; - frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); - }); - }); - - make_opportunity.on('click', function() { - let doctype = $(this).attr('data-doctype'); - - frappe.model.with_doctype(doctype, function() { - var new_doc = frappe.model.get_new_doc(doctype); - new_doc['opportunity_from'] = doc.doctype; - new_doc['party_name'] = doc.name; - frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); - }); - }); - } else { frappe.contacts.clear_address_and_contact(cur_frm); } diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js index 389e25ece10..2dd65fec170 100755 --- a/erpnext/public/js/utils.js +++ b/erpnext/public/js/utils.js @@ -286,6 +286,16 @@ $.extend(erpnext.utils, { refresh_field(table_fieldname); }, + create_new_doc: function (doctype, update_fields) { + frappe.model.with_doctype(doctype, function() { + var new_doc = frappe.model.get_new_doc(doctype); + for (let [key, value] of Object.entries(update_fields)) { + new_doc[key] = value; + } + frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); + }); + } + }); erpnext.utils.select_alternate_items = function(opts) { diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 61a4fd487e5..0ce521261ef 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -3,6 +3,18 @@ frappe.ui.form.on("Customer", { setup: function(frm) { + + frm.make_methods = { + 'Quotation': () => erpnext.utils.create_new_doc('Quotation', { + 'quotation_to': frm.doc.doctype, + 'party_name': frm.doc.name + }), + 'Opportunity': () => erpnext.utils.create_new_doc('Opportunity', { + 'opportunity_from': frm.doc.doctype, + 'party_name': frm.doc.name + }) + } + frm.add_fetch('lead_name', 'company_name', 'customer_name'); frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate'); frm.set_query('customer_group', {'is_group': 0}); @@ -113,31 +125,6 @@ frappe.ui.form.on("Customer", { // indicator erpnext.utils.set_party_dashboard_indicators(frm); - let make_quotation = frm.dashboard.transactions_area.find('.btn-new[data-doctype="Quotation"]').unbind('click'); - let make_opportunity = frm.dashboard.transactions_area.find('.btn-new[data-doctype="Opportunity"]').unbind('click'); - - make_quotation.on('click', function() { - let doctype = $(this).attr('data-doctype'); - - frappe.model.with_doctype(doctype, function() { - var new_doc = frappe.model.get_new_doc(doctype); - new_doc['quotation_to'] = frm.doc.doctype; - new_doc['party_name'] = frm.doc.name; - frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); - }); - }); - - make_opportunity.on('click', function() { - let doctype = $(this).attr('data-doctype'); - - frappe.model.with_doctype(doctype, function() { - var new_doc = frappe.model.get_new_doc(doctype); - new_doc['opportunity_from'] = frm.doc.doctype; - new_doc['party_name'] = frm.doc.name; - frappe.ui.form.make_quick_entry(doctype, null, null, new_doc); - }); - }); - } else { frappe.contacts.clear_address_and_contact(frm); }