Multiple Discount in Sales Invoice

Hi Everyone,

How can i set multiple discount in sales invoice?

E.g. Option like Apply Credit and Calculate the updated price on the item.

You can use pricing rule at some level.

@hari.kishor
This link Pricing Rule can help you.

Hey @Hor_Kimhab @bhavikpatel7023 thanks for response.

What i want is →

A new discount like field which we already have in Additional discounts section.
Let us assume the name of field as Credits Applied
Now whenever we set this field with any value then automatically all the calculation should happen like

  1. net total amount
  2. taxes calculation
  3. outstanding amount and other values.

All the values should change the same way when we apply discount.

I want this to be executed through custom script or any suggestion if i can use any custom script method or any frappe call or any solution you can provide.

Please help me out as its urgent.

User Custom Script for this issue.

But how that is my question ? How i can use the built in function of erpnext ? I want to know the method.

i give an example in our system theres a multiple discount by adding fields and used custom script.

2 Likes

@Denmark_Del_Puso
can you share the code with us ?

ok i can share my code.

//DISCOUNT 1
cur_frm.cscript.custom_disc_percent1 = function(doc){
	discount1 = (doc.disc_percent1/100.0)*doc.total; 
	cur_frm.set_value("disc_amount1",discount1);  
}

//DISCOUNT 2
cur_frm.cscript.custom_disc_amount1 = function(doc){
	new_total = doc.total - doc.disc_amount1;
	cur_frm.set_value("total2",new_total);  
	total_disc1 = doc.disc_amount1 + doc.disc_amount2 + doc.disc_amount3;
	cur_frm.set_value("discount_amount",total_disc1);
}
cur_frm.cscript.custom_disc_percent2 = function(doc){
	discount2 = (doc.disc_percent2/100.0)*doc.total2; 
	cur_frm.set_value("disc_amount2",discount2);  
}


//DISCOUNT 3

cur_frm.cscript.custom_disc_amount2 = function(doc){
	new_total = doc.total2 - doc.disc_amount2;
	cur_frm.set_value("total3",new_total);  
	total_disc2 = doc.disc_amount1 + doc.disc_amount2 + doc.disc_amount3;
	cur_frm.set_value("discount_amount",total_disc2);
}
cur_frm.cscript.custom_disc_percent3 = function(doc){
	discount3 = (doc.disc_percent3/100.0)*doc.total3; 
	cur_frm.set_value("disc_amount3",discount3);  
}

//total discount
cur_frm.cscript.custom_disc_amount3 = function(doc){
	total_disc = doc.disc_amount1 + doc.disc_amount2 + doc.disc_amount3;
	cur_frm.set_value("discount_amount",total_disc); 
}
3 Likes

how can i use the standard functions like calculate_discount_amount on custom field as you have mentioned disc_amount2

this functions are available in cscript but I want to understand how can i apply the same.

When we change the discount_amount field automatically all the calculations get triggered, so i also want the same recalculation to be triggered on custom discount field named as apply credits or disc_amount2

Please Help!

ok i will help you do you have team viewer or any software for viewing your desktop to demonstrate how to do that.

Pricing rule can be helpful but there is only one discount per item code / item group / customer. You can set priority but it will span accross tem code / item group / customer not on same item code. It will be overriden by one discount.

Other customizations like ones mentioned in above posts can be done. But manipulating the way in which we calculate discounts and taxes. (a core JS and Python function in erpnext). But a word of caution there, doing this will have issues when you update your code with ERPNext version.

Better option is to submit a feature in core and then use it.

hello ,

please i have same issue to use many discount on item price , can you help with any guide how to apply it …