Sales order Item -Amount calculation

Hello,
In my sales order, I want to remove the automatic calculation of ‘Amount’ (qty * rate) so that I can calculate Rate from Amount and Qty (Rate= Amount / Qty),

But I didn’t see any cscript for ‘rate’ value change in ‘sales_order.js’ file!
Where is that code? Anybody know how can I stop the the automatic calculation of Amount in Sales Order Items please?

Hi @Amalendu,

you can find the trigger for rate field in sales_common.js

Thanks, Makarand

@makarand_b
HI,

I have commented those lines, but it still calculate the amount dynamically from Qty and rate!!!
Now I am using ERPNext V7

 make_payment_request: function() {
                frappe.call({
                    method:"erpnext.accounts.doctype.payment_request.payment_request.make_payment_request",
                    args: {
                        "dt": cur_frm.doc.doctype,
                        "dn": cur_frm.doc.name,
                        "recipient_id": cur_frm.doc.contact_email
                    },
                    callback: function(r) {
                        if(!r.exc){
                            var doc = frappe.model.sync(r.message);
                            frappe.set_route("Form", r.message.doctype, r.message.name);
                        }
                    }
                })
            },

        //    rate: function(doc, cdt, cdn){
                // if user changes the rate then set margin Rate or amount to 0
        //        item = locals[cdt][cdn];
        //        item.margin_type = "";
        //        item.margin_rate_or_amount = 0.0;
        //        cur_frm.refresh_fields();
        //    },

            margin_rate_or_amount: function(doc, cdt, cdn) {
                // calculated the revised total margin and rate on margin rate changes
                item = locals[cdt][cdn];
                this.apply_pricing_rule_on_item(item)
                this.calculate_taxes_and_totals();
                cur_frm.refresh_fields();
            },

How can I stop this,?
I just want to enter the Qty and Amount only.
The rate is to be calculate from it…

I can write cscript. but how can i stop this?
anybody know?

hii there…
please help me on this topic…

Still i didn’t get a solution…

I urgently need the amount to be constant.
The rate must be calculate when i give Qty and Amount…

Even I commented the 'rate: ’ trigger in sales_common.js , when I click save button , it calculates Amount back to Qty * rate !!!

Eg. I gave Qty = 450
** Amount = 5000**
Calculated Rate = 11.11

when I click save Button

Amount changes to 4999.50
I want Amount as 5000

How to get this?

Hi have you tried doing this in Doc Events?

try making a python script that calculates and then put it here.

doc_events = {
    "Doctype": {
        "after_insert": "path.to.your.python.script.method"
    },
    "Another Doctype": {
        "after_insert": "path.to.your.other.python.script.method"
    }
}
2 Likes

@johnskywalker

Thank you for giving me a solution!

you’re welcome! :slight_smile: