Skip to content

Customizing Doctype Mapper

umairsy edited this page Jan 17, 2013 · 4 revisions

This following script was used to provide an option to convert Purchase Invoice into Sales Invoice. It was customized for a customer into services business where they purchase insurance policy by making Purchase Invoice. And convert the same Purchase Invoice into Sales Invoice when selling the policy to customer.

What will Script do?

The first part of script was written to show button "Make Sales Invoice" when Purchase Invoice has been submitted.

The later part of script maps data from main and child tables of Purchase Invoice into Sales Invoice form.

cur_frm.cscript.custom_refresh = function(doc) {
if(doc.docstatus == 1) {
cur_frm.add_custom_button("Make Sales Invoice",
cur_frm.cscript.make_sales_invoice);
}
};

cur_frm.cscript.make_sales_invoice = function() {
var sales_invoice = wn.model.make_new_doc_and_get_name("Sales Invoice");
$c("dt_map", {
docs: compress_doclist(make_doclist("Sales Invoice", sales_invoice)),
from_doctype: cur_frm.doc.doctype,
from_docname: cur_frm.doc.name,
to_doctype: "Sales Invoice",
from_to_list: JSON.stringify([["Purchase Invoice", "Sales Invoice"], ["Purchase Invoice Item", "Sales Invoice Item"]])
}, function(r, rt) {
loaddoc("Sales Invoice", sales_invoice);
});
}