Custom Scrip for emulating Multi Uom P Invoice

Hello community this time im trying to simulate a multi uom conversion in purchase doctype and sales doctype
i created a custon field called nvalor that will calculate the value of the price_list_rate by conversion_factor

right now in PURCHASE INVOICE it looks like this:

frappe.ui.form.on("Purchase Invoice Item", {
	uom: function(frm, cdt, cdn) {
		var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, "nvalor", d.price_list_rate * d.conversion_factor);        
	}
});

and

frappe.ui.form.on("Purchase Invoice Item", {
	qty: function(frm, cdt, cdn) {
		var d = locals[cdt][cdn];
frappe.model.set_value(d.doctype, d.name, "nvalor", d.price_list_rate * d.conversion_factor);        
	}
});

The field gets calculated, the problem is that i have change twice the uom or the qty to get the actual value sinces looks like it get triger before the conversion_rate changes.

Any Help ? Thanks in advance.

I this a child table?

yes the field and calculations are in the Purchase Invoice Item Table
The scrip goes in the Puchase Invoice Doctype.

are trying to trigger this by button?

no just by imput of qty or unit of measure change

ok, try this

cur_frm.cscript.some_fieldname_in_childtable = function (doc, cdt, cdn) {

var d = locals[cdt][cdn];

/*do your calculations here*/

refresh_field("the_child_table");

}

@johnskywalker thaks for your time. i never used that scrip before so i have no idea how to elaborate it please help me

My Parent doctype is Puchase Invoice
Calcuation are in Purchase Invoice Item

My custom Field is nvalor.
my calculation is: on change of qty or uom, (nvalor = d.price_list_rate * d.conversion_factor).
Thanks in advance!.

Hello, Is this correct?

  cur_frm.cscript.qty = function (doc, cdt, cdn) {

    var d = locals[cdt][cdn];

    /*do your calculations here*/
     cur_frm.set_value(d.doctype, d.name, "nvalor", d.price_list_rate * d.conversion_factor);

    refresh_field("items");
    }

its giving me the following error: Field Purchase Invoice Item not found.

thanks in advance

is “nvalor” a field in your child table?

Hello, yes in child table Purchase Invoice Item.

so it should be
d.nvalor = d.price_list_rate * d.conversion_factor;