Create 'Make Payment' button on custom Doctype

Hai Everyone,
I have created a custom doctype for entering expenses of Subcontractor.
If the form is saved and submitted, I want to do the ‘Make’ button visible and it shows options ‘Make Payment’ and ‘Make Completion Certificate’.
The ‘Make’ button is like in the cases of Lead/Opportunity/Sales order etc.

I am in trouble, as i don’t know where to do it in the custom doctype.
I see in Lead.js the code should be inside,
erpnext.LeadController = frappe.ui.form.Controller.extend({
similarily in Quotation.js, it is inside
erpnext.selling.QuotationController = erpnext.selling.SellingController.extend({

So howis it possible it in custom doctype?

@Amalendu
Add custom button and call your custom function.

Let me know, if you have any issue in creating button and calling your script

1 Like

@kolate_sambhaji. Thank you. Surely, will let you know soon.

@kolate_sambhaji. It works!!! Thank you so much

But, I want to show this button once it is submitted.
Is anything wrong in my code shown below: Can you help me please?

frappe.provide(“erpnext.crm”);
frappe.require(“assets/erpnext/js/utils.js”);
frappe.ui.form.on(‘Subcontract’, {
refresh: function(doc,dt,dn) {
//cur_frm.cscript.custom_validate(frm.doc);

	if(doc.docstatus=='Submitted') {
	//	if(doc.status != 'Closed') {
			cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_bank_entry, __("Make"));
			cur_frm.add_custom_button(__('Completion Certificate'), cur_frm.cscript.make_completion_certificate, __("Make"));
	//	}
		cur_frm.page.set_inner_btn_group_as_primary(__("Make"));	
	}
},

make_completion_certificate: function() {
	frappe.model.open_mapped_doc({
		method: "erpnext.projects.doctype.subcontractor_completion_certificates.opportunity.make_certificate",
		frm: cur_frm
	})
},

make_bank_entry: function() {
	return frappe.call({
		method: "erpnext.accounts.doctype.journal_entry.journal_entry.get_payment_entry_against_order",
		args: {
			"dt": "Sales Order",
			"dn": cur_frm.doc.name
		},
		callback: function(r) {
			var doclist = frappe.model.sync(r.message);
			frappe.set_route("Form", doclist[0].doctype, doclist[0].name);
		}
	});
}	

});

doc.docstatus == 1 to check submitted document.

@kolate_sambhaji I tried it also… but it doesn’t work for me.
Status is shown “undefined” !

@Amalendu share your code

@kolate_sambhaji

The code was…

frappe.ui.form.on(‘Subcontract’, {
refresh: function(doc,dt,dn) {
//cur_frm.cscript.custom_validate(frm.doc);
alert(doc.docstatus);
if (doc.docstatus==1) {
// if(doc.status != ‘Closed’) {
cur_frm.add_custom_button(__(‘Payment’), cur_frm.cscript.make_bank_entry, (“Make”));
cur_frm.add_custom_button(
(‘Completion Certificate’), cur_frm.cscript.make_completion_certificate, (“Make”));
// }
cur_frm.page.set_inner_btn_group_as_primary(
(“Make”));
}
},

But
alert(cur_frm.doc.docstatus) ;

Shows correct status!! Thank you

You need to write

refresh: function(frm,dt,dn) {
then you can access status using frm.doc.status

1 Like

oh… understood…
Thank you…