Amount field in Documents

In all the documents, Amount = Rate * Quantity.

I’m populating Rate automatically through a custom script. In this case, the Amount field (which is auto-calculated on entering Rate and Quantity) is not calculated.

Any suggestions to get the Amount field calculated automatically? Thanks!

That is a hard problem.

https://github.com/frappe/erpnext/blob/develop/erpnext/public/js/transaction.js#L621

We are using this script to calculate the total quantity.

How do we make sure that the fields which change on quantity also get changes when the script runs.

cur_frm.cscript.quantity_in_weight = function(doc, cdt, cdn) {
    var item = frappe.get_doc(cdt, cdn);
    item.qty = item.quantity_in_weight / item.net_weight;
    refresh_field("qty", item.name, item.parentfield);
};

Try this one:

cur_frm.cscript.quantity_in_weight = function(doc, cdt, cdn) {
    var item = frappe.get_doc(cdt, cdn);
    var qty = item.net_weight ? flt(item.quantity_in_weight) / flt(item.net_weight) : 0.0;
    frappe.model.set_value(cdt, cdn, "qty", qty);
};

Dear Nabin,

 frappe.model.set_value(cdt, cdn, "qty", qty);

This works fine. Now, dependent fields also changes.
Your script improve my code quality. If net_wet is zero, quantity becomes zero.

Thank you very much.