How to set default warehouse in the Stock entry

Hai, when I am creating the new stock entry I want the Source warehouse can be field up with the default warehouse of the item. how can I achieve this. if there is any code please provide .

Hi @harsha1,

That for, you have to write a client script for the Stock Entry DocType.

Please apply the code:

frappe.ui.form.on('Stock Entry Detail', {
    item_code: function(frm, cdt, cdn) {
        var row = locals[cdt][cdn];
        if(row.item_code) {
            frappe.call({
                method: "frappe.client.get",
                args: {
                    doctype: "Item",
                    filters: {
                        item_code: row.item_code
                    },
                    fields: ["item_defaults"]
                },
                callback: function(r) {
                    if(r.message && r.message.item_defaults.length > 0) {
                        var company = frm.doc.company;
                        var default_warehouse = null;

                        r.message.item_defaults.forEach(function(d) {
                            if (d.company === company) {
                                default_warehouse = d.default_warehouse;
                            }
                        });

                        if (default_warehouse) {
                            frappe.model.set_value(cdt, cdn, "s_warehouse", default_warehouse);
                        } else {
                            frappe.msgprint(__('No default warehouse found for item "{0}" under company "{1}".', [row.item_code, company]));
                        }
                    }
                }
            });
        }
    }
});

Output:

Now, you can set your logic according to the scenario.

1 Like