Data is getting load slowly. Have pasted the custom client script.
frappe.ui.form.on(‘Planning’, {
wi_no: function (frm) {
frm.clear_table('table_rmsf');
frappe.model.with_doc('WI', frm.doc.wi_no, function () {
let source_doc = frappe.model.get_doc('WI', frm.doc.wi_no);
parent_item_code=source_doc.child_table_item[0].custom_item_code;
// To fetch values from Product Table
$.each(source_doc.raw_material_table, function(index, source_row_raw) {
stock_qp=0;
frappe.db.get_list('Item', {
fields: ['*'],
filters: {
item_code: source_row_raw.item_code
}
}).then(records => {
row = frm.add_child('table_rmsf');
stock=records[0].custom_stock_qty;
saf_stk=records[0].safety_stock;
stock_qp=stock;
row.min_stock=saf_stk;
//////////////////////////// To Fetch Actual Quantity ////////////////////////////////////////
let act_qty_s=[];
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Bin",
fields: ['name','item_code','actual_qty'],
filters: {item_code: records[0].item_code},
},
async:false,
callback: function(r,act_qty_s=0) {
var a=r.message;
var act_qty=a[0]['actual_qty'];
row.stock = act_qty;
}
});
//////////////////////////////// To DISPLAY PO QTY Start////////////////////
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Order Item",
fields: ['parent','name','item_code','item_name','qty'],
filters: {item_code: records[0].item_code},
parent: "Purchase Order"
},
async:false,
callback: function(rpo) {
//////////////////*************** Purchase Receipt Display Start *****************////////////////////
var tprqtyp=0;
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Receipt Item",
fields: ['parent','name','item_code','item_name','received_qty'],
filters: {item_code: records[0].item_code},
parent: "Purchase Receipt"
},
async:false,
callback: function(prp) {
pr_message=prp.message['length'];
for(j=0;j<pr_message;j++){
prqtyp=parseFloat(prp.message[i].received_qty);
tprqtyp=parseFloat(tprqtyp)+parseFloat(prqtyp);
}
row.received_qty=tprqtyp;
}
})
//////////////////*************** Purchase Receipt Display End *****************////////////////////
l_message=rpo.message['length'];
var tpoqty=0;
for(i=0;i<l_message;i++){
/////////////////****************** FILTER PO QTY START ********************************************
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Order",
fields: ['*'],
filters: {name:rpo.message[i].parent},
},
async:false,
callback: function(rpop) {
if((rpop.message[0].status=="To Receive and Bill")||(rpop.message[0].status=="To Receive") ){
poqty=parseFloat(rpo.message[i].qty);
tpoqty=parseFloat(tpoqty)+parseFloat(poqty);
}
}
})
/////////////////******************** FILTER PO QTY END ******************************************
}
row.po_qty=(parseFloat(tpoqtyp)-parseFloat(row.received_qty));
}
});
//////////////////////////////// To DISPLAY PO QTY End ////////////////////
row.p_code=source_row_raw.item_code;
row.parent_code = parent_item_code;
row.part_name = source_row_raw.custom_part_name;
row.material = source_row_raw.custom_material;
row.location = source_row_raw.custom_location;
row.drawing_no__size = source_row_raw.custom_drawing_no__size;
row.item_code = source_row_raw.item_code;
row.item_name = source_row_raw.item_name;
row.qty = source_row_raw.custom_qty;
short_cal=row.qty-(row.stock+row.po_qty);
if(short_cal<0){
short_cal=0;
}
row.short=short_cal;
// row.short=row.qty-(row.stock+row.po_qty);
//////////////////////////////////////////////
row.order_qty=row.short;
frm.refresh_field('table_rmsf');
});
});
/////////////////// CUSTOM CUSTOM Items ///////////////////////////////////
$.each(source_doc.custom_custom, function(index, source_row_custom) {
stock_q=0;
saf_stk='';
frappe.db.get_list('Item', {
fields: ['*'],
filters: {
item_code: source_row_custom.item_code
}
}).then(records => {
row = frm.add_child('table_rmsf');
saf_stk=records[0].safety_stock;
/////////////////// To Display Actual Qty of Custom Item ///////////
let act_qty_sc=[];
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Bin",
fields: ['name','item_code','actual_qty'],
filters: {item_code: records[0].item_code},
},
async:false,
callback: function(rc,act_qty_sc=0) {
var ac=rc.message;
var act_qtyc=ac[0]['actual_qty'];
row.stock = act_qtyc;
}
});
//////////////////////////////// To DISPLAY CUSTOM PO QTY Start////////////////////
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Order Item",
fields: ['parent','name','item_code','item_name','qty'],
filters: {item_code: records[0].item_code},
parent: "Purchase Order"
},
async:false,
callback: function(rpoc) {
//////////////////*************** Purchase Receipt Display Start *****************////////////////////
var tprqty=0;
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Receipt Item",
fields: ['parent','name','item_code','item_name','received_qty'],
filters: {item_code: records[0].item_code},
parent: "Purchase Receipt"
},
async:false,
callback: function(pr) {
pr_message=pr.message['length'];
for(j=0;j<pr_message;j++){
prqty=parseFloat(pr.message[i].received_qty);
tprqty=parseFloat(tprqty)+parseFloat(prqty);
}
row.received_qty=tprqty;
}
})
//////////////////*************** Purchase Receipt Display End *****************////////////////////
l_message=rpoc.message['length'];
var tpoqty=0;
for(i=0;i<l_message;i++){
/////////////////****************** FILTER PO QTY START ********************************************
frappe.call({
method:"frappe.client.get_list",
args: {
doctype:"Purchase Order",
fields: ['*'],
filters: {name:rpoc.message[i].parent},
},
async:false,
callback: function(rpop) {
if((rpop.message[0].status=="To Receive and Bill")||(rpop.message[0].status=="To Receive")){
poqty=parseFloat(rpoc.message[i].qty);
tpoqty=parseFloat(tpoqty)+parseFloat(poqty);
}
}
})
/////////////////******************** FILTER PO QTY END ******************************************
}
row.po_qty=(parseFloat(tpoqty)-parseFloat(row.received_qty));
}
});
//////////////////////////////// To DISPLAY CUSTOM PO QTY End ////////////////////
row.p_code=source_row_custom.item_code;
row.item_code=source_row_custom.item_code;
row.item_name=source_row_custom.item_name;
row.parent_code = parent_item_code;
row.part_name = source_row_custom.part_name;
row.material = source_row_custom.material;
row.location = source_row_custom.location;
row.drawing_no__size = source_row_custom.drawing_no__size;
row.qty = source_row_custom.qty;
// row.stock=source_row_custom.custom_stock_qty;
// row.stock=stock_q;
row.min_stock=saf_stk;
short_cal=row.qty-(row.stock+row.po_qty);
if(short_cal<0){
short_cal=0;
// row.short=row.qty-(row.stock+row.po_qty);
}
row.short=short_cal;
// row.short=row.qty-(row.stock+row.po_qty);
row.order_qty=row.short;
frm.refresh_field('table_rmsf');
});
});
});
}
});