ERPNext.com Frappe Cloud Support Partners Foundation

Update amount field in Sales Order Item Table

We have three fields inside the Sales Order Item Table :
qty, bales, rate
We want to perform the operation: qty * bales * rate and update it in the amount field present inside the particular item.
Please help.

Try this…

frappe.ui.form.on("Sales Order Item", {
        qty: function(frm, cdt, cdn){
        var row = locals[cdt][cdn];
        row.amount = flt(row.qty) * flt(row.bales) * flt(row.rate);
        frm.refresh_field("items");
    },
        rate: function(frm, cdt, cdn){
        var row = locals[cdt][cdn];
        row.amount = flt(row.qty) * flt(row.bales) * flt(row.rate);
        frm.refresh_field("items");
    },
        bales: function(frm, cdt, cdn){
        var row = locals[cdt][cdn];
        row.amount = flt(row.qty) * flt(row.bales) * flt(row.rate);
        frm.refresh_field("items");
    },
});

@r.anderson Thanks for your reply.
Tried the above code, it is working fine when printing the values on the console.

But the amount field is not getting updated in the item section when qty, bales, and rate are entered in the respective order. ( it is not taking bales into consideration )

When the value of bales is entered after the rate, the amount is getting updated correctly.

Can’t really figure out the reason.

May be that is because of the code function sequence. Do notice that first qty: function, then rate: function and finally bales: function in the shared code snippet.
Just to confirm the above behavior, can you modify the code a bit to place bsales: function before rate: function