frappe.ui.form.on("Opportunity Item", "qty", function(frm, cdt, cdn){
var d = locals[cdt][cdn];
frappe.model.set_value(cdt, cdn, "amount", d.qty * d.amount);
});
that I inserted into a custom script with “Opportunity” doctype, but it didn’t work.
I customized a field on Opportunity form by creating “Amount” field, but it also didn’t work.
I would like to get the total amount of “With Items”, how can I do?
Rate and Amount fields are not available in default one you can add it using a custom field. But I think that’s not required for Opportunity. These fields are available in further selling and buying forms.
However, in case it is not available as in default, so how can I get an item rate from its selling rate or from a price list in order to get it to calculate with Qty in Opportunity? Because the objective by doing so, I’d like to get a total selling price (Qty * item amount) of the opportunity item table. How can I achieve this?
Hello Khushal_t,
Thanks so much for your reply. Your solution doesn’t work and I got some error raising when open Opportunity page. Could you please step into the solution in detail, how can I implement your suggestion? I’m quite new to ERPNext, so I’m probably implementing incorrectly. Additionally, I’m wondering that in Opportunity Items, there is no “rate” or “amount” in order to get for calculation, so how does it work for the solution?
@cipher Please you check console for errors please check that in for loop you have correct child table name . what I got is that you want to calculate the total amount in your opportunity item table eg; if it has 5 rows each have 100 amount so you want final amount to be 500 so if this is correct what I have got then
1)firstly calculate the amount for each row that is if you write a trigger on your qty so you will calculate row.qty * row.amount to that row so that u will set amount
> frappe.ui.form.on("<Child doctype Name>","<field(on which u want to trigger)>", function(frm, cdt, cdn) {
> var row = locals[cdt][cdn]
> frappe.model.set_value(row.doctype, row.name, "<Field on which u want to set the value>", row.qty * row.amount);
>
> });
after calculating to each row now you want to calculate total value for that child table in your case guess Opportunity Item
$.each(cur_frm.doc.opportunity_item, function(i,v){
//Here you iterate on your table to claculate
})
don’t directly copy and paste, check your field name for the same if I have understood your scenario well this should probably work. if I am wrong please provide more details
Hello Khushal_t,
Thank you so much for your reply. Please help me to check this link https://erpnext.org/docs/current/models/crm/opportunity_item?
There is no “Amount” or “Rate” field that involves an item rate (Selling price). Is it possible to use row.qty * row.amount
because I still don’t get that where I can get an item price for calculation. And what do you mean by //Here you iterate on your table to claculate
What syntax do I need to insert here? Feel sorry that I don’t understand what I have to do next really on this line.