I need childtable values from Job delivery transaction to Sales Invoice transaction

Hi All,
I need “Job Delivery Item” childtable from Job Delivery transaction to fetch to Sales Invoice childtable when choose"Get items from job delivery" in Sales invoice transaction


i need description,rate,amount fields for that i have written a code
frappe.ui.form.on(‘Sales Invoice’, {
refresh: function(frm) {
frm.fields_dict[‘project’].get_query = function(doc, cdt, cdn) {
var customer = frm.doc.customer;
return {
filters: [
[‘Customer’, ‘=’, customer]
]
};
};
}
});

frappe.ui.form.on(‘Sales Invoice’, {
refresh: function(frm) {
frm.add_custom_button(__(“Get items from Job Delivery”), function() {
show_sinv_dialog(frm);
});
}
});

function show_sinv_dialog(frm) {
frappe.prompt([
{‘fieldname’: ‘job_delivery’, ‘fieldtype’: ‘Link’, ‘label’: ‘Job Delivery’, ‘reqd’: 1, ‘options’: ‘Job Delivery’}
],
function(job_delivery){
console.log(job_delivery.job_delivery);
get_items_from_sinv(job_delivery.job_delivery);
},
‘Get items from job delivery’,
‘Get items’
)
}

function get_items_from_sinv(job_delivery) {
frappe.call({
“method”: “frappe.client.get”,
“args”: {
“doctype”: “Job Delivery”,
“name”: job_delivery
},
“callback”: function(response) {
// add items to your child table
var sinv = response.message;
console.log(sinv.items)
cur_frm.doc.customer=sinv.customer;
cur_frm.refresh_field(‘customer’);
cur_frm.clear_table(“items”);
sinv.items.forEach(function (item) {
var child = cur_frm.add_child(‘items’);
frappe.model.set_value(child.doctype, child.name, ‘item_code’, item.item_code);
frappe.model.set_value(child.doctype, child.name, ‘qty’, item.qty);
frappe.model.set_value(child.doctype, child.name, ‘description’, item.description);
frappe.model.set_value(child.doctype, child.name, ‘rate’, item.rate);
});
cur_frm.refresh_field(‘items’);
}
});
}
Thanks in Advance

sinv.items.forEach(function (item) {
cur_frm.add_child(“items”,{
“item_code”:item.item_code,
“qty”:item.qty,
“description”:item.description,
“rate”:item.rate
})
});

1 Like

but it is fetching values from item master for the fields “Description” and but for Rate and Amount fields are not fetching from Job Delivery to Sales Invoice


Thanks in Advance

you can do it using get_mapped_doc function in python

1 Like

can u guide or tell me the code please
Thanks in Advance

I think, you should check the video tutorial.

1 Like