I want to make option in lead like make customer

i have made a custom doctype it’s name is clients like customers
i want to add to add option in make button make to make a new client

Hi, @fatheyabdelslam
not possible through custom script. you can add button of that doctype on Lead Dashboard.

1 Like

thank you for your replay
do you say i can’t do such thing ?

Are you sure? I’m pretty sure you can, I’ve done auto-document-creation from a custom script before.

1 Like

Hi, @chabad360 that would be great if you send me the code so that i can work on it.

1 Like

I followed this.

1 Like

put this is custom script

frappe.ui.form.on("Lead", "refresh", function(frm, cdt, cdn) {
    frm.add_custom_button(__("Client"), this.creat_client, __("Make"));
});
1 Like

Hi, @Maheshwari_Bhavesh for me custom script is working. but getting following error.
Capture

Thank You

you need to make create_client method like below create_customer

	create_customer: function() {
		frappe.model.open_mapped_doc({
			method: "erpnext.crm.doctype.lead.lead.make_customer",
			frm: cur_frm
		})
	},

@Maheshwari_Bhavesh
it’s giving error
Capture%202

Thank You

share your custom script code

@Maheshwari_Bhavesh

frappe.ui.form.on("Lead", "refresh", function(frm, cdt, cdn) {
    frm.add_custom_button(__("Risk Profile"), this.creat_client, __("Make"));
	create_risk_profile: function() {
		frappe.model.open_mapped_doc({
			method: "erpnext.crm.doctype.lead.lead.make_risk_profile",
			frm: cur_frm
		});
	},
});

Thank You

try this:

frappe.ui.form.on("Lead", {
refresh:function(frm, cdt, cdn){
			frm.add_custom_button(__('Risk Profile'),
					function() {
							frappe.model.open_mapped_doc({
			                                                             method: "erpnext.crm.doctype.lead.lead.make_risk_profile",
			                                                             frm: cur_frm
		                                                              });
					}, __("Make"));
},


})

@Maheshwari_Bhavesh
again it’s giving error.
Capture3

share your python method:

erpnext.crm.doctype.lead.lead.make_risk_profile

@Maheshwari_Bhavesh
I don’t have a back-end access.
only i am working through Custom Script.

Note :-

  1. I was Created a Doctype Risk Profile.
  2. Module Name CRM.

Thank You

you need to make python method like below:

def  make_customer(source_name, target_doc=None, ignore_permissions=False):
	def set_missing_values(source, target):
		if source.company_name:
			target.customer_type = "Company"
			target.customer_name = source.company_name
		else:
			target.customer_type = "Individual"
			target.customer_name = source.lead_name

		target.customer_group = frappe.db.get_default("Customer Group")

	doclist = get_mapped_doc("Lead", source_name,
		{"Lead": {
			"doctype": "Customer",
			"field_map": {
				"name": "lead_name",
				"company_name": "customer_name",
				"contact_no": "phone_1",
				"fax": "fax_1"
			}
		}}, target_doc, set_missing_values, ignore_permissions=ignore_permissions)

	return doclist

Hi @Maheshwari_Bhavesh
through Custom Script it is possible or not because i don’t have back-end code access.

Thank You

possible check this :

Hi @hari.kishor

As far as I have understood from the conversation on this thread, I presume you want to add a Client button under the Make button on Lead doctype which would route you to your custom doctype’s new form.

You don’t need to add any back-end code. Paste the below code in the Custom Script for Lead doctype.

frappe.ui.form.on("Lead", {
	refresh: function(frm) {
		frm.add_custom_button(__("Client"), function() {
			frappe.route_options = {
				"client_name": frm.doc.lead_name
			};
			frappe.new_doc("[your_custom_doctype_name]");
		}, __("Make"));
	}
});

Here, under the route_options you can add the fields which you would like to copy from the Lead Doctype to your custom doctype and define according to that.

Hope this helps.

4 Likes