Hello,
I have copied Project DocType and renamed it to my custom App. It is working good with required custom fields. I have mapped the DocType with Sales Order so that Sales Orders could be made from Multiple Project (renamed as ‘Program’ for this example) DocTypes:
In client Script;
frappe.ui.form.on("Sales Order", {
refresh: function(frm) {
if (frm.doc.docstatus === 0) {
frm.add_custom_button(
__("Program"),
function () {
erpnext.utils.map_current_doc({
method: "merchandising.custom.program.make_sales_order",
source_doctype: "Program",
target: frm,
setters: [
{
label: "Customer",
fieldname: "customer",
fieldtype: "Link",
options: "Customer",
default: frm.doc.customer || undefined,
},
],
get_query_filters: {
company: frm.doc.company,
},
});
},
__("Get Items From")
);
}
},
})
And in custom App:
import frappe
from frappe.model.mapper import get_mapped_doc
@frappe.whitelist()
def make_sales_order(source_name, target_doc=None):
doclist = get_mapped_doc(
"Program",
source_name,
{
"Program": {
"doctype": "Sales Order",
"field_map": {
"customer": "customer",
}
},
"Program Item": {
"doctype": "Sales Order Item",
"field_map": {
"name": "program_item",
"program_item": "sales_order_item",
"parent": "program",
"item_no": "item_code",
"item_name": "item_name",
"uom": "uom",
"po_qty": "qty",
},
},
},
target_doc,
)
doclist.set_onload("load_after_mapping", False)
return doclist
It is mapping and importing the DocType including child table:
However, it is only linking the first ‘Program’ Doctype in the series and not the all I imported. For example, I imported 2 Documents as MP-0002 and MP-0003 but linking and showing the first one MP-0002 only.
Can anyone tell why it is happening? I will highly appreciate any clue.
Thanks.