We are making outgoing inspection from sales invocie (as it is set that quality inspection must be made before invoice) with reference type - sales invoice, reference name as sales invoice.
However, we also need a custom fielf that must show the sales order reference of the same invoice number.
can someone guide by custom script ?
NCP
July 6, 2024, 3:59pm
2
First add the custom field like sales_order_reference in the Quality Inspection and add the client and server script.
frappe.ui.form.on('Quality Inspection', {
reference_name: function(frm) {
if(frm.doc.reference_type == 'Sales Invoice' && frm.doc.reference_name) {
frappe.call({
method: 'custom_app.api.get_sales_order_from_invoice',
args: {
sales_invoice: frm.doc.reference_name
},
callback: function(r) {
if(r.message) {
frm.set_value('sales_order_reference', r.message);
}
}
});
}
}
});
import frappe
@frappe.whitelist()
def get_sales_order_from_invoice(sales_invoice):
sales_order = frappe.db.get_value('Sales Invoice Item', {'parent': sales_invoice}, 'sales_order')
return sales_order
Please set the method path according to the app. code tested so it works properly.
1 Like
Many thanks for such a fast response. I will try this and post a response shortly
This is something i am not able to understand that whether to install new app as âcustom appâ or new doctype or change code in method ?
WE were able to solve this with below script :
frappe.ui.form.on(âQuality Inspectionâ, {
refresh: function(frm) {
if(frm.doc.reference_type == âSales Invoiceâ){
if(!frm.doc.sales_order){
frappe.db.get_value(âSales Invoiceâ, frm.doc.reference_name, âsales_orderâ)
.then(r => {
if(r.message.sales_order) {
frm.set_value(âsales_orderâ, r.message.sales_order);
frm.refresh_field(âsales_orderâ);
}
});
}
}
},
onload: function(frm) {
if(frm.doc.reference_type == âSales Invoiceâ){
if(!frm.doc.sales_order){
frappe.db.get_value(âSales Invoiceâ, frm.doc.reference_name, âsales_orderâ)
.then(r => {
if(r.message.sales_order) {
frm.set_value(âsales_orderâ, r.message.sales_order);
frm.refresh_field(âsales_orderâ);
}
});
}
}
},