Fixes for discount amount
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index 7d19fde..640bcea 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -76,7 +76,7 @@
 				"tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
 
-			if not self.discount_amount_applied:
+			if tax.charge_type != "Actual" and not self.discount_amount_applied:
 				tax_fields.append("tax_amount")
 
 			for fieldname in tax_fields:
@@ -214,14 +214,15 @@
 					if n == len(self.doc.get("items")) - 1:
 						current_tax_amount += actual_tax_dict[tax.idx]
 
+				# accumulate tax amount into tax.tax_amount
+				if tax.charge_type != "Actual" and not self.discount_amount_applied:
+					tax.tax_amount += current_tax_amount
+
 				# store tax_amount for current item as it will be used for
 				# charge type = 'On Previous Row Amount'
 				tax.tax_amount_for_current_item = current_tax_amount
 
-				# accumulate tax amount into tax.tax_amount
-				if not self.discount_amount_applied:
-					tax.tax_amount += current_tax_amount
-
+				# set tax after discount
 				tax.tax_amount_after_discount_amount += current_tax_amount
 
 				if getattr(tax, "category", None):
diff --git a/erpnext/patches/v4_0/set_naming_series_property_setter.py b/erpnext/patches/v4_0/set_naming_series_property_setter.py
index bd4ed91..ff241ae 100644
--- a/erpnext/patches/v4_0/set_naming_series_property_setter.py
+++ b/erpnext/patches/v4_0/set_naming_series_property_setter.py
@@ -35,7 +35,6 @@
 def execute():
 	series_to_set = get_series_to_set()
 	for doctype, opts in series_to_set.items():
-		print "Setting naming series", doctype, opts
 		set_series(doctype, opts["options"], opts["default"])
 
 def set_series(doctype, options, default):
diff --git a/erpnext/public/js/controllers/accounts.js b/erpnext/public/js/controllers/accounts.js
index 4b15811..652350a 100644
--- a/erpnext/public/js/controllers/accounts.js
+++ b/erpnext/public/js/controllers/accounts.js
@@ -1,10 +1,6 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-frappe.ui.form.on(cur_frm.doctype, "refresh", function(frm) {
-	frm.set_footnote(frappe.markdown(frm.meta.description));
-}
-
 // get tax rate
 cur_frm.cscript.account_head = function(doc, cdt, cdn) {
 	var d = locals[cdt][cdn];
@@ -28,8 +24,8 @@
 	var d = locals[cdt][cdn];
 	if(!d.charge_type && (d.row_id || d.rate || d.tax_amount)) {
 		msgprint(__("Please select Charge Type first"));
-		d.row_id = ""
-		d.rate = d.tax_amount = 0.0
+		d.row_id = "";
+		d.rate = d.tax_amount = 0.0;
 	} else if((d.charge_type == 'Actual' || d.charge_type == 'On Net Total') && d.row_id) {
 		msgprint(__("Can refer row only if the charge type is 'On Previous Row Amount' or 'Previous Row Total'"));
 		d.row_id = "";
@@ -48,19 +44,19 @@
 
 frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
 	validate_taxes_and_charges(cdt, cdn);
-})
+});
 
 frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
 	validate_taxes_and_charges(cdt, cdn);
-})
+});
 
 frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
 	validate_taxes_and_charges(cdt, cdn);
-})
+});
 
 frappe.ui.form.on(cur_frm.cscript.tax_table, "charge_type", function(frm, cdt, cdn) {
 	validate_taxes_and_charges(cdt, cdn);
-})
+});
 
 
 cur_frm.set_query("account_head", "taxes", function(doc) {
@@ -86,7 +82,7 @@
 			'group_or_ledger': "Ledger"
 		}
 	}
-}
+});
 
 // For customizing print
 cur_frm.pformat.print_total = function(doc) { return ''; }
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index f5307c7..e30099c 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -88,7 +88,7 @@
 				"tax_amount_for_current_item", "grand_total_for_current_item",
 				"tax_fraction_for_current_item", "grand_total_fraction_for_current_item"]
 
-			if (!me.discount_amount_applied)
+			if (cstr(tax.charge_type) != "Actual" && !me.discount_amount_applied)
 				tax_fields.push("tax_amount");
 
 			$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
@@ -216,14 +216,15 @@
 					}
 				}
 
+				// accumulate tax amount into tax.tax_amount
+				if (tax.charge_type != "Actual" && !me.discount_amount_applied)
+					tax.tax_amount += current_tax_amount;
+
 				// store tax_amount for current item as it will be used for
 				// charge type = 'On Previous Row Amount'
 				tax.tax_amount_for_current_item = current_tax_amount;
 
-				// accumulate tax amount into tax.tax_amount
-				if (!me.discount_amount_applied)
-					tax.tax_amount += current_tax_amount;
-
+				// tax amount after discount amount
 				tax.tax_amount_after_discount_amount += current_tax_amount;
 
 				// for buying
@@ -239,7 +240,7 @@
 				// note: grand_total_for_current_item contains the contribution of
 				// item's amount, previously applied tax and the current tax on that item
 				if(i==0) {
-					tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount);
+					tax.grand_total_for_current_item = flt(item.net_amount + current_tax_amount);
 				} else {
 					tax.grand_total_for_current_item =
 						flt(me.frm.doc["taxes"][i-1].grand_total_for_current_item + current_tax_amount);
@@ -313,7 +314,7 @@
 	},
 
 	adjust_discount_amount_loss: function(tax) {
-		var discount_amount_loss = this.frm.doc.base_grand_total - flt(this.frm.doc.base_discount_amount) - tax.total;
+		var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total;
 		tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount +
 			discount_amount_loss, precision("tax_amount", tax));
 		tax.total = flt(tax.total + discount_amount_loss, precision("total", tax));
@@ -326,7 +327,7 @@
 		this.frm.doc.grand_total = flt(tax_count ? this.frm.doc["taxes"][tax_count - 1].total : this.frm.doc.net_total);
 
 		if(in_list(["Quotation", "Sales Order", "Delivery Note", "Sales Invoice"], this.frm.doc.doctype)) {
-			this.frm.doc.base_grand_total = (this.frm.doc.base_total_taxes_and_charges) ?
+			this.frm.doc.base_grand_total = (this.frm.doc.total_taxes_and_charges) ?
 				flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total;
 		} else {
 			// other charges added/deducted
@@ -345,7 +346,7 @@
 				frappe.model.round_floats_in(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
 			}
 
-			this.frm.doc.grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
+			this.frm.doc.base_grand_total = flt((this.frm.doc.taxes_and_charges_added || this.frm.doc.taxes_and_charges_deducted) ?
 				flt(this.frm.doc.grand_total * this.frm.doc.conversion_rate) : this.frm.doc.base_net_total);
 
 			this.set_in_company_currency(this.frm.doc, ["taxes_and_charges_added", "taxes_and_charges_deducted"]);
@@ -354,6 +355,8 @@
 		this.frm.doc.total_taxes_and_charges = flt(this.frm.doc.grand_total - this.frm.doc.net_total,
 			precision("total_taxes_and_charges"));
 
+		this.set_in_company_currency(this.frm.doc, ["total_taxes_and_charges"]);
+
 		// Round grand total as per precision
 		frappe.model.round_floats_in(this.frm.doc, ["grand_total", "base_grand_total"]);
 
@@ -408,7 +411,7 @@
 			if (total_for_discount_amount) {
 				$.each(this.frm.doc["items"] || [], function(i, item) {
 					distributed_amount = flt(me.frm.doc.discount_amount) * item.net_amount / total_for_discount_amount;
-					item.base_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
+					item.net_amount = flt(item.net_amount - distributed_amount, precision("base_amount", item));
 					item.net_rate = flt(item.net_amount / item.qty, precision("net_rate", item));
 
 					me.set_in_company_currency(item, ["net_rate", "net_amount"]);
@@ -441,8 +444,7 @@
 			});
 
 			$.each(actual_taxes_dict, function(key, value) {
-				if (value)
-					total_actual_tax += value;
+				if (value) total_actual_tax += value;
 			});
 
 			return flt(this.frm.doc.grand_total - total_actual_tax, precision("grand_total"));
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index 570c16a..c63939d 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -151,6 +151,7 @@
 		})
 	});
 	dialog.show();
+
 }
 
 cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
diff --git a/erpnext/setup/doctype/company/test_company.py b/erpnext/setup/doctype/company/test_company.py
index 06db121..32d0b0e 100644
--- a/erpnext/setup/doctype/company/test_company.py
+++ b/erpnext/setup/doctype/company/test_company.py
@@ -8,11 +8,8 @@
 
 class TestCompany(unittest.TestCase):
 	def atest_coa(self):
-		for country, chart_name in frappe.db.sql("""select country, chart_name 
+		for country, chart_name in frappe.db.sql("""select country, chart_name
 			from `tabChart of Accounts` where name = 'Deutscher Kontenplan SKR03'""", as_list=1):
-				print "Country: ", country
-				print "Chart Name: ", chart_name
-				
 				company_doc = frappe.get_doc({
 					"doctype": "Company",
 					"company_name": "_Test Company 2",
@@ -23,10 +20,10 @@
 				})
 
 				company_doc.insert()
-				self.assertTrue(frappe.db.sql("""select count(*) from tabAccount 
+				self.assertTrue(frappe.db.sql("""select count(*) from tabAccount
 					where company='_Test Company 2'""")[0][0] > 10)
-				
-				frappe.delete_doc("Company", "_Test Company 2")
-		
 
-test_records = frappe.get_test_records('Company')
\ No newline at end of file
+				frappe.delete_doc("Company", "_Test Company 2")
+
+
+test_records = frappe.get_test_records('Company')