Merge pull request #12347 from pratu16x7/buying-fix

[minor][buying] fix schedule date check
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index d871cd5..85ad436 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -5,7 +5,7 @@
 from erpnext.hooks import regional_overrides
 from frappe.utils import getdate
 
-__version__ = '10.0.5'
+__version__ = '10.0.6'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 36f8ce2..b3d1d55 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -53,14 +53,12 @@
 	def set_root_and_report_type(self):
 		if self.parent_account:
 			par = frappe.db.get_value("Account", self.parent_account,
-				["report_type", "root_type", "account_type"], as_dict=1)
+				["report_type", "root_type"], as_dict=1)
 
 			if par.report_type:
 				self.report_type = par.report_type
 			if par.root_type:
 				self.root_type = par.root_type
-			if par.account_type and not self.account_type:
-				self.account_type = par.account_type
 
 		if self.is_group:
 			db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1)
@@ -171,10 +169,10 @@
 		# Add company abbr if not provided
 		from erpnext.setup.doctype.company.company import get_name_with_abbr
 		new_account = get_name_with_abbr(new, self.company)
-		new_account = get_name_with_number(new_account, self.account_number)
-
-		# Validate properties before merging
-		if merge:
+		if not merge:
+			new_account = get_name_with_number(new_account, self.account_number)
+		else:
+			# Validate properties before merging
 			if not frappe.db.exists("Account", new):
 				throw(_("Account {0} does not exist").format(new))
 
diff --git a/erpnext/accounts/doctype/pos_profile/pos_profile.json b/erpnext/accounts/doctype/pos_profile/pos_profile.json
index e2a6b53..2cb8e10 100644
--- a/erpnext/accounts/doctype/pos_profile/pos_profile.json
+++ b/erpnext/accounts/doctype/pos_profile/pos_profile.json
@@ -130,7 +130,7 @@
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
-   "set_only_once": 1, 
+   "set_only_once": 0, 
    "unique": 0
   }, 
   {
@@ -1476,7 +1476,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-11 17:30:45.198147", 
+ "modified": "2018-01-03 17:30:45.198147", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "POS Profile", 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 07853d0..3f9bca7 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -350,7 +350,6 @@
 		self.negative_expense_to_be_booked = 0.0
 		gl_entries = []
 
-
 		self.make_supplier_gl_entry(gl_entries)
 		self.make_item_gl_entries(gl_entries)
 		self.make_tax_gl_entries(gl_entries)
@@ -424,7 +423,10 @@
 
 					# sub-contracting warehouse
 					if flt(item.rm_supp_cost):
-						supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["name"]
+						supplier_warehouse_account = warehouse_account[self.supplier_warehouse]["account"]
+						if not supplier_warehouse_account:
+							frappe.throw(_("Please set account in Warehouse {0}")
+								.format(self.supplier_warehouse))
 						gl_entries.append(self.get_gl_dict({
 							"account": supplier_warehouse_account,
 							"against": item.expense_account,
diff --git a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.js
index db71a17..8fac32d 100644
--- a/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/test_purchase_invoice.js
@@ -18,7 +18,7 @@
 				{update_stock:1},
 				{supplier_address: 'Test1-Billing'},
 				{contact_person: 'Contact 3-Test Supplier'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'},
 				{payment_terms_template: '_Test Payment Term Template UI'}
@@ -29,7 +29,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 			// grand_total Calculated
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
index bffa8e6..bd66aa5 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/purchase_taxes_and_charges_template.py
@@ -3,6 +3,7 @@
 # License: GNU General Public License v3. See license.txt
 
 from __future__ import unicode_literals
+import frappe
 from frappe.model.document import Document
 from erpnext.accounts.doctype.sales_taxes_and_charges_template.sales_taxes_and_charges_template \
 	import valdiate_taxes_and_charges_template
@@ -10,3 +11,8 @@
 class PurchaseTaxesandChargesTemplate(Document):
 	def validate(self):
 		valdiate_taxes_and_charges_template(self)
+
+	def autoname(self):
+		if self.company and self.title:
+			abbr = frappe.db.get_value('Company', self.company, 'abbr')
+			self.name = '{0} - {1}'.format(self.title, abbr)
diff --git a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.js b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.js
index 5e357ca..c73f03b 100644
--- a/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.js
+++ b/erpnext/accounts/doctype/purchase_taxes_and_charges_template/test_purchase_taxes_and_charges_template.js
@@ -1,7 +1,7 @@
 QUnit.module('Sales Taxes and Charges Template');
 
 QUnit.test("test sales taxes and charges template", function(assert) {
-	assert.expect(1);
+	assert.expect(2);
 	let done = assert.async();
 	frappe.run_serially([
 		() => {
@@ -19,7 +19,10 @@
 				]}
 			]);
 		},
-		() => {assert.ok(cur_frm.doc.title=='TEST In State GST');},
+		() => {
+			assert.ok(cur_frm.doc.title=='TEST In State GST');
+			assert.ok(cur_frm.doc.name=='TEST In State GST - FT');
+		},
 		() => done()
 	]);
 });
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js
index b4be3ba..0c92c37 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'},
 				{payment_terms_template: '_Test Payment Term Template UI'}
@@ -28,7 +28,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 			// grand_total Calculated
diff --git a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice.js b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice.js
index 35b2558..e12ac03 100644
--- a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice.js
+++ b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 			// grand_total Calculated
diff --git a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment.js b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment.js
index 890fb68..651bf0a 100644
--- a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment.js
+++ b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'},
 				{payment_terms_template: '_Test Payment Term Template UI'}
@@ -28,7 +28,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// grand_total Calculated
 			assert.ok(cur_frm.doc.grand_total==590, "Grad Total correct");
 
diff --git a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment_request.js b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment_request.js
index 7abfb41..b959cf9 100644
--- a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment_request.js
+++ b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_payment_request.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// grand_total Calculated
 			assert.ok(cur_frm.doc.grand_total==590, "Grad Total correct");
 
diff --git a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js
index 6005984..2697758 100644
--- a/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js
+++ b/erpnext/accounts/doctype/sales_invoice/tests/test_sales_invoice_with_serialize_item.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 4', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 			// get batch number
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
index 3947450..9dee1f9 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/sales_taxes_and_charges_template.py
@@ -11,7 +11,12 @@
 class SalesTaxesandChargesTemplate(Document):
 	def validate(self):
 		valdiate_taxes_and_charges_template(self)
-		
+
+	def autoname(self):
+		if self.company and self.title:
+			abbr = frappe.db.get_value('Company', self.company, 'abbr')
+			self.name = '{0} - {1}'.format(self.title, abbr)
+
 	def set_missing_values(self):
 		for data in self.taxes:
 			if data.charge_type == 'On Net Total' and flt(data.rate) == 0.0:
diff --git a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.js b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.js
index 2667ee6..d02e70b 100644
--- a/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.js
+++ b/erpnext/accounts/doctype/sales_taxes_and_charges_template/test_sales_taxes_and_charges_template.js
@@ -1,7 +1,7 @@
 QUnit.module('Sales Taxes and Charges Template');
 
 QUnit.test("test sales taxes and charges template", function(assert) {
-	assert.expect(1);
+	assert.expect(2);
 	let done = assert.async();
 	frappe.run_serially([
 		() => {
@@ -19,7 +19,10 @@
 				]}
 			]);
 		},
-		() => {assert.ok(cur_frm.doc.title=='TEST In State GST');},
+		() => {
+			assert.ok(cur_frm.doc.title=='TEST In State GST');
+			assert.ok(cur_frm.doc.name=='TEST In State GST - FT');
+		},
 		() => done()
 	]);
 });
diff --git a/erpnext/accounts/doctype/tax_rule/test_records.json b/erpnext/accounts/doctype/tax_rule/test_records.json
index 0913fba..e80b12f 100644
--- a/erpnext/accounts/doctype/tax_rule/test_records.json
+++ b/erpnext/accounts/doctype/tax_rule/test_records.json
@@ -2,7 +2,7 @@
 	{
 		"doctype": "Tax Rule",
 		"tax_type" : "Sales",
-		"sales_tax_template": "_Test Tax 1",
+		"sales_tax_template": "_Test Tax 1 - _TC",
 		"use_for_shopping_cart": 1,
 		"billing_city": "_Test City",
 		"billing_state": "Test State",
@@ -15,7 +15,7 @@
 	{
 		"doctype": "Tax Rule",
 		"tax_type" : "Sales",
-		"sales_tax_template": "_Test Tax 2",
+		"sales_tax_template": "_Test Tax 2 - _TC",
 		"use_for_shopping_cart": 0,
 		"billing_city": "_Test City",
 		"billing_country": "India",
diff --git a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py
index ee5b3c9..54a7520 100644
--- a/erpnext/accounts/doctype/tax_rule/test_tax_rule.py
+++ b/erpnext/accounts/doctype/tax_rule/test_tax_rule.py
@@ -18,40 +18,40 @@
 
 	def test_conflict(self):
 		tax_rule1 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1)
 		tax_rule1.save()
 
 		tax_rule2 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1)
 
 		self.assertRaises(ConflictingTaxRule, tax_rule2.save)
 
 	def test_conflict_with_non_overlapping_dates(self):
 		tax_rule1 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1, from_date = "2015-01-01")
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01")
 		tax_rule1.save()
 
 		tax_rule2 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1, to_date = "2013-01-01")
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, to_date = "2013-01-01")
 
 		tax_rule2.save()
 		self.assertTrue(tax_rule2.name)
 
 	def test_for_parent_customer_group(self):
 		tax_rule1 = make_tax_rule(customer_group= "All Customer Groups",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1, from_date = "2015-01-01")
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01")
 		tax_rule1.save()
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer_group" : "Commercial", "use_for_shopping_cart":0}),
-			"_Test Sales Taxes and Charges Template")
+			"_Test Sales Taxes and Charges Template - _TC")
 
 	def test_conflict_with_overlapping_dates(self):
 		tax_rule1 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1, from_date = "2015-01-01", to_date = "2015-01-05")
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-01", to_date = "2015-01-05")
 		tax_rule1.save()
 
 		tax_rule2 = make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority = 1, from_date = "2015-01-03", to_date = "2015-01-09")
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority = 1, from_date = "2015-01-03", to_date = "2015-01-09")
 
 		self.assertRaises(ConflictingTaxRule, tax_rule2.save)
 
@@ -62,66 +62,66 @@
 
 	def test_select_tax_rule_based_on_customer(self):
 		make_tax_rule(customer= "_Test Customer",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)
 
 		make_tax_rule(customer= "_Test Customer 1",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)
 
 		make_tax_rule(customer= "_Test Customer 2",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 2", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 2 - _TC", save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer 2"}),
-			"_Test Sales Taxes and Charges Template 2")
+			"_Test Sales Taxes and Charges Template 2 - _TC")
 
 	def test_select_tax_rule_based_on_better_match(self):
 		make_tax_rule(customer= "_Test Customer", billing_city = "Test City", billing_state = "Test State",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)
 
 		make_tax_rule(customer= "_Test Customer",  billing_city = "Test City1", billing_state = "Test State",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City", "billing_state": "Test State"}),
-			"_Test Sales Taxes and Charges Template")
+			"_Test Sales Taxes and Charges Template - _TC")
 
 	def test_select_tax_rule_based_on_state_match(self):
 		make_tax_rule(customer= "_Test Customer", shipping_state = "Test State",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)
 
 		make_tax_rule(customer= "_Test Customer", shipping_state = "Test State12",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", priority=2, save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", priority=2, save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "shipping_state": "Test State"}),
-			"_Test Sales Taxes and Charges Template")
+			"_Test Sales Taxes and Charges Template - _TC")
 
 	def test_select_tax_rule_based_on_better_priority(self):
 		make_tax_rule(customer= "_Test Customer", billing_city = "Test City",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", priority=1, save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", priority=1, save=1)
 
 		make_tax_rule(customer= "_Test Customer", billing_city = "Test City",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", priority=2, save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", priority=2, save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City"}),
-			"_Test Sales Taxes and Charges Template 1")
+			"_Test Sales Taxes and Charges Template 1 - _TC")
 
 	def test_select_tax_rule_based_cross_matching_keys(self):
 		make_tax_rule(customer= "_Test Customer", billing_city = "Test City",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)
 
 		make_tax_rule(customer= "_Test Customer 1", billing_city = "Test City 1",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City 1"}),
 			None)
 
 	def test_select_tax_rule_based_cross_partially_keys(self):
 		make_tax_rule(customer= "_Test Customer", billing_city = "Test City",
-			sales_tax_template = "_Test Sales Taxes and Charges Template", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template - _TC", save=1)
 
 		make_tax_rule(billing_city = "Test City 1",
-			sales_tax_template = "_Test Sales Taxes and Charges Template 1", save=1)
+			sales_tax_template = "_Test Sales Taxes and Charges Template 1 - _TC", save=1)
 
 		self.assertEquals(get_tax_template("2015-01-01", {"customer":"_Test Customer", "billing_city": "Test City 1"}),
-			"_Test Sales Taxes and Charges Template 1")
+			"_Test Sales Taxes and Charges Template 1 - _TC")
 
 
 def make_tax_rule(**args):
diff --git a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
index 205d43f..ab5251f 100644
--- a/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
+++ b/erpnext/accounts/report/item_wise_sales_register/item_wise_sales_register.py
@@ -6,6 +6,7 @@
 from frappe import _
 from frappe.utils import flt
 from frappe.model.meta import get_field_precision
+from frappe.utils.xlsxutils import handle_html
 from erpnext.accounts.report.sales_register.sales_register import get_mode_of_payments
 
 def execute(filters=None):
@@ -188,10 +189,10 @@
 		tuple([doctype] + invoice_item_row.keys()))
 
 	for parent, description, item_wise_tax_detail, charge_type, tax_amount in tax_details:
+		description = handle_html(description)
 		if description not in tax_columns and tax_amount:
 			# as description is text editor earlier and markup can break the column convention in reports
-			from frappe.utils.xlsxutils import handle_html
-			tax_columns.append(handle_html(description))
+			tax_columns.append(description)
 
 		if item_wise_tax_detail:
 			try:
diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
index 93c0308..f38f28d 100644
--- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
+++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
@@ -66,12 +66,12 @@
 	invoice_list = get_invoices(filters)
 	invoice_list_names = ",".join(['"' + invoice['name'] + '"' for invoice in invoice_list])
 	if invoice_list:
-		inv_mop = frappe.db.sql("""select a.owner,a.posting_date, ifnull(b.mode_of_payment, '')
+		inv_mop = frappe.db.sql("""select a.owner,a.posting_date, ifnull(b.mode_of_payment, '') as mode_of_payment
 			from `tabSales Invoice` a, `tabSales Invoice Payment` b
 			where a.name = b.parent
 			and a.name in ({invoice_list_names})
 			union
-			select a.owner,a.posting_date, ifnull(b.mode_of_payment, '')
+			select a.owner,a.posting_date, ifnull(b.mode_of_payment, '') as mode_of_payment
 			from `tabSales Invoice` a, `tabPayment Entry` b,`tabPayment Entry Reference` c
 			where a.name = c.reference_name 
 			and b.name = c.parent
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 0394f74..ef59cd8 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -12,6 +12,15 @@
 			'Purchase Invoice': 'Invoice',
 			'Stock Entry': 'Material to Supplier'
 		}
+		
+		frm.set_query("reserve_warehouse", "supplied_items", function() {
+			return {
+				filters: {
+					"company": frm.doc.company,
+					"is_group": 0
+				}
+			}
+		});
 	},
 
 	onload: function(frm) {
@@ -289,7 +298,8 @@
 		filters: [
 			['BOM', 'item', '=', d.item_code],
 			['BOM', 'is_active', '=', '1'],
-			['BOM', 'docstatus', '=', '1']
+			['BOM', 'docstatus', '=', '1'],
+			['BOM', 'company', '=', doc.company]
 		]
 	}
 }
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.json b/erpnext/buying/doctype/purchase_order/purchase_order.json
index 2191a55..2325a8c 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -3071,6 +3071,38 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:doc.is_subcontracted", 
+   "fieldname": "supplied_items_section", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Supplied Items", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "", 
    "fieldname": "supplied_items", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -3261,8 +3293,8 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-19 14:53:03.986840", 
- "modified_by": "nabinhait@gmail.com", 
+ "modified": "2018-01-05 14:44:56.132189", 
+ "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order", 
  "owner": "Administrator", 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.py b/erpnext/buying/doctype/purchase_order/purchase_order.py
index df65ef9..c6e21ad 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.py
@@ -12,7 +12,7 @@
 from erpnext.stock.stock_balance import update_bin_qty, get_ordered_qty
 from frappe.desk.notifications import clear_doctype_notifications
 from erpnext.buying.utils import validate_for_items, check_for_closed_status
-
+from erpnext.stock.utils import get_bin
 
 form_grid_templates = {
 	"items": "templates/form_grid/item_grid.html"
@@ -71,8 +71,10 @@
 	def validate_supplier(self):
 		prevent_po = frappe.db.get_value("Supplier", self.supplier, 'prevent_pos')
 		if prevent_po:
-			standing = frappe.db.get_value("Supplier Scorecard",self.supplier, 'status')
-			frappe.throw(_("Purchase Orders are not allowed for {0} due to a scorecard standing of {1}.").format(self.supplier, standing))
+			standing = frappe.db.get_value("Supplier Scorecard", self.supplier, 'status')
+			if standing:
+				frappe.throw(_("Purchase Orders are not allowed for {0} due to a scorecard standing of {1}.")
+					.format(self.supplier, standing))
 
 		warn_po = frappe.db.get_value("Supplier", self.supplier, 'warn_pos')
 		if warn_po:
@@ -184,6 +186,9 @@
 		self.set_status(update=True, status=status)
 		self.update_requested_qty()
 		self.update_ordered_qty()
+		if self.is_subcontracted == "Yes":
+			self.update_reserved_qty_for_subcontract()
+
 		self.notify_update()
 		clear_doctype_notifications(self)
 
@@ -196,6 +201,8 @@
 		self.update_prevdoc_status()
 		self.update_requested_qty()
 		self.update_ordered_qty()
+		if self.is_subcontracted == "Yes":
+			self.update_reserved_qty_for_subcontract()
 
 		frappe.get_doc('Authorization Control').validate_approving_authority(self.doctype,
 			self.company, self.base_grand_total)
@@ -209,6 +216,9 @@
 		if self.has_drop_ship_item():
 			self.update_delivered_qty_in_sales_order()
 
+		if self.is_subcontracted == "Yes":
+			self.update_reserved_qty_for_subcontract()
+
 		self.check_for_closed_status()
 
 		frappe.db.set(self,'status','Cancelled')
@@ -256,6 +266,12 @@
 			if item.delivered_by_supplier == 1:
 				item.received_qty = item.qty
 
+	def update_reserved_qty_for_subcontract(self):
+		for d in self.supplied_items:
+			if d.rm_item_code:
+				stock_bin = get_bin(d.rm_item_code, d.reserve_warehouse)
+				stock_bin.update_reserved_qty_for_sub_contracting()
+
 @frappe.whitelist()
 def close_or_unclose_purchase_orders(names, status):
 	if not frappe.has_permission("Purchase Order", "write"):
diff --git a/erpnext/buying/doctype/purchase_order/test_purchase_order.py b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
index d31b230..5ae4d3b 100644
--- a/erpnext/buying/doctype/purchase_order/test_purchase_order.py
+++ b/erpnext/buying/doctype/purchase_order/test_purchase_order.py
@@ -6,8 +6,8 @@
 import frappe
 import frappe.defaults
 from frappe.utils import flt, add_days, nowdate
-from erpnext.buying.doctype.purchase_order.purchase_order import make_purchase_receipt, make_purchase_invoice
-
+from erpnext.buying.doctype.purchase_order.purchase_order import (make_purchase_receipt, make_purchase_invoice, make_stock_entry as make_subcontract_transfer_entry)
+from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
 
 class TestPurchaseOrder(unittest.TestCase):
 	def test_make_purchase_receipt(self):
@@ -182,24 +182,129 @@
 		pi.insert()
 		self.assertTrue(pi.get('payment_schedule'))
 
-		
+	def test_reserved_qty_subcontract_po(self):
+		# Make stock available for raw materials
+		make_stock_entry(target="_Test Warehouse - _TC", qty=10, basic_rate=100)
+		make_stock_entry(target="_Test Warehouse - _TC", item_code="_Test Item Home Desktop 100",
+			qty=20, basic_rate=100)
+
+		bin1 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname=["reserved_qty_for_sub_contract", "projected_qty"], as_dict=1)
+
+		# Submit PO
+		po = create_purchase_order(item_code="_Test FG Item", is_subcontracted="Yes")
+
+		bin2 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname=["reserved_qty_for_sub_contract", "projected_qty"], as_dict=1)
+		self.assertEquals(bin2.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract + 10)
+		self.assertEquals(bin2.projected_qty, bin1.projected_qty - 10)
+
+		# Create stock transfer
+		se = frappe.get_doc(make_subcontract_transfer_entry(po.name, "_Test FG Item"))
+		se.to_warehouse = "_Test Warehouse 1 - _TC"
+		for d in se.get("items"):
+			if d.item_code == "_Test Item":
+				d.qty = 6
+		se.save()
+		se.submit()
+
+		bin3 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin3.reserved_qty_for_sub_contract, bin2.reserved_qty_for_sub_contract - 6)
+
+		# close PO
+		po.update_status("Closed")
+		bin4 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin4.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract)
+
+		# Re-open PO
+		po.update_status("Submitted")
+		bin5 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin5.reserved_qty_for_sub_contract, bin2.reserved_qty_for_sub_contract - 6)
+
+		# make Purchase Receipt against PO
+		pr = make_purchase_receipt(po.name)
+		pr.supplier_warehouse = "_Test Warehouse 1 - _TC"
+		pr.save()
+		pr.submit()
+
+		bin6 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin6.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract)
+
+		# Cancel PR
+		pr.cancel()
+		bin7 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin7.reserved_qty_for_sub_contract, bin2.reserved_qty_for_sub_contract - 6)
+
+		# Make Purchase Invoice
+		pi = make_purchase_invoice(po.name)
+		pi.update_stock = 1
+		pi.supplier_warehouse = "_Test Warehouse 1 - _TC"
+		pi.insert()
+		pi.submit()
+		bin8 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin8.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract)
+
+		# Cancel PR
+		pi.cancel()
+		bin9 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin9.reserved_qty_for_sub_contract, bin2.reserved_qty_for_sub_contract - 6)
+
+		# Cancel Stock Entry
+		se.cancel()
+		bin10 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+		self.assertEquals(bin10.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract + 10)
+
+		# Cancel PO
+		po.reload()
+		po.cancel()
+		bin11 = frappe.db.get_value("Bin",
+			filters={"warehouse": "_Test Warehouse - _TC", "item_code": "_Test Item"},
+			fieldname="reserved_qty_for_sub_contract", as_dict=1)
+
+		self.assertEquals(bin11.reserved_qty_for_sub_contract, bin1.reserved_qty_for_sub_contract)
+
 def get_same_items():
 	return [
-				{
-					"item_code": "_Test FG Item",
-					"warehouse": "_Test Warehouse - _TC",
-					"qty": 1,
-					"rate": 500,
-					"schedule_date": add_days(nowdate(), 1)
-				},
-				{
-					"item_code": "_Test FG Item",
-					"warehouse": "_Test Warehouse - _TC",
-					"qty": 4,
-					"rate": 500,
-					"schedule_date": add_days(nowdate(), 1)
-				}
-			]		
+		{
+			"item_code": "_Test FG Item",
+			"warehouse": "_Test Warehouse - _TC",
+			"qty": 1,
+			"rate": 500,
+			"schedule_date": add_days(nowdate(), 1)
+		},
+		{
+			"item_code": "_Test FG Item",
+			"warehouse": "_Test Warehouse - _TC",
+			"qty": 4,
+			"rate": 500,
+			"schedule_date": add_days(nowdate(), 1)
+		}
+	]
 
 def create_purchase_order(**args):
 	po = frappe.new_doc("Purchase Order")
@@ -224,6 +329,10 @@
 	if not args.do_not_save:
 		po.insert()
 		if not args.do_not_submit:
+			if po.is_subcontracted == "Yes":
+				supp_items = po.get("supplied_items")
+				for d in supp_items:
+					d.reserve_warehouse = args.warehouse or "_Test Warehouse - _TC"
 			po.submit()
 
 	return po
diff --git a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
index 27129fb..39716ed 100644
--- a/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
+++ b/erpnext/buying/doctype/purchase_order/tests/test_purchase_order_with_taxes_and_charges.js
@@ -24,7 +24,7 @@
 					]
 				]},
 
-				{taxes_and_charges: 'TEST In State GST'}
+				{taxes_and_charges: 'TEST In State GST - FT'}
 			]);
 		},
 
diff --git a/erpnext/buying/doctype/purchase_order_item_supplied/purchase_order_item_supplied.json b/erpnext/buying/doctype/purchase_order_item_supplied/purchase_order_item_supplied.json
index 4a87037..d4a02fb 100644
--- a/erpnext/buying/doctype/purchase_order_item_supplied/purchase_order_item_supplied.json
+++ b/erpnext/buying/doctype/purchase_order_item_supplied/purchase_order_item_supplied.json
@@ -1,5 +1,6 @@
 {
  "allow_copy": 0, 
+ "allow_guest_to_view": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
  "beta": 0, 
@@ -10,16 +11,20 @@
  "editable_grid": 1, 
  "fields": [
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 2, 
    "fieldname": "main_item_code", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Item Code", 
    "length": 0, 
    "no_copy": 0, 
@@ -29,6 +34,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -36,16 +42,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 2, 
    "fieldname": "rm_item_code", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Raw Material Item Code", 
    "length": 0, 
    "no_copy": 0, 
@@ -55,6 +65,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -62,16 +73,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 2, 
    "fieldname": "required_qty", 
    "fieldtype": "Float", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Supplied Qty", 
    "length": 0, 
    "no_copy": 0, 
@@ -81,6 +96,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -88,16 +104,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 2, 
    "fieldname": "rate", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Rate", 
    "length": 0, 
    "no_copy": 0, 
@@ -108,6 +128,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -115,16 +136,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amount", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -135,6 +160,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -142,16 +168,49 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_6", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "bom_detail_no", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "BOM Detail No", 
    "length": 0, 
    "no_copy": 0, 
@@ -161,6 +220,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -168,16 +228,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "reference_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Reference Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -187,6 +251,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -194,16 +259,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "conversion_factor", 
    "fieldtype": "Float", 
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Conversion Factor", 
    "length": 0, 
    "no_copy": 0, 
@@ -213,6 +282,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -220,16 +290,20 @@
    "unique": 0
   }, 
   {
+   "allow_bulk_edit": 0, 
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "stock_uom", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Stock Uom", 
    "length": 0, 
    "no_copy": 0, 
@@ -240,6 +314,38 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "reserve_warehouse", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Reserve Warehouse", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Warehouse", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -247,17 +353,17 @@
    "unique": 0
   }
  ], 
+ "has_web_view": 0, 
  "hide_heading": 0, 
  "hide_toolbar": 1, 
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
- "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-11 03:28:05.533063", 
+ "modified": "2018-01-05 14:47:15.400785", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Purchase Order Item Supplied", 
@@ -266,5 +372,7 @@
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "show_name_in_global_search": 0, 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_taxes_and_charges.js b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_taxes_and_charges.js
index c4b3419..e37731e 100644
--- a/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_taxes_and_charges.js
+++ b/erpnext/buying/doctype/supplier_quotation/tests/test_supplier_quotation_for_taxes_and_charges.js
@@ -17,7 +17,7 @@
 						{"warehouse": 'Stores - '+frappe.get_abbr(frappe.defaults.get_default('Company'))},
 					]
 				]},
-				{taxes_and_charges:'TEST In State GST'},
+				{taxes_and_charges:'TEST In State GST - FT'},
 			]);
 		},
 		() => {supplier_quotation_name = cur_frm.doc.name;},
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 8ab5128..24ad3a3 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -160,6 +160,11 @@
 				if item in self.sub_contracted_items and not item.bom:
 					frappe.throw(_("Please select BOM in BOM field for Item {0}").format(item.item_code))
 
+			if self.doctype == "Purchase Order":
+				for supplied_item in self.get("supplied_items"):
+					if not supplied_item.reserve_warehouse:
+						frappe.throw(_("Reserved Warehouse is mandatory for Item {0} in Raw Materials supplied").format(frappe.bold(supplied_item.rm_item_code)))
+
 		else:
 			for item in self.get("items"):
 				if item.bom:
@@ -189,8 +194,16 @@
 	def update_raw_materials_supplied(self, item, raw_material_table):
 		bom_items = self.get_items_from_bom(item.item_code, item.bom)
 		raw_materials_cost = 0
+		items = list(set([d.item_code for d in bom_items]))
+		item_wh = frappe._dict(frappe.db.sql("""select item_code, default_warehouse
+			from `tabItem` where name in ({0})""".format(", ".join(["%s"] * len(items))), items))
 
 		for bom_item in bom_items:
+			if self.doctype == "Purchase Order":
+				reserve_warehouse = bom_item.source_warehouse or item_wh.get(bom_item.item_code)
+				if frappe.db.get_value("Warehouse", reserve_warehouse, "company") != self.company:
+					reserve_warehouse = None
+
 			# check if exists
 			exists = 0
 			for d in self.get(raw_material_table):
@@ -210,6 +223,8 @@
 			rm.rm_item_code = bom_item.item_code
 			rm.stock_uom = bom_item.stock_uom
 			rm.required_qty = required_qty
+			if self.doctype == "Purchase Order" and not rm.reserve_warehouse:
+				rm.reserve_warehouse = reserve_warehouse
 
 			rm.conversion_factor = item.conversion_factor
 
@@ -261,7 +276,7 @@
 	def get_items_from_bom(self, item_code, bom):
 		bom_items = frappe.db.sql("""select t2.item_code,
 			t2.stock_qty / ifnull(t1.quantity, 1) as qty_consumed_per_unit,
-			t2.rate, t2.stock_uom, t2.name, t2.description
+			t2.rate, t2.stock_uom, t2.name, t2.description, t2.source_warehouse
 			from `tabBOM` t1, `tabBOM Item` t2, tabItem t3
 			where t2.parent = t1.name and t1.item = %s
 			and t1.docstatus = 1 and t1.is_active = 1 and t1.name = %s
@@ -336,7 +351,7 @@
 					frappe.get_meta(item_row.doctype).get_label(fieldname), item_row['item_code'])))
 
 	def update_stock_ledger(self, allow_negative_stock=False, via_landed_cost_voucher=False):
-		self.update_ordered_qty()
+		self.update_ordered_and_reserved_qty()
 
 		sl_entries = []
 		stock_items = self.get_stock_items()
@@ -378,7 +393,7 @@
 		self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock,
 			via_landed_cost_voucher=via_landed_cost_voucher)
 
-	def update_ordered_qty(self):
+	def update_ordered_and_reserved_qty(self):
 		po_map = {}
 		for d in self.get("items"):
 			if self.doctype=="Purchase Receipt" \
@@ -397,6 +412,8 @@
 						frappe.InvalidStatusError)
 
 				po_obj.update_ordered_qty(po_item_rows)
+				if self.is_subcontracted:
+					po_obj.update_reserved_qty_for_subcontract()
 
 	def make_sl_entries_for_supplier_warehouse(self, sl_entries):
 		if hasattr(self, 'supplied_items'):
diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py
index 85bbf2a..fe1e911 100644
--- a/erpnext/crm/doctype/lead/lead.py
+++ b/erpnext/crm/doctype/lead/lead.py
@@ -101,7 +101,7 @@
 
 	def set_lead_name(self):
 		if not self.lead_name:
-			frappe.db.set_value("Lead", self.name, "lead_name", self.organization_name)
+			frappe.db.set_value("Lead", self.name, "lead_name", self.company_name)
 
 @frappe.whitelist()
 def make_customer(source_name, target_doc=None):
diff --git a/erpnext/crm/doctype/lead/test_records.json b/erpnext/crm/doctype/lead/test_records.json
index 590e200..39864e2 100644
--- a/erpnext/crm/doctype/lead/test_records.json
+++ b/erpnext/crm/doctype/lead/test_records.json
@@ -29,7 +29,7 @@
  "email_id": "test_lead4@example.com",
  "organization_lead": 1,
  "lead_name": "_Test Lead 4",
- "organization_name": "_Test Lead 4",
+ "company_name": "_Test Lead 4",
  "status": "Open"
 }
 ]
diff --git a/erpnext/docs/assets/img/setup-wizard/step-1.png b/erpnext/docs/assets/img/setup-wizard/step-1.png
index 0a3c230..79d4e1f 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-1.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-10.png b/erpnext/docs/assets/img/setup-wizard/step-10.png
index 4687999..f16ab62 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-10.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-10.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-10a.png b/erpnext/docs/assets/img/setup-wizard/step-10a.png
new file mode 100644
index 0000000..5f40555
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-10a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-11.png b/erpnext/docs/assets/img/setup-wizard/step-11.png
new file mode 100644
index 0000000..229c360
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-11.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-11a.png b/erpnext/docs/assets/img/setup-wizard/step-11a.png
new file mode 100644
index 0000000..2804bc9
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-11a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-12.png b/erpnext/docs/assets/img/setup-wizard/step-12.png
new file mode 100644
index 0000000..ea6cb8e
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-12.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-12a.png b/erpnext/docs/assets/img/setup-wizard/step-12a.png
new file mode 100644
index 0000000..3b156ee
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-12a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-2.png b/erpnext/docs/assets/img/setup-wizard/step-2.png
index 7330004..abd9deb 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-2.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-3.png b/erpnext/docs/assets/img/setup-wizard/step-3.png
index 7aac64a..182d153 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-3.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-3.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-4.png b/erpnext/docs/assets/img/setup-wizard/step-4.png
index cee29fc..d799f4b 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-4.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-4.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-5.png b/erpnext/docs/assets/img/setup-wizard/step-5.png
index a770f3e..fbe8bf6 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-5.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-5.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-6.png b/erpnext/docs/assets/img/setup-wizard/step-6.png
index db2bf38..a1675dd 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-6.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-6.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-6a.png b/erpnext/docs/assets/img/setup-wizard/step-6a.png
new file mode 100644
index 0000000..f9388b5
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-6a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-7.png b/erpnext/docs/assets/img/setup-wizard/step-7.png
index 02c6da6..9e5f8fc 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-7.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-7.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-8.png b/erpnext/docs/assets/img/setup-wizard/step-8.png
index 18f8d88..2e12519 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-8.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-8.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-8a.png b/erpnext/docs/assets/img/setup-wizard/step-8a.png
new file mode 100644
index 0000000..764e64f
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-8a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-9.png b/erpnext/docs/assets/img/setup-wizard/step-9.png
index dced6e0..b417cf8 100644
--- a/erpnext/docs/assets/img/setup-wizard/step-9.png
+++ b/erpnext/docs/assets/img/setup-wizard/step-9.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/step-9a.png b/erpnext/docs/assets/img/setup-wizard/step-9a.png
new file mode 100644
index 0000000..f409785
--- /dev/null
+++ b/erpnext/docs/assets/img/setup-wizard/step-9a.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup-wizard/twofactor.png b/erpnext/docs/assets/img/setup-wizard/twofactor.png
deleted file mode 100644
index ada4f5b..0000000
--- a/erpnext/docs/assets/img/setup-wizard/twofactor.png
+++ /dev/null
Binary files differ
diff --git a/erpnext/docs/user/manual/de/human-resources/training.md b/erpnext/docs/user/manual/de/human-resources/training.md
new file mode 100644
index 0000000..84091d9
--- /dev/null
+++ b/erpnext/docs/user/manual/de/human-resources/training.md
@@ -0,0 +1,37 @@
+# Schulung
+### Schulungsprogramm
+
+Erstelle ein Schulungsprogramm und teile die Schulungstermine ein. Auf der Seite des  Schulungsprogramms gibt es einen Link zur Ansicht aller Schulungstermine dieses Schulungsprogramms.
+
+<img class="screenshot" alt="Employee" src="/docs/assets/img/human-resources/training_program.png">
+
+### Schulungstermin
+
+Erstelle Termine für Seminare, Workshops, Konferenzen etc über den Link im Schulungsprogramm. Hier können die Teilnehmer die die Schulung benötigen eingetragen werden.
+
+<img class="screenshot" alt="Employee" src="/docs/assets/img/human-resources/training_event.png">
+
+### Teilnehmer zum Schulungstermin einladen
+
+Die Teilnehmer können aus der Liste der Mitarbeiter ausgewählt werden.
+
+Standardmäßig ist der Status des Mitarbeiters „Offen“.
+
+<img class="screenshot" alt="Employee" src="/docs/assets/img/human-resources/training_event_employee.png">
+
+Wenn der Schulungstermin gebucht wird, dann wird eine Benachrichtigung an den Mitarbeiter gesendet, dass er zum Schulungstermin eigeladen ist. Dies wird über die automatische Email „Schulungstermin“ gesendet. Der Inhalt der Email kann entsprechend angepasst werden.
+
+### Schulungsergebnis
+
+Nach der Schulung können die Ergebnisse gespeichert werden basierend auf dem Feedback des Trainers.
+
+<img class="screenshot" alt="Employee" src="/docs/assets/img/human-resources/training_result.png">
+
+Wenn das Schulungsergebnis gebucht wird, bekommen die Mitarbeiter eine Benachrichtigung, dass sie eine Schulungsbeurteilung abgeben sollen. Dies wird ebenfalls über die automatische Email verwaltet, der Inhalt kann auch hier angepasst werden.
+
+### Schulungsbeurteilung
+
+Die Mitarbeiter können ihre Rückmeldung durch die Schulungsbeurteilung geben.
+
+<img class="screenshot" alt="Employee" src="/docs/assets/img/human-resources/training_feedback.png">
+
diff --git a/erpnext/docs/user/manual/en/education/admission/program-enrollment-tool.md b/erpnext/docs/user/manual/en/education/admission/program-enrollment-tool.md
index 53d9d9c..97a26c7 100644
--- a/erpnext/docs/user/manual/en/education/admission/program-enrollment-tool.md
+++ b/erpnext/docs/user/manual/en/education/admission/program-enrollment-tool.md
@@ -1,16 +1,21 @@
 # Program Enrollment Tool
 
-The Program Enrollment tool allows the bulk enrollment of the **Student Applicants** in a Program. 
+The Program Enrollment tool allows the bulk enrollment of the new and old students in a Program. If you are enrolling a new student, you  can fetch the students from the **Student Applicant** or if you are promoting the older students you can fetch them from the **Program Enrollment** itself
 
+> Note: Academic Term is optional in the Program Enrollment Tool
 
-You can create the the Program Enrollment for :
+You can create the Program Enrollment for :
 
-1. **Student Applicants** >> List of Student Applicants will be fetched for the selected **Program** and **Academic year**.
+1. **Student Applicants**: List of Student Applicants will be fetched for the selected **Program**, **Academic year** and **Academic Term** (if provided). 
 
 <img class="screenshot" alt="Student Applicant Enrollment" src="/docs/assets/img/education/admission/program-enrollment-tool.gif">
 
-2. **Program Enrollment** >> You can bulk update the **Program** for the students from one academic year to another in the same **Program** or a new **Program**.
+2. **Program Enrollment**: List of students already enrolled in selected **Program** for the given **Academic Year**, **Academic Term** (if provided) and **Student Batch** will be fetched and can be used to enroll students from one academic year/term to another in the same **Program** or a new **Program**.
 
 <img class="screenshot" alt="Student Applicant Enrollment" src="/docs/assets/img/education/admission/program-enrollment-tool01.gif">
 
+**New Student Batch**: This can be selected for the entire students fetched in the table. Priority will be given to the Batch selected in the table (for individual students).
+
+For promoting the students, the new academic year, academic term and program can also be selected for the enrollment of the fetched students list.
+
 {next}
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.md
index c05c4af..36b79ce 100644
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.md
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.md
@@ -1,6 +1,6 @@
 # Setup Wizard
 
-The Setup Wizard helps you quickly setup ERPnext as per your locale and sets up your organisation.
+The Setup Wizard helps you quickly setup ERPnext as per your locale and sets up your organization.
 
 Here is a quick overview of the steps:
 
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.txt b/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.txt
index b2f680a..91c3afc 100644
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.txt
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/index.txt
@@ -1,5 +1,12 @@
-step-1-language
-step-2-currency-and-timezone
-step-3-user-details
-step-4-two-factor-authentication
-step-5-company-details
+step-01-language
+step-02-currency-and-timezone
+step-03-user-details
+step-04-select-domain
+step-05-the-brand
+step-06-your-organization
+step-07-setup-company-complete
+step-08-set-sales-target
+step-09-customers
+step-10-letterhead
+step-11-suppliers
+step-12-users
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-1-language.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-01-language.md
similarity index 100%
rename from erpnext/docs/user/manual/en/setting-up/setup-wizard/step-1-language.md
rename to erpnext/docs/user/manual/en/setting-up/setup-wizard/step-01-language.md
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-02-currency-and-timezone.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-02-currency-and-timezone.md
new file mode 100644
index 0000000..4f0fbcc
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-02-currency-and-timezone.md
@@ -0,0 +1,15 @@
+# Step 2: Country, Currency and Time Zone
+
+Set your Country Name, Time Zone and Currency.
+
+<img alt="Currency" class="screenshot" src="/docs/assets/img/setup-wizard/step-2.png">
+
+### Default Currency
+
+For most countries, your currency and time zone will be automatically set.
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-03-user-details.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-03-user-details.md
new file mode 100644
index 0000000..d85c940
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-03-user-details.md
@@ -0,0 +1,11 @@
+# Step 3: User Details
+
+Enter the First User. Give the Full Name, Email Address (as User ID) and Password. This first user will be setup as a System Manager with privileges similar to the Administrator account.
+
+<img alt="User" class="screenshot" src="/docs/assets/img/setup-wizard/step-3.png">
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-04-select-domain.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-04-select-domain.md
new file mode 100644
index 0000000..523195b
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-04-select-domain.md
@@ -0,0 +1,11 @@
+# Step 4: Select Domain
+
+Select the domain(s) that will be enabled after setup.
+
+<img alt="Domains" class="screenshot" src="/docs/assets/img/setup-wizard/step-4.png">
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-05-the-brand.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-05-the-brand.md
new file mode 100644
index 0000000..a310144
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-05-the-brand.md
@@ -0,0 +1,17 @@
+# Step 5: The Brand
+
+Enter Company Name, Abbreviation and add a logo.
+
+<img alt="Company Details" class="screenshot" src="/docs/assets/img/setup-wizard/step-5.png">
+
+### Company Abbreviation
+
+These will be appended to your **Account** Heads, for example if your abbreviation is **WPL**, then your Sales account will be **Sales - WPL**
+
+For Example: East Wind will be abbreviated as EW. Shades of Green will be abbreviated as SOG. In case you wish to give your own abbreviation, you can do so. The text field allows any type of text.
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-06-your-organization.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-06-your-organization.md
new file mode 100644
index 0000000..301e529
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-06-your-organization.md
@@ -0,0 +1,23 @@
+# Step 6: Your Organization
+
+Enter in a short sentence of what your company does. This is often a mission statement or vision statement.
+
+Add the name of the organization's primary financial institution. This information will populate **Accounts**.
+
+<img alt="Company Details" class="screenshot" src="/docs/assets/img/setup-wizard/step-6.png">
+
+### Chart of Accounts
+
+Select whether the organization will use a standard chart of accounts without number or a standard chart of accounts with numbers.  The out of box chart of accounts is the same either way.
+
+### Financial Year
+
+Any annual period at the end of which a firm's accounts are made up is called a Financial Year. Some countries have their account year starting from 1st January and some 1st April.
+
+The end date will be set automatically
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-07-setup-company-complete.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-07-setup-company-complete.md
new file mode 100644
index 0000000..477a2ca
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-07-setup-company-complete.md
@@ -0,0 +1,15 @@
+# Step 7: Initial Setup Complete
+
+The initial setup wizard will create all the settings needed including the first system manager user. 
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-6a.png">
+
+When complete, the Setup Wizard will go to the Desk and begin a secondary set of steps. This screen shows that the initial setup wizard is complete and begins the secondary setup wizard.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-7.png">
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-08-set-sales-target.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-08-set-sales-target.md
new file mode 100644
index 0000000..98d9f75
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-08-set-sales-target.md
@@ -0,0 +1,15 @@
+# Step 8: Set Sales Target
+
+Set a monthly sales target for the organization in the currency selected during Step 2.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-8.png">
+
+If a sales target is not known, then clicking **Mark as Done** will complete the step.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-8a.png">
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-09-customers.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-09-customers.md
new file mode 100644
index 0000000..9b38ae6
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-09-customers.md
@@ -0,0 +1,15 @@
+# Step 9: Add Customers
+
+Add known customers to the system.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-9.png">
+
+If customers are not known, then clicking **Mark as Done** will complete the step.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-9a.png"> 
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-10-letterhead.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-10-letterhead.md
new file mode 100644
index 0000000..55dccb1
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-10-letterhead.md
@@ -0,0 +1,15 @@
+# Step 10: Company Letter Head
+
+Add a company logo to be used as a standard letter head on all printed invoices and other document types. Ideally the logo is 900px by 100px.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-10.png">
+
+If a letter head logo file is not available, the clicking **Mark as Done** will complete the step.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-10a.png">
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-11-suppliers.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-11-suppliers.md
new file mode 100644
index 0000000..f1e9967
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-11-suppliers.md
@@ -0,0 +1,20 @@
+# Step 11: Add Suppliers
+
+Add known suppliers to the system.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-11.png">
+
+If suppliers are not known, then clicking **Mark as Done** will complete the step.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-11a.png"> 
+
+
+## Step 11a: Other Domain Specific Steps
+
+Depending on the domain(s) selected in Step 4, there will be more screens to fill in for the secondary setup wizard.
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-12-users.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-12-users.md
new file mode 100644
index 0000000..cc2a4ae
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-12-users.md
@@ -0,0 +1,15 @@
+# Step 12: Add Users
+
+The last step in the secondary setup wizard will prompt to add more users to the system. These users will be regular non-privileged users.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-12.png">
+
+If users are not known, then clicking **Mark as Done** will complete the step.
+
+<img alt="Language" class="screenshot" src="/docs/assets/img/setup-wizard/step-12a.png"> 
+
+---
+
+Translations are contributed by the ERPNext Community. If you want to contribute, [please checkout the translator portal](https://translate.erpnext.com).
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-2-currency-and-timezone.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-2-currency-and-timezone.md
deleted file mode 100644
index 6809f40..0000000
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-2-currency-and-timezone.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Step 2: Currency and Timezone
-
-Set your country name, currency and timezone.
-
-<img alt="Currency" class="screenshot" src="/docs/assets/img/setup-wizard/step-2.png">
-
----
-
-### Default Currency
-
-For most countries, your currency and timezone will be automatically set
-
-{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-3-user-details.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-3-user-details.md
deleted file mode 100644
index 228b972..0000000
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-3-user-details.md
+++ /dev/null
@@ -1,11 +0,0 @@
-# Step 3: User Details
-
-Enter Users Profile Details like Name, User ID and preferred password.
-
-<img alt="User" class="screenshot" src="/docs/assets/img/setup-wizard/step-3.png">
-
----
-
-Note: Add your own photograph, not your company's
-
-{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-4-two-factor-authentication.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-4-two-factor-authentication.md
deleted file mode 100644
index 66bbd07..0000000
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-4-two-factor-authentication.md
+++ /dev/null
@@ -1,13 +0,0 @@
-# Step 4: Two Factor Authentication
-
-Enable Two Factor Athentication
-
-<img alt="TwoFactor" class="screenshot" src="/docs/assets/img/setup-wizard/twofactor.png">
-
----
-###Authentication Method
-Whenevever each user logs in, based on the role set for that user,
-they will be asked for a **One Time Password** after they input 
-their login details.
-
-{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-5-company-details.md b/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-5-company-details.md
deleted file mode 100644
index 13a87e9..0000000
--- a/erpnext/docs/user/manual/en/setting-up/setup-wizard/step-5-company-details.md
+++ /dev/null
@@ -1,21 +0,0 @@
-# Step 5: Company Details
-
-Enter Company Details like Name, Abbreviation and Financial Year Details.
-
-<img alt="Company Details" class="screenshot" src="/docs/assets/img/setup-wizard/step-4.png">
-
----
-
-### Company Abbreviation
-
-These will be appened to your **Account** Heads, for example if your abbreviation is **WP**, then your Sales account will be **Sales - WPL**
-
-For Example: East Wind will be abbreviated as EW. Shades of Green will be abbreviated as SOG. In case you wish to give your own abbreviation, you can do so. The text field allows any type of text.
-
-### Financial Year
-
-Any annual period at the end of which a firm's accounts are made up is called a Financial Year. Some countries have their account year starting from 1st January and some 1st April.
-
-The end date will be set automatically
-
-{next}
diff --git a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.js b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.js
index bf6f3e0..4f8ce6d 100644
--- a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.js
+++ b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.js
@@ -1,11 +1,19 @@
 // Copyright (c) 2016, Frappe and contributors
 // For license information, please see license.txt
-cur_frm.add_fetch("student", "title", "student_name");
-cur_frm.add_fetch("student_applicant", "title", "student_name");
 
 frappe.ui.form.on("Program Enrollment Tool", {
+	setup: function(frm) {
+		frm.add_fetch("student", "title", "student_name");
+		frm.add_fetch("student_applicant", "title", "student_name");
+	},
+
 	"refresh": function(frm) {
 		frm.disable_save();
+		frm.fields_dict.enroll_students.$input.addClass(' btn btn-primary');
+		frappe.realtime.on("program_enrollment_tool", function(data) {
+			frappe.hide_msgprint(true);
+			frappe.show_progress(__("Enrolling students"), data.progress[0], data.progress[1]);
+		});
 	},
 
 	"get_students": function(frm) {
@@ -18,7 +26,7 @@
 					frm.set_value("students", r.message);
 				}
 			}
-		})
+		});
 	},
 
 	"enroll_students": function(frm) {
@@ -27,7 +35,8 @@
 			doc:frm.doc,
 			callback: function(r) {
 				frm.set_value("students", []);
+				frappe.hide_msgprint(true);
 			}
-		})
+		});
 	}
 });
diff --git a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.json b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.json
index 71071cd..d611a6f 100644
--- a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.json
+++ b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.json
@@ -29,7 +29,7 @@
    "label": "Get Students From", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nStudent Applicants\nProgram Enrollments", 
+   "options": "\nStudent Applicant\nProgram Enrollment", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -79,6 +79,67 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:doc.get_students_from==\"Program Enrollment\"", 
+   "fieldname": "student_batch", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Student Batch", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Batch Name", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_3", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "academic_year", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -110,8 +171,8 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "get_students", 
-   "fieldtype": "Button", 
+   "fieldname": "academic_term", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -119,9 +180,10 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Get Students", 
+   "label": "Academic Term", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Academic Term", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -169,6 +231,36 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "get_students", 
+   "fieldtype": "Button", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Get Students", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "students", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -209,6 +301,7 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Enrollment Details", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -229,7 +322,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "eval:doc.get_students_from==\"Program Enrollments\"", 
+   "depends_on": "eval:doc.get_students_from==\"Program Enrollment\"", 
    "fieldname": "new_program", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -261,8 +354,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "eval:doc.get_students_from==\"Program Enrollments\"", 
-   "fieldname": "new_academic_year", 
+   "fieldname": "new_student_batch", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -271,10 +363,10 @@
    "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "New Academic Year", 
+   "label": "New Student Batch", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Academic Year", 
+   "options": "Student Batch Name", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -316,6 +408,99 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_12", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:doc.get_students_from==\"Program Enrollment\"", 
+   "fieldname": "new_academic_year", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "New Academic Year", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Academic Year", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:doc.get_students_from==\"Program Enrollment\"", 
+   "fieldname": "new_academic_term", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "New Academic Term", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Academic Term", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "has_web_view": 0, 
@@ -328,7 +513,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-12-27 09:35:45.002469", 
+ "modified": "2018-01-02 11:59:40.230689", 
  "modified_by": "Administrator", 
  "module": "Education", 
  "name": "Program Enrollment Tool", 
diff --git a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.py b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.py
index d989d9f..824a295 100644
--- a/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.py
+++ b/erpnext/education/doctype/program_enrollment_tool/program_enrollment_tool.py
@@ -17,21 +17,26 @@
 		elif not self.academic_year:
 			frappe.throw(_("Mandatory field - Academic Year"))
 		else:
-			if self.get_students_from == "Student Applicants":
-				students = frappe.db.sql("select name as student_applicant, title as student_name from \
-					`tabStudent Applicant` where program = %s and academic_year = %s",(self.program, self.academic_year), as_dict=1)
-			else:
-				students = frappe.db.sql("select student, student_name, student_batch_name from \
-					`tabProgram Enrollment` where program = %s and academic_year = %s",(self.program, self.academic_year), as_dict=1)
+			condition = 'and academic_term=%(academic_term)s' if self.academic_term else " "
+			if self.get_students_from == "Student Applicant":
+				students = frappe.db.sql('''select name as student_applicant, title as student_name from `tabStudent Applicant`
+					where application_status="Approved" and program=%(program)s and academic_year=%(academic_year)s {0}'''
+					.format(condition), self.as_dict(), as_dict=1)
+			elif self.get_students_from == "Program Enrollment":
+				condition2 = 'and student_batch_name=%(student_batch)s' if self.student_batch else " "
+				students = frappe.db.sql('''select student, student_name, student_batch_name from `tabProgram Enrollment`
+					where program=%(program)s and academic_year=%(academic_year)s {0} {1}'''
+					.format(condition, condition2), self.as_dict(), as_dict=1)
+
 				student_list = [d.student for d in students]
+				if student_list:
+					inactive_students = frappe.db.sql('''
+						select name as student, title as student_name from `tabStudent` where name in (%s) and enabled = 0''' %
+						', '.join(['%s']*len(student_list)), tuple(student_list), as_dict=1)
 
-				inactive_students = frappe.db.sql('''
-					select name as student, title as student_name from `tabStudent` where name in (%s) and enabled = 0''' %
-					', '.join(['%s']*len(student_list)), tuple(student_list), as_dict=1)
-
-				for student in students:
-					if student.student in [d.student for d in inactive_students]:
-						students.remove(student)
+					for student in students:
+						if student.student in [d.student for d in inactive_students]:
+							students.remove(student)
 
 		if students:
 			return students
@@ -39,18 +44,22 @@
 			frappe.throw(_("No students Found"))
 			
 	def enroll_students(self):
-		for stud in self.students:
+		total = len(self.students)
+		for i, stud in enumerate(self.students):
+			frappe.publish_realtime("program_enrollment_tool", dict(progress=[i+1, total]), user=frappe.session.user)
 			if stud.student:
 				prog_enrollment = frappe.new_doc("Program Enrollment")
 				prog_enrollment.student = stud.student
 				prog_enrollment.student_name = stud.student_name
-				prog_enrollment.student_batch_name = stud.student_batch_name
 				prog_enrollment.program = self.new_program
 				prog_enrollment.academic_year = self.new_academic_year
+				prog_enrollment.academic_term = self.new_academic_term
+				prog_enrollment.student_batch_name = stud.student_batch_name if stud.student_batch_name else self.new_student_batch
 				prog_enrollment.save()
 			elif stud.student_applicant:
 				prog_enrollment = enroll_student(stud.student_applicant)
 				prog_enrollment.academic_year = self.academic_year
+				prog_enrollment.academic_term = self.academic_term
+				prog_enrollment.student_batch_name = stud.student_batch_name if stud.student_batch_name else self.new_student_batch
 				prog_enrollment.save()
-		frappe.msgprint("Students have been enrolled.")
-			
\ No newline at end of file
+		frappe.msgprint("{0} Students have been enrolled.".format(total))
diff --git a/erpnext/education/doctype/program_enrollment_tool_student/program_enrollment_tool_student.json b/erpnext/education/doctype/program_enrollment_tool_student/program_enrollment_tool_student.json
index 0dbe1b8..9be292b 100644
--- a/erpnext/education/doctype/program_enrollment_tool_student/program_enrollment_tool_student.json
+++ b/erpnext/education/doctype/program_enrollment_tool_student/program_enrollment_tool_student.json
@@ -133,6 +133,37 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "student_batch_name", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Student Batch Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Batch Name", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
   }
  ], 
  "has_web_view": 0, 
@@ -145,7 +176,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2017-11-10 19:09:59.530615", 
+ "modified": "2018-01-02 12:03:53.890741", 
  "modified_by": "Administrator", 
  "module": "Education", 
  "name": "Program Enrollment Tool Student", 
diff --git a/erpnext/education/doctype/student_applicant/student_applicant.json b/erpnext/education/doctype/student_applicant/student_applicant.json
index 9c84234..1140984 100644
--- a/erpnext/education/doctype/student_applicant/student_applicant.json
+++ b/erpnext/education/doctype/student_applicant/student_applicant.json
@@ -326,6 +326,37 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "academic_term", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Academic Term", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Academic Term", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_admission", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -1058,7 +1089,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-11-10 19:08:55.049625", 
+ "modified": "2018-01-02 11:47:14.944338", 
  "modified_by": "Administrator", 
  "module": "Education", 
  "name": "Student Applicant", 
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index 65d1065..f40e77c 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -262,27 +262,30 @@
 	},
 
 	get_advances: function(frm) {
-		return frappe.call({
-			method: "erpnext.hr.doctype.expense_claim.expense_claim.get_advances",
-			args: {
-				employee: frm.doc.employee
-			},
-			callback: function(r, rt) {
-				frappe.model.clear_table(frm.doc, "advances");
-				if(r.message) {
-					$.each(r.message, function(i, d) {
-						var row = frappe.model.add_child(frm.doc, "Expense Claim Advance", "advances");
-						row.employee_advance = d.name;
-						row.posting_date = d.posting_date;
-						row.advance_account = d.advance_account;
-						row.advance_paid = d.paid_amount;
-						row.unclaimed_amount = flt(d.paid_amount) - flt(d.claimed_amount);
-						row.allocated_amount = flt(d.paid_amount) - flt(d.claimed_amount);
-					});
-					refresh_field("advances");
+		frappe.model.clear_table(frm.doc, "advances");
+		if (frm.doc.employee) {
+			return frappe.call({
+				method: "erpnext.hr.doctype.expense_claim.expense_claim.get_advances",
+				args: {
+					employee: frm.doc.employee
+				},
+				callback: function(r, rt) {
+				
+					if(r.message) {
+						$.each(r.message, function(i, d) {
+							var row = frappe.model.add_child(frm.doc, "Expense Claim Advance", "advances");
+							row.employee_advance = d.name;
+							row.posting_date = d.posting_date;
+							row.advance_account = d.advance_account;
+							row.advance_paid = d.paid_amount;
+							row.unclaimed_amount = flt(d.paid_amount) - flt(d.claimed_amount);
+							row.allocated_amount = flt(d.paid_amount) - flt(d.claimed_amount);
+						});
+						refresh_field("advances");
+					}
 				}
-			}
-		});
+			});
+		}
 	}
 });
 
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index 5976915..5c2c112 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -484,4 +484,5 @@
 erpnext.patches.v10_0.enabled_regional_print_format_based_on_country
 erpnext.patches.v10_0.update_asset_calculate_depreciation
 erpnext.patches.v10_0.add_guardian_role_for_parent_portal
-erpnext.patches.v10_0.set_numeric_ranges_in_template_if_blank
\ No newline at end of file
+erpnext.patches.v10_0.set_numeric_ranges_in_template_if_blank
+erpnext.patches.v10_0.update_reserved_qty_for_purchase_order
\ No newline at end of file
diff --git a/erpnext/patches/v10_0/update_reserved_qty_for_purchase_order.py b/erpnext/patches/v10_0/update_reserved_qty_for_purchase_order.py
new file mode 100644
index 0000000..f0de423
--- /dev/null
+++ b/erpnext/patches/v10_0/update_reserved_qty_for_purchase_order.py
@@ -0,0 +1,48 @@
+import frappe
+from frappe import _
+from erpnext.stock.utils import get_bin
+
+def execute():
+	po_item = list(frappe.db.sql(("""
+		select distinct po.name as poname, poitem.rm_item_code as rm_item_code, po.company
+		from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitem
+		where po.name = poitem.parent
+			and po.is_subcontracted = "Yes"
+			and po.docstatus = 1"""), as_dict=1))
+	if not po_item:
+		return
+
+	company_warehouse = frappe._dict(frappe.db.sql("""select company, min(name) from `tabWarehouse`
+		where is_group = 0 group by company"""))
+
+	items = list(set([d.rm_item_code for d in po_item]))
+	item_wh = frappe._dict(frappe.db.sql("""select item_code, default_warehouse
+		from `tabItem` where name in ({0})""".format(", ".join(["%s"] * len(items))), items))
+
+	# Update reserved warehouse
+	for item in po_item:
+		reserve_warehouse = get_warehouse(item.rm_item_code, item.company, company_warehouse, item_wh)
+		update_res_warehouse = frappe.db.sql("""update `tabPurchase Order Item Supplied`
+			set reserve_warehouse = %s
+			where parent = %s and rm_item_code = %s
+		""", (reserve_warehouse, item["poname"], item["rm_item_code"]))
+
+	# Update bin
+	item_wh_bin = frappe.db.sql(("""
+		select distinct poitemsup.rm_item_code as rm_item_code, 
+			poitemsup.reserve_warehouse as reserve_warehouse
+		from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
+		where po.name = poitemsup.parent
+			and po.is_subcontracted = "Yes"
+			and po.docstatus = 1"""), as_dict=1)
+	for d in item_wh_bin:
+		stock_bin = get_bin(d["rm_item_code"], d["reserve_warehouse"])
+		stock_bin.update_reserved_qty_for_sub_contracting()
+
+def get_warehouse(item_code, company, company_warehouse, item_wh):
+	reserve_warehouse = item_wh.get(item_code)
+	if frappe.db.get_value("Warehouse", reserve_warehouse, "company") != company:
+		reserve_warehouse = None
+	if not reserve_warehouse:
+		reserve_warehouse = company_warehouse.get(company)
+	return reserve_warehouse
\ No newline at end of file
diff --git a/erpnext/patches/v5_8/update_order_reference_in_return_entries.py b/erpnext/patches/v5_8/update_order_reference_in_return_entries.py
index d7972dc..5032638 100644
--- a/erpnext/patches/v5_8/update_order_reference_in_return_entries.py
+++ b/erpnext/patches/v5_8/update_order_reference_in_return_entries.py
@@ -10,6 +10,7 @@
 	frappe.reload_doctype("Purchase Receipt")
 	frappe.reload_doctype("Sales Order Item")
 	frappe.reload_doctype("Purchase Order Item")
+	frappe.reload_doctype("Purchase Order Item Supplied")
 
 	# sales return
 	return_entries = list(frappe.db.sql("""
@@ -86,6 +87,6 @@
 			""", (order_details[0].purchase_order, order_details[0].po_detail, d.row_id))
 
 			pr = frappe.get_doc("Purchase Receipt", d.name)
-			pr.update_ordered_qty()
+			pr.update_ordered_and_reserved_qty()
 			pr.update_prevdoc_status()
 
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 711e836..1102006 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -236,7 +236,11 @@
 		var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
 			me.frm.doc.name);
 
-		if(taxes_and_charges_field) {
+		if (!this.frm.doc.taxes_and_charges && this.frm.doc.taxes) {
+			return;
+		}
+
+		if (taxes_and_charges_field) {
 			return frappe.call({
 				method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
 				args: {
@@ -1231,13 +1235,14 @@
 
 	payment_terms_template: function() {
 		var me = this;
-		if(this.frm.doc.payment_terms_template) {
+		const doc = this.frm.doc;
+		if(doc.payment_terms_template && doc.doctype !== 'Delivery Note') {
 			frappe.call({
 				method: "erpnext.controllers.accounts_controller.get_payment_terms",
 				args: {
-					terms_template: this.frm.doc.payment_terms_template,
-					posting_date: this.frm.doc.posting_date || this.frm.doc.transaction_date,
-					grand_total: this.frm.doc.rounded_total || this.frm.doc.grand_total
+					terms_template: doc.payment_terms_template,
+					posting_date: doc.posting_date || doc.transaction_date,
+					grand_total: doc.rounded_total || doc.grand_total
 				},
 				callback: function(r) {
 					if(r.message && !r.exc) {
diff --git a/erpnext/selling/doctype/quotation/tests/test_quotation_with_taxes_and_charges.js b/erpnext/selling/doctype/quotation/tests/test_quotation_with_taxes_and_charges.js
index 6cc3604..ac7ed65 100644
--- a/erpnext/selling/doctype/quotation/tests/test_quotation_with_taxes_and_charges.js
+++ b/erpnext/selling/doctype/quotation/tests/test_quotation_with_taxes_and_charges.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 4', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 
diff --git a/erpnext/selling/doctype/sales_order/tests/test_sales_order.js b/erpnext/selling/doctype/sales_order/tests/test_sales_order.js
index 939261c..c99f9ef 100644
--- a/erpnext/selling/doctype/sales_order/tests/test_sales_order.js
+++ b/erpnext/selling/doctype/sales_order/tests/test_sales_order.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'},
 				{payment_terms_template: '_Test Payment Term Template UI'}
@@ -34,7 +34,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 3', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 		},
diff --git a/erpnext/selling/doctype/sales_order/tests/test_sales_order_with_taxes_and_charges.js b/erpnext/selling/doctype/sales_order/tests/test_sales_order_with_taxes_and_charges.js
index c946443..a3668ab 100644
--- a/erpnext/selling/doctype/sales_order/tests/test_sales_order_with_taxes_and_charges.js
+++ b/erpnext/selling/doctype/sales_order/tests/test_sales_order_with_taxes_and_charges.js
@@ -17,7 +17,7 @@
 				{customer_address: 'Test1-Billing'},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 4', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 
diff --git a/erpnext/selling/page/point_of_sale/point_of_sale.js b/erpnext/selling/page/point_of_sale/point_of_sale.js
index 386e18d..e2fc10c 100644
--- a/erpnext/selling/page/point_of_sale/point_of_sale.js
+++ b/erpnext/selling/page/point_of_sale/point_of_sale.js
@@ -360,6 +360,7 @@
 			fieldtype: 'Link',
 			label: __('POS Profile'),
 			options: 'POS Profile',
+			reqd: 1,
 			get_query: () => {
 				return {
 					query: 'erpnext.accounts.doctype.pos_profile.pos_profile.pos_profile_query',
@@ -1211,6 +1212,7 @@
 		return new Promise(res => {
 			frappe.call({
 				method: "erpnext.selling.page.point_of_sale.point_of_sale.get_items",
+				freeze: true,
 				args: {
 					start,
 					page_length,
diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js
index 8b7e641..29077dc 100644
--- a/erpnext/setup/doctype/company/company.js
+++ b/erpnext/setup/doctype/company/company.js
@@ -34,24 +34,52 @@
 
 			frm.add_custom_button(__('Cost Centers'), function() {
 				frappe.set_route('Tree', 'Cost Center', {'company': frm.doc.name})
-			})
+			}, __("View"));
 
 			frm.add_custom_button(__('Chart of Accounts'), function() {
 				frappe.set_route('Tree', 'Account', {'company': frm.doc.name})
-			})
+			}, __("View"));
+
+			frm.add_custom_button(__('Sales Tax Template'), function() {
+				frappe.set_route('List', 'Sales Taxes and Charges Template', {'company': frm.doc.name});
+			}, __("View"));
+
+			frm.add_custom_button(__('Purchase Tax Template'), function() {
+				frappe.set_route('List', 'Purchase Taxes and Charges Template', {'company': frm.doc.name});
+			}, __("View"));
+
+			frm.add_custom_button(__('Default Tax Template'), function() {
+				frm.trigger("make_default_tax_template");
+			}, __("Make"));
+
+			frm.page.set_inner_btn_group_as_primary(__("View"));
+			frm.page.set_inner_btn_group_as_primary(__("Make"));
 		}
 
 		erpnext.company.set_chart_of_accounts_options(frm.doc);
 
 	},
 
+	make_default_tax_template: function(frm) {
+		frm.call({
+			method: "create_default_tax_template",
+			doc: frm.doc,
+			freeze: true,
+			callback: function() {
+				frappe.msgprint(__("Default tax templates for sales and purchase are created."));
+			}
+		})
+	},
+
 	onload_post_render: function(frm) {
 		if(frm.get_field("delete_company_transactions").$input)
 			frm.get_field("delete_company_transactions").$input.addClass("btn-danger");
 	},
+
 	country: function(frm) {
 		erpnext.company.set_chart_of_accounts_options(frm.doc);
 	},
+
 	delete_company_transactions: function(frm) {
 		frappe.verify_password(function() {
 			var d = frappe.prompt({
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 0a8d504..a36810f 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -50,6 +50,13 @@
 		if frappe.db.sql("select abbr from tabCompany where name!=%s and abbr=%s", (self.name, self.abbr)):
 			frappe.throw(_("Abbreviation already used for another company"))
 
+	def create_default_tax_template(self):
+		from erpnext.setup.setup_wizard.operations.taxes_setup import create_sales_tax
+		create_sales_tax({
+			'country': self.country,
+			'company_name': self.name
+		})
+
 	def validate_default_accounts(self):
 		for field in ["default_bank_account", "default_cash_account",
 			"default_receivable_account", "default_payable_account",
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 5d3ef78..39172d7 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -82,7 +82,7 @@
 
 	# base query
 	query = """select I.name, I.item_name, I.item_code, I.route, I.image, I.website_image, I.thumbnail, I.item_group,
-			I.description, I.web_long_description as website_description,
+			I.description, I.web_long_description as website_description, I.is_stock_item,
 			case when (S.actual_qty - S.reserved_qty) > 0 then 1 else 0 end as in_stock
 		from `tabItem` I
 		left join tabBin S on I.item_code = S.item_code and I.website_warehouse = S.warehouse
diff --git a/erpnext/setup/setup_wizard/operations/taxes_setup.py b/erpnext/setup/setup_wizard/operations/taxes_setup.py
index a2466fe..dd5c037 100644
--- a/erpnext/setup/setup_wizard/operations/taxes_setup.py
+++ b/erpnext/setup/setup_wizard/operations/taxes_setup.py
@@ -16,38 +16,44 @@
 				tax_data.get('tax_rate'), sales_tax)
 
 def make_tax_account_and_template(company, account_name, tax_rate, template_name=None):
+	if not isinstance(account_name, (list, tuple)):
+		account_name = [account_name]
+		tax_rate = [tax_rate]
+
+	accounts = []
+	for i, name in enumerate(account_name):
+		tax_account = make_tax_account(company, account_name[i], tax_rate[i])
+		if tax_account:
+			accounts.append(tax_account)
+
 	try:
-		if not isinstance(account_name, (list, tuple)):
-			account_name = [account_name]
-			tax_rate = [tax_rate]
-
-		accounts = []
-		for i, name in enumerate(account_name):
-			tax_account = make_tax_account(company, account_name[i], tax_rate[i])
-			if tax_account:
-				accounts.append(tax_account)
-
 		if accounts:
 			make_sales_and_purchase_tax_templates(accounts, template_name)
 	except frappe.NameError:
-		pass
+		frappe.message_log.pop()
 	except RootNotEditable:
 		pass
 
 def make_tax_account(company, account_name, tax_rate):
 	tax_group = get_tax_account_group(company)
 	if tax_group:
-		return frappe.get_doc({
-			"doctype":"Account",
-			"company": company,
-			"parent_account": tax_group,
-			"account_name": account_name,
-			"is_group": 0,
-			"report_type": "Balance Sheet",
-			"root_type": "Liability",
-			"account_type": "Tax",
-			"tax_rate": flt(tax_rate) if tax_rate else None
-		}).insert(ignore_permissions=True, ignore_mandatory=True)
+		try:
+			return frappe.get_doc({
+				"doctype":"Account",
+				"company": company,
+				"parent_account": tax_group,
+				"account_name": account_name,
+				"is_group": 0,
+				"report_type": "Balance Sheet",
+				"root_type": "Liability",
+				"account_type": "Tax",
+				"tax_rate": flt(tax_rate) if tax_rate else None
+			}).insert(ignore_permissions=True, ignore_mandatory=True)
+		except frappe.NameError:
+			frappe.message_log.pop()
+			abbr = frappe.db.get_value('Company', company, 'abbr')
+			account = '{0} - {1}'.format(account_name, abbr)
+			return frappe.get_doc('Account', account)
 
 def make_sales_and_purchase_tax_templates(accounts, template_name=None):
 	if not template_name:
@@ -62,7 +68,7 @@
 
 	for account in accounts:
 		sales_tax_template['taxes'].append({
-			"category": "Valuation and Total",
+			"category": "Total",
 			"charge_type": "On Net Total",
 			"account_head": account.name,
 			"description": "{0} @ {1}".format(account.account_name, account.tax_rate),
diff --git a/erpnext/shopping_cart/product_info.py b/erpnext/shopping_cart/product_info.py
index 8015c48..6f9c8ac 100644
--- a/erpnext/shopping_cart/product_info.py
+++ b/erpnext/shopping_cart/product_info.py
@@ -30,10 +30,10 @@
 	product_info = {
 		"price": price,
 		"stock_qty": stock_status.stock_qty,
-		"in_stock": stock_status.in_stock,
+		"in_stock": stock_status.in_stock if stock_status.is_stock_item else 1,
 		"qty": 0,
 		"uom": frappe.db.get_value("Item", item_code, "stock_uom"),
-		"show_stock_qty": show_quantity_in_website()
+		"show_stock_qty": show_quantity_in_website() if stock_status.is_stock_item else 0
 	}
 
 	if product_info["price"]:
diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py
index 0c94cd8..5578546 100644
--- a/erpnext/shopping_cart/test_shopping_cart.py
+++ b/erpnext/shopping_cart/test_shopping_cart.py
@@ -128,7 +128,7 @@
 			"contact_email": frappe.session.user,
 			"selling_price_list": "_Test Price List Rest of the World",
 			"currency": "USD",
-			"taxes_and_charges" : "_Test Tax 1",
+			"taxes_and_charges" : "_Test Tax 1 - _TC",
 			"conversion_rate":1,
 			"transaction_date" : nowdate(),
 			"valid_till" : add_months(nowdate(), 1),
@@ -136,7 +136,7 @@
 				"item_code": "_Test Item",
 				"qty": 1
 			}],
-			"taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1").taxes,
+			"taxes": frappe.get_doc("Sales Taxes and Charges Template", "_Test Tax 1 - _TC").taxes,
 			"company": "_Test Company"
 		}
 
diff --git a/erpnext/stock/dashboard/item_dashboard.js b/erpnext/stock/dashboard/item_dashboard.js
index 3c334c4..23820d3 100644
--- a/erpnext/stock/dashboard/item_dashboard.js
+++ b/erpnext/stock/dashboard/item_dashboard.js
@@ -89,7 +89,7 @@
 		data.forEach(function(d) {
 			d.actual_or_pending = d.projected_qty + d.reserved_qty + d.reserved_qty_for_production;
 			d.pending_qty = 0;
-			d.total_reserved = d.reserved_qty + d.reserved_qty_for_production;
+			d.total_reserved = d.reserved_qty + d.reserved_qty_for_production + d.reserved_qty_for_sub_contract;
 			if(d.actual_or_pending > d.actual_qty) {
 				d.pending_qty = d.actual_or_pending - d.actual_qty;
 			}
diff --git a/erpnext/stock/dashboard/item_dashboard.py b/erpnext/stock/dashboard/item_dashboard.py
index 0d75a9a..f95daaf 100644
--- a/erpnext/stock/dashboard/item_dashboard.py
+++ b/erpnext/stock/dashboard/item_dashboard.py
@@ -26,13 +26,14 @@
 	return frappe.db.sql('''
 	select
 		b.item_code, b.warehouse, b.projected_qty, b.reserved_qty,
-		b.reserved_qty_for_production, b.actual_qty, b.valuation_rate, i.item_name
+		b.reserved_qty_for_production, b.reserved_qty_for_sub_contract, b.actual_qty, b.valuation_rate, i.item_name
 	from
 		tabBin b, tabItem i
 	where
 		b.item_code = i.name
 		and
-		(b.projected_qty != 0 or b.reserved_qty != 0 or b.reserved_qty_for_production != 0 or b.actual_qty != 0)
+		(b.projected_qty != 0 or b.reserved_qty != 0 or b.reserved_qty_for_production != 0 
+		or b.reserved_qty_for_sub_contract != 0 or b.actual_qty != 0)
 		{conditions}
 	order by
 		{sort_by} {sort_order}
diff --git a/erpnext/stock/doctype/bin/bin.json b/erpnext/stock/doctype/bin/bin.json
index 1f6e9e1..def817b 100644
--- a/erpnext/stock/doctype/bin/bin.json
+++ b/erpnext/stock/doctype/bin/bin.json
@@ -302,6 +302,36 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "reserved_qty_for_sub_contract", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Reserved Qty for sub contract", 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "ma_rate", 
    "fieldtype": "Float", 
    "hidden": 1, 
@@ -463,7 +493,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-06-13 13:06:32.601505", 
+ "modified": "2017-11-22 08:14:30.615638", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Bin", 
diff --git a/erpnext/stock/doctype/bin/bin.py b/erpnext/stock/doctype/bin/bin.py
index fbbe6ee..fd34423 100644
--- a/erpnext/stock/doctype/bin/bin.py
+++ b/erpnext/stock/doctype/bin/bin.py
@@ -64,7 +64,7 @@
 	def set_projected_qty(self):
 		self.projected_qty = (flt(self.actual_qty) + flt(self.ordered_qty)
 			+ flt(self.indented_qty) + flt(self.planned_qty) - flt(self.reserved_qty)
-			- flt(self.reserved_qty_for_production))
+			- flt(self.reserved_qty_for_production) - flt(self.reserved_qty_for_sub_contract))
 
 	def get_first_sle(self):
 		sle = frappe.db.sql("""
@@ -93,6 +93,42 @@
 		self.db_set('reserved_qty_for_production', flt(self.reserved_qty_for_production))
 		self.db_set('projected_qty', self.projected_qty)
 
+	def update_reserved_qty_for_sub_contracting(self):
+		#reserved qty
+		reserved_qty_for_sub_contract = frappe.db.sql('''
+			select ifnull(sum(itemsup.required_qty),0)
+			from `tabPurchase Order` po, `tabPurchase Order Item Supplied` itemsup
+			where
+				itemsup.rm_item_code = %s
+				and itemsup.parent = po.name
+				and po.docstatus = 1
+				and po.is_subcontracted = 'Yes'
+				and po.status != 'Closed'
+				and po.per_received < 100
+				and itemsup.reserve_warehouse = %s''', (self.item_code, self.warehouse))[0][0]
+
+		#Get Transferred Entries
+		materials_transferred = frappe.db.sql("""
+			select
+				ifnull(sum(transfer_qty),0)
+			from
+				`tabStock Entry` se, `tabStock Entry Detail` sed, `tabPurchase Order` po
+			where
+				se.docstatus=1
+				and se.purpose='Subcontract'
+				and ifnull(se.purchase_order, '') !=''
+				and sed.item_code = %s
+				and se.name = sed.parent
+				and se.purchase_order = po.name
+				and po.docstatus = 1
+				and po.is_subcontracted = 'Yes'
+				and po.status != 'Closed'
+				and po.per_received < 100
+		""", (self.item_code))[0][0]
+
+		self.db_set('reserved_qty_for_sub_contract', (reserved_qty_for_sub_contract - materials_transferred))
+		self.set_projected_qty()
+		self.db_set('projected_qty', self.projected_qty)
 
 def update_item_projected_qty(item_code):
 	'''Set total_projected_qty in Item as sum of projected qty in all warehouses'''
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.json b/erpnext/stock/doctype/delivery_note/delivery_note.json
index 1f944e4..0e6bf16 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.json
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.json
@@ -2439,6 +2439,95 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "payment_terms_template_section", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "payment_terms_template", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Payment Terms Template", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Payment Terms Template", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "terms_section", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_bulk_edit": 0, 
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "tc_name", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -3641,7 +3730,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2017-11-29 14:13:32.770027", 
+ "modified": "2018-01-02 09:24:54.746875", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note", 
diff --git a/erpnext/stock/doctype/delivery_note/test_delivery_note.js b/erpnext/stock/doctype/delivery_note/test_delivery_note.js
index bbc97b8..3f6e8d1 100644
--- a/erpnext/stock/doctype/delivery_note/test_delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/test_delivery_note.js
@@ -15,7 +15,7 @@
 				]},
 				{shipping_address_name: 'Test1-Shipping'},
 				{contact_person: 'Contact 1-Test Customer 1'},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{transporter_name:'TEST TRANSPORT'},
 				{lr_no:'MH-04-FG 1111'}
diff --git a/erpnext/stock/doctype/packing_slip/packing_slip.py b/erpnext/stock/doctype/packing_slip/packing_slip.py
index ec5392f..b99215c 100644
--- a/erpnext/stock/doctype/packing_slip/packing_slip.py
+++ b/erpnext/stock/doctype/packing_slip/packing_slip.py
@@ -137,10 +137,10 @@
 
 		for d in self.get("items"):
 			res = frappe.db.get_value("Item", d.item_code,
-				["net_weight", "weight_uom"], as_dict=True)
+				["weight_per_unit", "weight_uom"], as_dict=True)
 
 			if res and len(res)>0:
-				d.net_weight = res["net_weight"]
+				d.net_weight = res["weight_per_unit"]
 				d.weight_uom = res["weight_uom"]
 
 	def get_recommended_case_no(self):
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
index 29f3553..fb12f19 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py
@@ -121,8 +121,10 @@
 		if self.per_billed < 100:
 			self.update_billing_status()
 
+		
 		# Updating stock ledger should always be called after updating prevdoc status,
-		# because updating ordered qty in bin depends upon updated ordered qty in PO
+		# because updating ordered qty, reserved_qty_for_subcontract in bin
+		# depends upon updated ordered qty in PO
 		self.update_stock_ledger()
 
 		from erpnext.stock.doctype.serial_no.serial_no import update_serial_nos_after_submit
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.js
index 0b3fcc9..d1f4485 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.js
@@ -17,7 +17,7 @@
 						{'rejected_warehouse':'Work In Progress - '+frappe.get_abbr(frappe.defaults.get_default('Company'))},
 					]
 				]},
-				{taxes_and_charges: 'TEST In State GST'},
+				{taxes_and_charges: 'TEST In State GST - FT'},
 				{tc_name: 'Test Term 1'},
 				{terms: 'This is Test'}
 			]);
@@ -27,7 +27,7 @@
 			// get_item_details
 			assert.ok(cur_frm.doc.items[0].item_name=='Test Product 1', "Item name correct");
 			// get tax details
-			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST', "Tax details correct");
+			assert.ok(cur_frm.doc.taxes_and_charges=='TEST In State GST - FT', "Tax details correct");
 			// get tax account head details
 			assert.ok(cur_frm.doc.taxes[0].account_head=='CGST - '+frappe.get_abbr(frappe.defaults.get_default('Company')), " Account Head abbr correct");
 			// grand_total Calculated
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 6a6c667..3af8d4e 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -11,6 +11,7 @@
 from erpnext.stock.get_item_details import get_bin_details, get_default_cost_center, get_conversion_factor
 from erpnext.stock.doctype.batch.batch import get_batch_no, set_batch_nos, get_batch_qty
 from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
+from erpnext.stock.utils import get_bin
 import json
 
 class IncorrectValuationRateError(frappe.ValidationError): pass
@@ -69,11 +70,15 @@
 		update_serial_nos_after_submit(self, "items")
 		self.update_production_order()
 		self.validate_purchase_order()
+		if self.purchase_order and self.purpose == "Subcontract":
+			self.update_purchase_order_supplied_items()
 		self.make_gl_entries()
 
 	def on_cancel(self):
 		self.update_stock_ledger()
 		self.update_production_order()
+		if self.purchase_order and self.purpose == "Subcontract":
+			self.update_purchase_order_supplied_items()
 		self.make_gl_entries_on_cancel()
 
 	def validate_purpose(self):
@@ -581,19 +586,31 @@
 						frappe.throw(_("Manufacturing Quantity is mandatory"))
 
 					item_dict = self.get_bom_raw_materials(self.fg_completed_qty)
+
+					#Get PO Supplied Items Details
+					if self.purchase_order and self.purpose == "Subcontract":
+						#Get PO Supplied Items Details
+						item_wh = frappe._dict(frappe.db.sql("""
+							select rm_item_code, reserve_warehouse 
+							from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
+							where po.name = poitemsup.parent
+								and po.name = %s""",self.purchase_order))
 					for item in item_dict.values():
 						if self.pro_doc and not self.pro_doc.skip_transfer:
 							item["from_warehouse"] = self.pro_doc.wip_warehouse
-
+						#Get Reserve Warehouse from PO
+						item["from_warehouse"] = item_wh.get(item.item_code)
 						item["to_warehouse"] = self.to_warehouse if self.purpose=="Subcontract" else ""
 
 					self.add_to_stock_entry_detail(item_dict)
 
-					scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
-					for item in scrap_item_dict.values():
-						if self.pro_doc and self.pro_doc.scrap_warehouse:
-							item["to_warehouse"] = self.pro_doc.scrap_warehouse
-					self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
+					if self.purpose != "Subcontract":
+						scrap_item_dict = self.get_bom_scrap_material(self.fg_completed_qty)
+						for item in scrap_item_dict.values():
+							if self.pro_doc and self.pro_doc.scrap_warehouse:
+								item["to_warehouse"] = self.pro_doc.scrap_warehouse
+
+						self.add_to_stock_entry_detail(scrap_item_dict, bom_no=self.bom_no)
 
 			# fetch the serial_no of the first stock entry for the second stock entry
 			if self.production_order and self.purpose == "Manufacture":
@@ -830,9 +847,23 @@
 					expiry_date = frappe.db.get_value("Batch", item.batch_no, "expiry_date")
 					if expiry_date:
 						if getdate(self.posting_date) > getdate(expiry_date):
-							frappe.throw(_("Batch {0} of Item {1} has expired.").format(item.batch_no, item.item_code))
+							frappe.throw(_("Batch {0} of Item {1} has expired.")
+								.format(item.batch_no, item.item_code))
 
+	def update_purchase_order_supplied_items(self):
+		#Get PO Supplied Items Details
+		item_wh = frappe._dict(frappe.db.sql("""
+			select rm_item_code, reserve_warehouse 
+			from `tabPurchase Order` po, `tabPurchase Order Item Supplied` poitemsup
+			where po.name = poitemsup.parent
+			and po.name = %s""", self.purchase_order))
 
+		#Update reserved sub contracted quantity in bin based on Supplied Item Details
+		for d in self.get("items"):
+			reserve_warehouse = item_wh.get(d.item_code)
+			stock_bin = get_bin(d.item_code, reserve_warehouse)
+			stock_bin.update_reserved_qty_for_sub_contracting()
+	
 @frappe.whitelist()
 def move_sample_to_retention_warehouse(company, items):
 	if isinstance(items, basestring):
@@ -843,7 +874,8 @@
 	stock_entry.purpose = "Material Transfer"
 	for item in items:
 		if item.get('sample_quantity') and item.get('batch_no'):
-			sample_quantity = validate_sample_quantity(item.get('item_code'), item.get('sample_quantity'), item.get('transfer_qty') or item.get('qty'), item.get('batch_no'))
+			sample_quantity = validate_sample_quantity(item.get('item_code'), item.get('sample_quantity'),
+				item.get('transfer_qty') or item.get('qty'), item.get('batch_no'))
 			if sample_quantity:
 				sample_serial_nos = ''
 				if item.get('serial_no'):
@@ -851,6 +883,7 @@
 					if serial_nos and len(serial_nos) > item.get('sample_quantity'):
 						serial_no_list = serial_nos[:-(len(serial_nos)-item.get('sample_quantity'))]
 						sample_serial_nos = '\n'.join(serial_no_list)
+
 				stock_entry.append("items", {
 					"item_code": item.get('item_code'),
 					"s_warehouse": item.get('t_warehouse'),
diff --git a/erpnext/stock/page/stock_balance/stock_balance.js b/erpnext/stock/page/stock_balance/stock_balance.js
index 16a85fa..85ea5b1 100644
--- a/erpnext/stock/page/stock_balance/stock_balance.js
+++ b/erpnext/stock/page/stock_balance/stock_balance.js
@@ -48,6 +48,7 @@
 				{fieldname: 'projected_qty', label: __('Projected qty')},
 				{fieldname: 'reserved_qty', label: __('Reserved for sale')},
 				{fieldname: 'reserved_qty_for_production', label: __('Reserved for manufacturing')},
+				{fieldname: 'reserved_qty_for_sub_contract', label: __('Reserved for sub contracting')},
 				{fieldname: 'actual_qty', label: __('Actual qty in stock')},
 			]
 		},
diff --git a/erpnext/stock/report/item_price_stock/item_price_stock.py b/erpnext/stock/report/item_price_stock/item_price_stock.py
index 95cf3db..4cd8fdd 100644
--- a/erpnext/stock/report/item_price_stock/item_price_stock.py
+++ b/erpnext/stock/report/item_price_stock/item_price_stock.py
@@ -37,9 +37,10 @@
 		from `tabItem Price` a left join `tabBin` b
 		ON a.item_code = b.item_code
 		{conditions}"""
-		.format(conditions=conditions),filters,as_dict=1)
+		.format(conditions=conditions), filters, as_dict=1)
 
-	price_list_names = ",".join(['"' + item['price_list_name'] + '"' for item in item_results])
+	price_list_names = ",".join(['"' + frappe.db.escape(item['price_list_name']) + '"'
+		for item in item_results])
 
 	buying_price_map = get_buying_price_map(price_list_names)
 	selling_price_map = get_selling_price_map(price_list_names)
@@ -66,7 +67,8 @@
 			`tabItem Price`
 		where
 			name in ({price_list_names}) and buying=1
-		""".format(price_list_names=price_list_names),as_dict=1)
+		""".format(price_list_names=price_list_names), as_dict=1)
+
 	buying_price_map = {}
 	for d in buying_price:
 		name = d["name"]
@@ -84,7 +86,8 @@
 			`tabItem Price`
 		where
 			name in ({price_list_names}) and selling=1
-		""".format(price_list_names=price_list_names),as_dict=1)
+		""".format(price_list_names=price_list_names), as_dict=1)
+
 	selling_price_map = {}
 	for d in selling_price:
 		name = d["name"]
diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
index 21287b9..89a256c 100644
--- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
+++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
@@ -16,6 +16,7 @@
 		_("UOM") + ":Link/UOM:100", _("Actual Qty") + ":Float:100", _("Planned Qty") + ":Float:100",
 		_("Requested Qty") + ":Float:110", _("Ordered Qty") + ":Float:100",
 		_("Reserved Qty") + ":Float:100", _("Reserved Qty for Production") + ":Float:100",
+		_("Reserved for sub contracting") + ":Float:100",
 		_("Projected Qty") + ":Float:100", _("Reorder Level") + ":Float:100", _("Reorder Qty") + ":Float:100",
 		_("Shortage Qty") + ":Float:100"]
 
@@ -33,7 +34,8 @@
 			continue
 
 		# item = item_map.setdefault(bin.item_code, get_item(bin.item_code))
-		company = warehouse_company.setdefault(bin.warehouse, frappe.db.get_value("Warehouse", bin.warehouse, "company"))
+		company = warehouse_company.setdefault(bin.warehouse,
+			frappe.db.get_value("Warehouse", bin.warehouse, "company"))
 
 		if filters.brand and filters.brand != item.brand:
 			continue
@@ -52,7 +54,8 @@
 
 		data.append([item.name, item.item_name, item.description, item.item_group, item.brand, bin.warehouse,
 			item.stock_uom, bin.actual_qty, bin.planned_qty, bin.indented_qty, bin.ordered_qty,
-			bin.reserved_qty, bin.reserved_qty_for_production, bin.projected_qty, re_order_level, re_order_qty, shortage_qty])
+			bin.reserved_qty, bin.reserved_qty_for_production, bin.reserved_qty_for_sub_contract,
+			bin.projected_qty, re_order_level, re_order_qty, shortage_qty])
 
 	return data
 
@@ -71,7 +74,7 @@
 				warehouse_details.rgt))
 
 	bin_list = frappe.db.sql("""select item_code, warehouse, actual_qty, planned_qty, indented_qty,
-		ordered_qty, reserved_qty, reserved_qty_for_production, projected_qty
+		ordered_qty, reserved_qty, reserved_qty_for_production, reserved_qty_for_sub_contract, projected_qty
 		from tabBin bin {conditions} order by item_code, warehouse
 		""".format(conditions=" where " + " and ".join(conditions) if conditions else ""), as_dict=1)
 
diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py
index 6a4ac43..49909d9 100644
--- a/erpnext/stock/stock_balance.py
+++ b/erpnext/stock/stock_balance.py
@@ -150,7 +150,7 @@
 	if mismatch:
 		bin.projected_qty = (flt(bin.actual_qty) + flt(bin.ordered_qty) +
 			flt(bin.indented_qty) + flt(bin.planned_qty) - flt(bin.reserved_qty)
-			- flt(bin.reserved_qty_for_production))
+			- flt(bin.reserved_qty_for_production)) - flt(bin.reserved_qty_for_sub_contract)
 
 		bin.save()
 
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 93dadaa..9f9d6ac 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -64,7 +64,7 @@
 			// then chose the closest available one
 
 			var attribute = $(this).attr("data-attribute");
-			var attribute_value = $(this).val()
+			var attribute_value = $(this).val();
 			var item_code = find_closest_match(attribute, attribute_value);
 
 			if (!item_code) {
diff --git a/erpnext/templates/includes/products_as_grid.html b/erpnext/templates/includes/products_as_grid.html
index b2437d3..4a9692a 100644
--- a/erpnext/templates/includes/products_as_grid.html
+++ b/erpnext/templates/includes/products_as_grid.html
@@ -5,7 +5,7 @@
 		<div class="product-image-img">
 			{{ product_image_square(thumbnail or website_image) }}
 			<div class="product-text" itemprop="name">{{ item_name }}</div>
-			{% if in_stock %}
+			{% if in_stock or not is_stock_item %}
 				<div style='color: green'> <i class='fa fa-check'></i> {{ _("In stock") }}</div>
 			{% else %}
 				<div style='color: red'> <i class='fa fa-close'></i> {{ _("Not in stock") }}</div>
diff --git a/erpnext/utilities/page/leaderboard/leaderboard.py b/erpnext/utilities/page/leaderboard/leaderboard.py
index 6e7eabc..58d480e 100644
--- a/erpnext/utilities/page/leaderboard/leaderboard.py
+++ b/erpnext/utilities/page/leaderboard/leaderboard.py
@@ -34,7 +34,8 @@
 	x = frappe.get_list(doctype, filters=filters, limit_start=start, limit_page_length=limit)
 
 	for val in x:
-		y = dict(frappe.db.sql('''select name, grand_total from `tabSales Invoice` where customer = %s''', (val.name)))
+		y = dict(frappe.db.sql('''select name, grand_total from `tabSales Invoice`\
+			where customer = %s and docstatus != 2''', (val.name)))
 		invoice_list = y.keys()
 		if len(invoice_list) > 0:
 			item_count = frappe.db.sql('''select count(name) from `tabSales Invoice Item` where parent in (%s)''' % ", ".join(
diff --git a/erpnext/utilities/product.py b/erpnext/utilities/product.py
index 10366be..9d5c056 100644
--- a/erpnext/utilities/product.py
+++ b/erpnext/utilities/product.py
@@ -9,7 +9,7 @@
 
 def get_qty_in_stock(item_code, item_warehouse_field):
 	in_stock, stock_qty = 0, ''
-	template_item_code = frappe.db.get_value("Item", item_code, "variant_of")
+	template_item_code, is_stock_item = frappe.db.get_value("Item", item_code, ["variant_of", "is_stock_item"])
 
 	warehouse = frappe.db.get_value("Item", item_code, item_warehouse_field)
 	if not warehouse and template_item_code and template_item_code != item_code:
@@ -21,7 +21,7 @@
 		if stock_qty:
 			in_stock = stock_qty[0][0] > 0 and 1 or 0
 
-	return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty})
+	return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item})
 
 def get_price(item_code, price_list, customer_group, company, qty=1):
 	template_item_code = frappe.db.get_value("Item", item_code, "variant_of")