How can add Extra Amount with Total field


@NCP can you help me for this?

You can edit the total INR?
If the field is read-only, go to customize and disable read-only.

this is from opportunity doctype here total calculating from controller class…

Do you created a custom field " Extra Amount "?

Yes i created custom field that amount i want to add in total INR

go to client script

choose doctype : opportunity

Paste this script

frappe.ui.form.on(‘Opportunity’, {
refresh(frm) {
frappe.ui.form.on(‘Opportunity Item’, {
// Trigger the calculation when the extra amount, quantity, or rate changes
extra_amount: function(frm, cdt, cdn) {
calculateTotalINR(frm);
},
qty: function(frm, cdt, cdn) {
calculateTotalINR(frm);
},
rate: function(frm, cdt, cdn) {
calculateTotalINR(frm);
}
});

function calculateTotalINR(frm) {
var total = 0;
frm.doc.items.forEach(function(item) {
total += flt(item.amount);
total += flt(item.extra_amount);
});
frm.set_value(‘total’, total);
refresh_field(‘total’);
}

}

})

save
then check

it will not work, once check after save…

REPLY THIS SCRIPT

frappe.ui.form.on(‘Opportunity Item’, {
// Trigger the calculation when the items table refreshes
items_remove: function(frm, cdt, cdn) {
calculateTotal(frm);
},
items_add: function(frm, cdt, cdn) {
calculateTotal(frm);
}
});

frappe.ui.form.on(‘Opportunity Item’, ‘extra_amount’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘qty’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘rate’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity’, {
// Trigger the calculation when the form refreshes
refresh: function(frm) {
calculateTotal(frm);
}
});

function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function(item) {
total += flt(item.amount);
total += flt(item.extra_amount);
});
frm.set_value(‘total’, total); // Update the “total” field
refresh_field(‘total’); // Refresh the “total” field to display the updated value
}

using this client script, can’t save the form

if you do not add the field in the item table, replace “extra_amount” instead of “item.extra_amount”

i added in opportunity item child table but when i applied this client script i am not able to save opportunity it always show not saved, did you try save opportunity ?

please send me the error message or screenshot of opportunity

I clear that issue replace this script

"

frappe.ui.form.on(‘Opportunity Item’, {
// Trigger the calculation when the items table refreshes
items_remove: function(frm, cdt, cdn) {
calculateTotal(frm);
},
items_add: function(frm, cdt, cdn) {
calculateTotal(frm);
}
});

frappe.ui.form.on(‘Opportunity Item’, ‘extra_amount’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘qty’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘rate’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity’, {
// Trigger the calculation when the form refreshes
refresh: function(frm) {
calculateTotal(frm);
}
});

function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function(item) {
total += flt(item.amount);
total += flt(item.extra_amount);
});
frm.set_value(‘total’, total); // Update the “total” field
refresh_field(‘total’); // Refresh the “total” field to display the updated value
}

frappe.ui.form.on(‘Opportunity Item’, {
// Trigger the calculation when the items table refreshes
items_remove: function(frm, cdt, cdn) {
calculateTotal(frm);
},
items_add: function(frm, cdt, cdn) {
calculateTotal(frm);
}
});

frappe.ui.form.on(‘Opportunity Item’, ‘extra_amount’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘qty’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

frappe.ui.form.on(‘Opportunity Item’, ‘rate’, function(frm, cdt, cdn) {
calculateTotal(frm);
});

function calculateTotal(frm) {
var total = 0;
frm.doc.items.forEach(function(item) {
total += flt(item.amount);
total += flt(item.extra_amount);
});

// Set the “total” field and trigger its recalculation and refresh
frappe.model.set_value(frm.doctype, frm.docname, ‘total’, total);
frappe.model.trigger(frm.doctype, frm.docname, ‘total’);
}

"


see when i saved form it always show not saved and when i checkd in database, it show 1,50,000 not 1,50,400

@umair and @rmehta please help @NCP