[fix] Tax calculation while discount applied on net total
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 6b59cea..d526f66 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -219,7 +219,7 @@
 
 					# adjust Discount Amount loss in last tax iteration
 					if i == (len(self.doc.get("taxes")) - 1) and self.discount_amount_applied \
-						and self.doc.discount_amount:
+						and self.doc.discount_amount and self.doc.apply_discount_on == "Grand Total":
 							self.adjust_discount_amount_loss(tax)
 
 
@@ -303,9 +303,9 @@
 			for tax in self.doc.get("taxes"):
 				if tax.category in ["Valuation and Total", "Total"]:
 					if tax.add_deduct_tax == "Add":
-						self.doc.taxes_and_charges_added += flt(tax.tax_amount)
+						self.doc.taxes_and_charges_added += flt(tax.tax_amount_after_discount_amount)
 					else:
-						self.doc.taxes_and_charges_deducted += flt(tax.tax_amount)
+						self.doc.taxes_and_charges_deducted += flt(tax.tax_amount_after_discount_amount)
 
 			self.doc.round_floats_in(self.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"])
 
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 1e238d6..0b3ca7f 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -256,7 +256,8 @@
 					me.round_off_totals(tax);
 
 					// adjust Discount Amount loss in last tax iteration
-					if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied && me.frm.doc.apply_discount_on == "Grand Total")
+					if ((i == me.frm.doc["taxes"].length - 1) && me.discount_amount_applied 
+							&& me.frm.doc.apply_discount_on == "Grand Total" && me.frm.doc.discount_amount)
 						me.adjust_discount_amount_loss(tax);
 				}
 			});
@@ -365,9 +366,9 @@
 				$.each(this.frm.doc["taxes"] || [], function(i, tax) {
 					if (in_list(["Valuation and Total", "Total"], tax.category)) {
 						if(tax.add_deduct_tax == "Add") {
-							me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount);
+							me.frm.doc.taxes_and_charges_added += flt(tax.tax_amount_after_discount_amount);
 						} else {
-							me.frm.doc.taxes_and_charges_deducted += flt(tax.tax_amount);
+							me.frm.doc.taxes_and_charges_deducted += flt(tax.tax_amount_after_discount_amount);
 						}
 					}
 				})