To fetch the discount_percentage and discount_rate fields from Sales Order Item (SOI)and set them into Sales Invoice Item (SII) child table in ERPNext Version 15.
I have to make custom script get the value from sales order but not set in the sales invoice items “discount_percentage” and “discount_rate” fields under “Discount and Rate Margin” section.
Sales Invoice:
custom script code:
frappe.ui.form.on(‘Sales Invoice’, {
// Trigger when Sales Invoice is loaded
onload: function(frm) {
if (!frm.doc.__islocal) {
return;
}
console.log(‘frm.doc’);console.log(frm.doc);
if (frm.doc.items && frm.doc.custom_sales_order) {
frappe.call({
method: ‘frappe.client.get’,
args: {
doctype: ‘Sales Order’,
name: frm.doc.custom_sales_order
},
callback: function(response) {
let custom_sales_order = response.message;
if (custom_sales_order) {
let sales_order_items = custom_sales_order.items;
frm.doc.items.forEach((invoice_item) => {
// Find the corresponding Sales Order Item
let so_item = sales_order_items.find(item => item.item_code === invoice_item.item_code);
if (so_item) {
// Set discount_percentage and rate from Sales Order Item
console.log('discount_percentage'+so_item.discount_percentage);
console.log('discoount_rate'+so_item.discoount_rate);
frappe.model.set_value(invoice_item.doctype, invoice_item.name, 'discount_percentage', so_item.discount_percentage);
frappe.model.set_value(invoice_item.doctype, invoice_item.name, 'discoount_rate', so_item.rate);
}
});
}
}
});
}
}
});
we have got both value “discount_percentage” and “disscount_rate” but not set in sales invoice child table first we have created sales order after that create sales invoice from sales order.
How to resolve this issue only set the value??