How to override frappe javascript function

How to replace an Erpnext javascript function in V14. There is a function located at erpnext/erpnext/stock/doctype/item_price/item_price.js i want to replace it with my code, the function i want to replace in below. I know it can be done in hooks but i don’t know how to do it. I know how to replace a python script using hooks but with js i have failed please help.

frappe.ui.form.on(“Item Price”, {
setup(frm) {
frm.set_query(“item_code”, function() {
return {
filters: {
“disabled”: 0,
“has_variants”: 0
}
};
});
},

onload(frm) {
	// Fetch price list details
	frm.add_fetch("price_list", "buying", "buying");
	frm.add_fetch("price_list", "selling", "selling");
	frm.add_fetch("price_list", "currency", "currency");

	// Fetch item details
	frm.add_fetch("item_code", "item_name", "item_name");
	frm.add_fetch("item_code", "description", "item_description");
	frm.add_fetch("item_code", "stock_uom", "uom");

	frm.set_df_property("bulk_import_help", "options",
		'<a href="/app/data-import-tool/Item Price">' + __("Import in Bulk") + '</a>');

	frm.set_query('batch_no', function() {
		return {
			filters: {
				'item': frm.doc.item_code
			}
		};
	});
}

});

Hi @imbra,

Please go to the hook.py file and added it.

doctype_js = {"Item Price" : "public/js/item_price.js"}

Then go to the your_custom_app/public/js/ and create a item_price.js file and added a code.
Then reload (Ctrl + Shift + R) and check it.

Thank You!

3 Likes

Hey @NCP, thank you, but i have done this and nothing happed. I did bench clear-cache, bench build and bench migrate but nothing happened. But i will try (Ctrl + Shift + R)

The code below is in my custom app

frappe.ui.form.on(“Item Price”, {
	onload(frm) {
		frm.add_fetch("price_list", "opop", "opop");
	}
});

Hi @imbra,

If only work, this value gets updated every time you select a price_list in an Item Price.

frappe.ui.form.on("Item Price", {
	price_list: function(frm) {
		frm.add_fetch("price_list", "opop", "opop");
	}
});

Reference: https://docs.erpnext.com/docs/v12/user/manual/en/customize-erpnext/custom-scripts/fetch-values-from-master#example

Thank You!

Thank you am going to try this

Hey, i have unistalled and reinstalled frappe and it is working

@NCP What if you want to override only a specific function within the file? Let’s say the refresh function only. Will this method work?

Hi @flexy2ky,

Yes.

Hi @imbra .
Nice to meet you.
Could you please check my topic , and have an idea?
Thank you.