ERPNext Foundation ERPNext Cloud Chat Blog Discuss Frappé* Donate

How to Override js function in erpnext v9



I am trying to override js function named “calculate_item_values” is available in (erpnext=>erpnext=>public=>js=>controllers=>taxes_and_totals.js) erpnext.
to do a calculation for an amount in sales order lines.

Below is my code, I added in my custom application by creating controllers directory but it not working.

erpnext.TaxesAndTotalsCustomization = erpnext.taxes_and_totals.extend({
setup: function(){},
calculate_item_values: function() {
var me = this;

It is more prior to me. Please help me on this.

Thanks in advance :slight_smile:

Pass data to new link doctype

This won’t work because even after this, erpnext.taxes_and_totals is used to calculate the values and not your modified function. You can do this:


erpnext.TaxesAndTotalsCustomization = erpnext.taxes_and_totals.extend({
  setup: function(){},
  calculate_item_values: function() {
    var me = this;
    console.log(":::::CUSTOM:::::me:::::", me);

erpnext.taxes_and_totals = erpnext.TaxesAndTotalsCustomization;


Hello @netchampfaris,

Thank you for replying. :slight_smile:
I improved my code as per your suggestion but still it not working,
And also tried commands to remove cache.

bench migrate
bench build
bench clear-cache
and then reloaded the browser, but still not working. :thinking:


Make sure your js file is loaded. Maybe you’ll have to add it to build.json


Where do I need to add build.json file?
because I am not aware of build.json file.

Yes, my js file is loaded because I added one console.log() at the beginning of my js file and that is print when I reload the browser, because of my js file path is added to ( app_include_js = “”).



In that case, you dont need to add to build.json, You will have to check whether the erpnext.taxes_and_totals class is available before extending it. Try debugging it using the debugger statement in JS


Hello @netchampfaris,

Sry for the late reply.
Thanks for the suggestion. I will try to fix it by the debugger.


Hello @netchampfaris,

Finally, I got the solution to override js function through the prototype.
Below is my code and it works fine.

erpnext.taxes_and_totals.prototype.calculate_item_values = function(){
var me = this;

Thanks. :slight_smile:


Am trying to override the onload function of Item, from custom script. This is my code


erpnext.item.prototype.onload = function()
frappe.msgprint(‘overriding onload from cust script’);

What am I missing?



Hello Krithi,

where did you put this code?
I mean create a New and separate application?
you have to put the code in public directory ( for ex : public=>js=> file.js ) and also add the path of that file in (app_include_js)



Yes. In a custom app,added a file under pubic/js/ and referred it in hooks under doctype_js.

Now tried adding under app_include_js also. Didn’t work. Still invokes core ‘onload’.