We have done the same for one of our clients.
We have created custom doc Inquiry and then based on the details filled in the Inquiry, Sales order is being created.
below is the custom script for both
In Inquiry
frappe.ui.form.on("Inquiry", {
"refresh": function(frm, cdt, cdn) {
var d = locals[cdt][cdn];
frm.add_custom_button(__("Create Sales Order"), function() {
frappe.new_doc('Sales Order', {
"customer": cur_frm.doc.company_name,
"inquiry_no": cur_frm.doc.name
});
});
}
});
And in Sales Order
frappe.ui.form.on("Sales Order", {
"refresh": function(frm, cdt, cdn) {
if(frm.doc.__islocal && frm.doc.inquiry_no){
frappe.model.with_doc("Inquiry", frm.doc.inquiry_no, function() {
var mcd = frappe.model.get_doc("Inquiry", frm.doc.inquiry_no);
cur_frm.clear_table("items");
$.each(mcd.items, function(i, d) {
i = frm.add_child("items");
i.item_code = d.item_code;
i.item_name = d.item_name;
i.product_make = d.product_make;
i.cas_no = d.cas_no;
i.uom = d.uom;
i.stock_uom = d.uom;
i.description = d.description;
i.qty = d.qty;
});
cur_frm.refresh_field("items");
});
}
}
});