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.
frappe.provide(“erpnext.public”);
frappe.provide(“erpnext.controllers”);
console.log(“:::::::”);
erpnext.TaxesAndTotalsCustomization = erpnext.taxes_and_totals.extend({
setup: function(){},
calculate_item_values: function() {
var me = this;
console.log(“:::::CUSTOM:::::me:::::”,me);
},
})
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 hooks.py ( 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
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 hooks.py. (app_include_js)
Hi @yogendrasinh@krithi_ramani I seem to be having a similar issue, I am trying to extend the functionality of the calculate_outstanding_amount method in the same script,
I have done everything stated here (added to app_include_js) and even added the file path to my build.json but still the core method is still being called, can i please get any guidance ? thank you
@pipech can you explain what it is you are doing with your code? Does it completely override the pre existing js or extends it? I tried it and it didn’t seem to work. I’ve been trying to override pre existing js functions.
// TaxesAndTotalsExtend is just variable name
// erpnext.taxes_and_totals is function contain function you want to override
const TaxesAndTotalsExtend = erpnext.taxes_and_totals.extend({
// calculate_item_values is function you want to override
calculate_item_values: () => {
console.log('Hello from extend taxes and total extend !!');
},
});
// this tell current form to use this override script
$.extend(
cur_frm.cscript,
new TaxesAndTotalsExtend({frm: cur_frm}),
);
Is this the same? The code below is called when the is_fixed_asset function is called, but i don’t think it replaces it. Its called from the core JS. I tried your code snippet, and it didn’t seem to work and i kept getting an error. I received a fatal error saying there was no erpnext.item.extend method when the script was called.
Your variation:
const ItemExtend = erpnext.item.extend({
is_fixed_asset:() => {
console.log("Hello from extend Item !! ");
},
});
$.extend(cur_frm.cscript, new ItemExtend({frm: cur_frm}),
);