Calculated Field for Purchase Order Item - ERPNext Cloud

Hi ERPNext community, a little help … ?
I am evaluating ERPNext cloud and need a little help making a calculated field show for Purchase Order Item. Should be fairly simple right … ?

Calculated field: qty_outstanding = qty - received_qty
have tried script for doc type ‘Purchase Order’ and script ‘Purchase Order’
have tried script for doc type ‘Purchase Order’ and script ‘Purchase Order Item’
have tried script for doc type ‘Purchase Order Item’ and script ‘Purchase Order’
have tried script for doc type ‘Purchase Order Item’ and script ‘Purchase Order Item’

frappe.ui.form.on(“Purchase Order Item”, “qty”, function(frm)
{frm.set_value(“qty_oustanding”, (frm.doc.qty - frm.doc.received_qty));}
);

Purchase Order (child table Purchase Order Item): does not show calculated field
(the 88 and 66 are manually entered, just to make sure the custom field is working OK - yes it is) - just the calculation does not work.

Hi @Jack! Try this under Purchase Order custom script:

cur_frm.cscript.qty = function(doc, cdt, cdn) {
	var d = locals[cdt][cdn];
        d.qty_outstanding = d.qty - d.received_qty
        refresh_field("items");
} 
1 Like

Works like a charm, thanks very much @creamdory, love your work.
ERPNext back in the game.

2 Likes

I tried this script for Sales Order, with the child table “items”. The custom field is of type float with name outstanding_qty in the child table.
It is somehow not working. Can anyone help me on this?

In custom script of Sales Order:

cur_frm.cscript.qty = function(doc, cdt, cdn) {
var d = locals[cdt][cdn];
d.outstanding_qty= d.qty - d.delivered_qty;
refresh_field(“items”);
}