ERPNext Conference 2019* Blog

Custom Script Button at PURCHASE ORDER To Discount / Recude All Item Price At Child Table


Hi, ERPNext is great ERP because we can make own Button and make it run for some alert or custom script.

Now, I would like to ask help to make a CUSTOM SCRIPT BUTTON for change or reduce each price rate at Item list (child table) of PURCHASE ORDER. The Purchase Order status still at DRAFT.

What I Need: When the Button Pressed, all Rate price will be -50 (reduce $50 or some other fix value) for each item list like picture that I attach.

Thank you in advance


@erpwork You can Create Button by going into Customize Form of Purchase Order.

frappe.ui.form.on("Purchase Order", {
	discount_button_name:function () {
		var fix_value=cur_frm.doc.fix_value;
		var child_table=cur_frm.doc.items;
		for(var i=0;i<child_table.length;i++){
			child_table[i].rate -=fix_value

custom Script may Look like this.


Thank you for fast reply @ROHAN_JAIN1 :pray:

You give me great idea to make it work as what I need :+1:

I have done some editing to your code and it can run without troubles after copy and paste at Custom Script form.

frappe.ui.form.on('Purchase Order', {

refresh: function(frm) {

	frm.add_custom_button(__("Reduce Price"), function() {
		var fix_value=50;

		var child_table=cur_frm.doc.items;
		for(var i=0;i<child_table.length;i++){
			child_table[i].rate -=fix_value;

		frappe.msgprint("Done <b>FINISH</b> "+fix_value);

}  });

Once again thank you very much :innocent: