Adding Sales Order & Invoice Buttons on the Item Form

Hi,

Is it possible to add Sales Order & Sales Invoice buttons at the top of the Item form (in the section I’ve circled), which will allow creating a Sales Order or Sales Invoice directly for that specific item? I want these buttons to automatically populate the item in the Sales Order/Invoice when clicked.
If so, can anyone guide me on how to implement this feature?

Please apply the client script on Item doctype.

frappe.ui.form.on('Item', {
    refresh: function(frm) {
        frm.add_custom_button(__('Sales Order'), function() {
            frappe.new_doc("Sales Order", {}, so => {
                frappe.model.clear_table(so, 'items');
                let row = frappe.model.add_child(so, "items");
                frappe.model.set_value(row.doctype, row.name, "item_code", frm.doc.name);
            });
        }, __('Create'));

        frm.add_custom_button(__('Sales Invoice'), function() {
            frappe.new_doc("Sales Invoice", {}, si => {
                frappe.model.clear_table(si, 'items');
                let row = frappe.model.add_child(si, "items");
                frappe.model.set_value(row.doctype, row.name, "item_code", frm.doc.name);
            });
        }, __('Create'));
    }
});

Now, you can set the scenario according.

1 Like

Thank you!!