What is the best way to duplicate a DocType of ERPNext

@YogiYang I checked the method you are using make_stock_entry and it only has 3 args (work_order_id, purpose, qty).

The warehouse that will be used is the wip_warehouse (work in progress) from work order.

And if the stock entry a material transfer then the purpose must be Material Transfer for Manufacture.

But if the purpose is something else, then the from_warehouse will be the wip_warehouse and the to_warehouse will be the finished good warehouse fg_warehouse from the work order.

@kid1194,

Ok understood.

But in my case we never use the WIP Warehouse.

The source warehouse is different at various stages of production.

Is there any way by which we can show the Stock Entry DocType pre-filled with necessary data and then let the user submit it?

TIA

Yogi Yang

@YogiYang Moreover, the make_stock_entry method doesn’t create an entry, it returns a dict object of the entry. So you can edit the result of the call and add then create the entry.

The code can be something like the following:

frappe.xcall('erpnext.manufacturing.doctype.work_order.work_order.make_stock_entry', {
    work_order_id: "MFG-WO-2022-00008",
    purpose: "Material Transfer for Manufacture",
    qty: finish_args.qty_mfged
}).then(function(data) {
    data.from_warehouse = My_Row.source_warehouse;
    data.to_warehouse = My_Row.target_warehouse;
    frappe.db.insert(data);
});
1 Like

@YogiYang But if you want to redirect the user to the Stock Entry form with predefined values, then use the following codes.

Redirect

The object is the predefined fieldnames and values.

frappe.set_route('Form', 'Stock Entry',  {
    work_order_id: "MFG-WO-2022-00008",
    purpose: "Material Transfer for Manufacture",
    qty: finish_args.qty_mfged
});

Client Script for stock entry form

frappe.ui.form.on('Stock Entry', {
   refresh: function(frm) {
       if (frappe.has_route_options) {
           $.each(frappe.route_options, function(k, v) {
               frm.set_value(k, v);
           });
       }
   }
});
1 Like

Hi @kid1194 ,
I need to duplicate the sales invoice doctype but when i click on duplicate and click save it is not getting saved