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.
frm.set_df_property('packed_items', 'cannot_add_rows', true);
frm.set_df_property('packed_items', 'cannot_delete_rows', true);
},
refresh: function(frm) {
if(frm.doc.docstatus === 1 && frm.doc.status !== 'Closed'
&& flt(frm.doc.per_delivered, 6) < 100 && flt(frm.doc.per_billed, 6) < 100) {
frm.add_custom_button(__('Update Items'), () => {
erpnext.utils.update_child_items({
frm: frm,
child_docname: "items",
child_doctype: "Sales Order Detail",
cannot_add_row: false,
})
});
}
if (frm.doc.docstatus === 0 && frm.doc.is_internal_customer) {
frm.events.get_items_from_internal_purchase_order(frm);
}
},
query.filters.push(["Bin", "item_code", "=", row.item_code]);
}
return query;
});
// On cancel and amending a sales order with advance payment, reset advance paid amount
if (frm.is_new()) {
frm.set_value("advance_paid", 0)
}
frm.ignore_doctypes_on_cancel_all = ['Purchase Order'];
},
delivery_date: function(frm) {
$.each(frm.doc.items || [], function(i, d) {
if(!d.delivery_date) d.delivery_date = frm.doc.delivery_date;
});
refresh_field("items");
}
});
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…