resolved merge conflicts
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index 448cc83..ac19690 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -169,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/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/report/sales_partners_commission/sales_partners_commission.json b/erpnext/accounts/report/sales_partners_commission/sales_partners_commission.json
index 9e8670a..a740de3 100644
--- a/erpnext/accounts/report/sales_partners_commission/sales_partners_commission.json
+++ b/erpnext/accounts/report/sales_partners_commission/sales_partners_commission.json
@@ -12,7 +12,7 @@
  "module": "Accounts", 
  "name": "Sales Partners Commission", 
  "owner": "Administrator", 
- "query": "SELECT\n    sales_partner as \"Sales Partner:Link/Sales Partner:150\",\n\tsum(base_net_total) as \"Invoiced Amount (Exculsive Tax):Currency:210\",\n\tsum(total_commission) as \"Total Commission:Currency:150\",\n\tsum(total_commission)*100/sum(base_net_total) as \"Average Commission Rate:Currency:170\"\nFROM\n\t`tabSales Invoice`\nWHERE\n\tdocstatus = 1 and ifnull(base_net_total, 0) > 0 and ifnull(total_commission, 0) > 0\nGROUP BY\n\tsales_partner\nORDER BY\n\t\"Total Commission:Currency:120\"", 
+ "query": "SELECT\n    sales_partner as \"Sales Partner:Link/Sales Partner:150\",\n\tsum(base_net_total) as \"Invoiced Amount (Exclusive Tax):Currency:210\",\n\tsum(total_commission) as \"Total Commission:Currency:150\",\n\tsum(total_commission)*100/sum(base_net_total) as \"Average Commission Rate:Currency:170\"\nFROM\n\t`tabSales Invoice`\nWHERE\n\tdocstatus = 1 and ifnull(base_net_total, 0) > 0 and ifnull(total_commission, 0) > 0\nGROUP BY\n\tsales_partner\nORDER BY\n\t\"Total Commission:Currency:120\"", 
  "ref_doctype": "Sales Invoice", 
  "report_name": "Sales Partners Commission", 
  "report_type": "Query Report", 
@@ -24,4 +24,4 @@
    "role": "Accounts User"
   }
  ]
-}
\ No newline at end of file
+}
diff --git a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js
index a0e56de..068926b 100644
--- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js
+++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.js
@@ -33,8 +33,13 @@
 		},
 		{
 			"fieldname":"is_pos",
-			"label": __("POS?"),
+			"label": __("Show only POS"),
 			"fieldtype": "Check"
-		}
+		},
+		{
+			"fieldname":"payment_detail",
+			"label": __("Show Payment Details"),
+			"fieldtype": "Check"
+		},
 	]
 };
\ No newline at end of file
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 f38f28d..6ce65bf 100644
--- a/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
+++ b/erpnext/accounts/report/sales_payment_summary/sales_payment_summary.py
@@ -14,25 +14,41 @@
 def get_columns():
 	return [
 		_("Date") + ":Date:80",
-		_("Owner") + "::150",
-		_("Payment Mode") + "::140",
+		_("Owner") + ":Data:200",
+		_("Payment Mode") + ":Data:240",
 		_("Sales and Returns") + ":Currency/currency:120",
 		_("Taxes") + ":Currency/currency:120",
-		_("Payments") + ":Currency/currency:120",
-		_("Outstanding Amount") + ":Currency/currency:150",
+		_("Payments") + ":Currency/currency:120"
 	]
 
 def get_sales_payment_data(filters, columns):
-	sales_invoice_data = get_sales_invoice_data(filters)
 	data = []
+	show_payment_detail = False
+
+	sales_invoice_data = get_sales_invoice_data(filters)
 	mode_of_payments = get_mode_of_payments(filters)
+	mode_of_payment_details = get_mode_of_payment_details(filters)
+
+	if filters.get("payment_detail"):
+		show_payment_detail = True
+	else:
+		show_payment_detail = False
+
 	for inv in sales_invoice_data:
-		mode_of_payment = inv["owner"]+cstr(inv["posting_date"])
-		row = [inv.posting_date, inv.owner,", ".join(mode_of_payments.get(mode_of_payment, [])),
-		inv.net_total,
-		inv.total_taxes, (inv.net_total + inv.total_taxes - inv.outstanding_amount),
-		inv.outstanding_amount]
-		data.append(row)
+		owner_posting_date = inv["owner"]+cstr(inv["posting_date"])
+		if show_payment_detail:
+			row = [inv.posting_date, inv.owner," ",inv.net_total,inv.total_taxes, 0]
+			data.append(row)
+			for mop_detail in mode_of_payment_details.get(owner_posting_date,[]):
+				row = [inv.posting_date, inv.owner,mop_detail[0],0,0,mop_detail[1],0]
+				data.append(row)
+		else:
+			total_payment = 0
+			for mop_detail in mode_of_payment_details.get(owner_posting_date,[]):
+				total_payment = total_payment + mop_detail[1]
+			row = [inv.posting_date, inv.owner,", ".join(mode_of_payments.get(owner_posting_date, [])),
+			inv.net_total,inv.total_taxes,total_payment]
+			data.append(row)
 	return data
 
 def get_conditions(filters):
@@ -73,9 +89,17 @@
 			union
 			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 
+			where a.name = c.reference_name
 			and b.name = c.parent
 			and a.name in ({invoice_list_names})
+			union
+			select a.owner, a.posting_date,
+			ifnull(a.voucher_type,'') as mode_of_payment
+			from `tabJournal Entry` a, `tabJournal Entry Account` b
+			where a.name = b.parent
+			and a.docstatus = 1
+			and b.reference_type = "Sales Invoice"
+			and b.reference_name in ({invoice_list_names})
 			""".format(invoice_list_names=invoice_list_names), as_dict=1)
 		for d in inv_mop:
 			mode_of_payments.setdefault(d["owner"]+cstr(d["posting_date"]), []).append(d.mode_of_payment)
@@ -86,4 +110,37 @@
 	return frappe.db.sql("""select a.name
 		from `tabSales Invoice` a
 		where a.docstatus = 1 and {conditions}""".format(conditions=conditions),
-		filters, as_dict=1)
\ No newline at end of file
+		filters, as_dict=1)
+
+def get_mode_of_payment_details(filters):
+	mode_of_payment_details = {}
+	invoice_list = get_invoices(filters)
+	invoice_list_names = ",".join(['"' + invoice['name'] + '"' for invoice in invoice_list])
+	if invoice_list:
+		inv_mop_detail = frappe.db.sql("""select a.owner, a.posting_date,
+			ifnull(b.mode_of_payment, '') as mode_of_payment, sum(b.base_amount) as paid_amount
+			from `tabSales Invoice` a, `tabSales Invoice Payment` b
+			where a.name = b.parent
+			and a.name in ({invoice_list_names})
+			group by a.owner, a.posting_date, mode_of_payment
+			union
+			select a.owner,a.posting_date,
+			ifnull(b.mode_of_payment, '') as mode_of_payment, sum(b.base_paid_amount) as paid_amount
+			from `tabSales Invoice` a, `tabPayment Entry` b,`tabPayment Entry Reference` c
+			where a.name = c.reference_name
+			and b.name = c.parent
+			and a.name in ({invoice_list_names})
+			group by a.owner, a.posting_date, mode_of_payment
+			union
+			select a.owner, a.posting_date,
+			ifnull(a.voucher_type,'') as mode_of_payment, sum(b.credit)
+			from `tabJournal Entry` a, `tabJournal Entry Account` b
+			where a.name = b.parent
+			and a.docstatus = 1
+			and b.reference_type = "Sales Invoice"
+			and b.reference_name in ({invoice_list_names})
+			group by a.owner, a.posting_date, mode_of_payment
+			""".format(invoice_list_names=invoice_list_names), as_dict=1)
+		for d in inv_mop_detail:
+			mode_of_payment_details.setdefault(d["owner"]+cstr(d["posting_date"]), []).append((d.mode_of_payment,d.paid_amount))
+	return mode_of_payment_details
\ No newline at end of file
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index fe8642c..3f12bce 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) {
@@ -284,7 +293,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 a895a54..35ce399 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.json
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.json
@@ -3102,6 +3102,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, 
@@ -3291,9 +3323,9 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
- "max_attachments": 0,
- "modified": "2017-12-21 14:45:34.140128", 
- "modified_by": "Administrator",
+ "max_attachments": 0, 
+ "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 1929476..096b9c6 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:
@@ -183,6 +185,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)
 
@@ -195,6 +200,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)
@@ -208,6 +215,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')
@@ -255,6 +265,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()
+
 def item_last_purchase_rate(name, conversion_rate, item_code, conversion_factor= 1.0):
 	"""get last purchase rate for an item"""
 	if cint(frappe.db.get_single_value("Buying Settings", "disable_fetch_last_purchase_rate")): return
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_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/config/healthcare.py b/erpnext/config/healthcare.py
index f4bf4f7..37d95ad 100644
--- a/erpnext/config/healthcare.py
+++ b/erpnext/config/healthcare.py
@@ -11,7 +11,7 @@
 				{
 					"type": "doctype",
 					"name": "Patient Appointment",
-					"description": _("Patient Appointment"),
+					"label": _("Patient Appointment"),
 				},
 				{
 					"type": "doctype",
@@ -43,7 +43,7 @@
 				{
 					"type": "doctype",
 					"name": "Lab Test",
-					"description": _("Results"),
+					"label": _("Lab Test"),
 				},
 				{
 					"type": "doctype",
@@ -53,7 +53,8 @@
 				{
 					"type": "report",
 					"name": "Lab Test Report",
-					"is_query_report": True
+					"is_query_report": True,
+					"label": _("Lab Test Report"),
 				}
 			]
 		},
@@ -69,7 +70,7 @@
 				{
 					"type": "doctype",
 					"name": "Physician",
-					"label": "Physician",
+					"label": _("Physician"),
 				},
 				{
 					"type": "doctype",
@@ -100,57 +101,57 @@
 				{
 					"type": "doctype",
 					"name": "Medical Department",
-					"label": "Medical Department"
+					"label": _("Medical Department"),
 				},
 				{
 					"type": "doctype",
 					"name": "Appointment Type",
-					"description": _("Appointment Type Master"),
+					"label": _("Appointment Type"),
 				},
 				{
 					"type": "doctype",
 					"name": "Prescription Dosage",
-					"description": _("Prescription Dosage")
+					"label": _("Prescription Dosage")
 				},
 				{
 					"type": "doctype",
 					"name": "Prescription Duration",
-					"description": _("Prescription Period")
+					"label": _("Prescription Duration")
 				},
 				{
 					"type": "doctype",
 					"name": "Complaint",
-					"description": _("Complaint")
+					"label": _("Complaint")
 				},
 				{
 					"type": "doctype",
 					"name": "Diagnosis",
-					"description": _("Diagnosis")
+					"label": _("Diagnosis")
 				},
 				{
 					"type": "doctype",
 					"name": "Lab Test Sample",
-					"description": _("Test Sample Master."),
+					"label": _("Test Sample."),
 				},
 				{
 					"type": "doctype",
 					"name": "Lab Test UOM",
-					"description": _("Lab Test UOM.")
+					"label": _("Lab Test UOM.")
 				},
 				{
 					"type": "doctype",
 					"name": "Antibiotic",
-					"description": _("Antibiotic.")
+					"label": _("Antibiotic.")
 				},
 				{
 					"type": "doctype",
 					"name": "Sensitivity",
-					"description": _("Sensitivity Naming.")
+					"label": _("Sensitivity Naming.")
 				},
 				{
 					"type": "doctype",
 					"name": "Lab Test Template",
-					"description": _("Lab Test Configurations.")
+					"label": _("Lab Test Template.")
 				}
 			]
 		}
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 63e55ee..4b7b43c 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -163,6 +163,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:
@@ -192,8 +197,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):
@@ -213,6 +226,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
 
@@ -264,7 +279,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
@@ -339,7 +354,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()
@@ -381,7 +396,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" \
@@ -400,6 +415,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/controllers/queries.py b/erpnext/controllers/queries.py
index a71a08e..dd95026 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -418,6 +418,6 @@
 			'where (`tabBatch`.expiry_date >= CURDATE() or `tabBatch`.expiry_date IS NULL)'
 
 	if filters and filters.get('item_code'):
-		query += 'where item = %(item_code)s' % filters
+		query += 'and item = %(item_code)s'
 
-	return frappe.db.sql(query)
+	return frappe.db.sql(query, filters)
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/customize-erpnext/articles/making-custom-reports-in-erpnext.md b/erpnext/docs/user/manual/en/customize-erpnext/articles/making-custom-reports-in-erpnext.md
index 3d5174f..5ef4248 100644
--- a/erpnext/docs/user/manual/en/customize-erpnext/articles/making-custom-reports-in-erpnext.md
+++ b/erpnext/docs/user/manual/en/customize-erpnext/articles/making-custom-reports-in-erpnext.md
@@ -6,7 +6,7 @@
 
 Report Builder is an in-built report customization tool in ERPNext. This allows you to define specific fields of the form which shall be added in the report. Also you can set required filters, sorting and give preferred name to report.
 
-<iframe width="660" height="371" src="https://www.youtube.com/embed/y0o5iYZOioU" frameborder="0" allowfullscreen></iframe>
+<iframe width="660" height="371" src="https://www.youtube.com/watch?v=TxJGUNarcQs" frameborder="0" allowfullscreen></iframe>
 
 ### 2. Query Report
 
diff --git a/erpnext/docs/user/manual/en/customize-erpnext/custom-doctype.md b/erpnext/docs/user/manual/en/customize-erpnext/custom-doctype.md
index 33a5857..93abb3e 100644
--- a/erpnext/docs/user/manual/en/customize-erpnext/custom-doctype.md
+++ b/erpnext/docs/user/manual/en/customize-erpnext/custom-doctype.md
@@ -36,7 +36,7 @@
 1. Actions (button)
 1. Attachments or Images
 
-<img alt="Doc fields" class="screenshot" src="/docs/assets/img/setup/customize/doctype-all-fields.png">
+<img alt="Doc fields" class="screenshot" src="/docs/assets/img/setup/customize/Doctype-all-fields.png">
 
 When you add fields, you need to enter the **Type**. **Label** is optional for Section Break and Column Break. **Name** (`fieldname`) is the name of the database table column.
 
@@ -52,13 +52,13 @@
 
 In this table, you should select roles and define permission roles for them for this Doctype.
 
-<img alt="Doctype Permissions" class="screenshot" src="/docs/assets/img/setup/customize/doctype-permissions.png">
+<img alt="Doctype Permissions" class="screenshot" src="/docs/assets/img/setup/customize/Doctype-permissions.png">
 
 #### Save DocType
 
 On saving doctype, you will get pop-up to provide name for this Doctype.
 
-<img alt="Doctype Save" class="screenshot" src="/docs/assets/img/setup/customize/doctype-save.png">
+<img alt="Doctype Save" class="screenshot" src="/docs/assets/img/setup/customize/Doctype-save.png">
 
 #### DocType in System
 
@@ -67,12 +67,12 @@
 
 `Human Resource > Document > Book`
 
-<img alt="Doctype List" class="screenshot" src="/docs/assets/img/setup/customize/doctype-list-view.png">
+<img alt="Doctype List" class="screenshot" src="/docs/assets/img/setup/customize/Doctype-list-view.png">
 
 #### Book master
 
 Using the fields entered, following is the master one book.
 
-<img alt="Doctype Form" class="screenshot" src="/docs/assets/img/setup/customize/doctype-book-added.png">
+<img alt="Doctype Form" class="screenshot" src="/docs/assets/img/setup/customize/Doctype-book-added.png">
 
 {next}
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/student_attendance_tool/test_student_attendance_tool.js b/erpnext/education/doctype/student_attendance_tool/test_student_attendance_tool.js
index 19b32a9..cea0761 100644
--- a/erpnext/education/doctype/student_attendance_tool/test_student_attendance_tool.js
+++ b/erpnext/education/doctype/student_attendance_tool/test_student_attendance_tool.js
@@ -77,7 +77,7 @@
 		() => frappe.set_route('List', 'Student Attendance/List'),
 		() => frappe.timeout(1),
 		() => {
-			assert.equal(($('div.list-item').size() - 1), count, "Attendance list created");
+			assert.equal(cur_list.data.length, count, "Attendance list created");
 		},
 
 		() => done()
diff --git a/erpnext/healthcare/doctype/consultation/consultation.js b/erpnext/healthcare/doctype/consultation/consultation.js
index 8ed01c3..89b8861 100644
--- a/erpnext/healthcare/doctype/consultation/consultation.js
+++ b/erpnext/healthcare/doctype/consultation/consultation.js
@@ -28,7 +28,6 @@
 						age = calculate_age(data.message.dob);
 					}
 					frappe.model.set_value(frm.doctype,frm.docname, "patient_age", age);
-					show_details(data.message);
 				}
 			});
 		}
@@ -144,58 +143,6 @@
 	frappe.new_doc("Vital Signs");
 };
 
-var show_details = function(data){
-	var personal_details = "";
-	var age = null;
-	if(data.dob){
-		age = calculate_age(data.dob);
-		personal_details += "<br><b>Age :</b> " + age;
-	}
-	if(data.sex) personal_details += "<br><b>Gender :</b> " + data.sex;
-	if(data.blood_group) personal_details += "<br><b>Blood group : </b> " + data.blood_group;
-	if(data.occupation) personal_details += "<br><b>Occupation :</b> " + data.occupation;
-	if(data.email) personal_details += "<br><b>Email :</b> " + data.email;
-	if(data.mobile) personal_details += "<br><b>Mobile :</b> " + data.mobile;
-
-	if(personal_details){
-		personal_details = "<div style='padding-left:10px; font-size:13px;' align='left'></br><b class='text-muted'>Personal Details</b>" + personal_details + "</div>";
-	}
-
-	var details = "";
-	if(data.allergies) details +=  "<br><br><b>Allergies : </b> "+  data.allergies;
-	if(data.medication) details +=  "<br><b>Medication : </b> "+  data.medication;
-	if(data.alcohol_current_use) details +=  "<br><br><b>Alcohol use : </b> "+  data.alcohol_current_use;
-	if(data.alcohol_past_use) details +=  "<br><b>Alcohol past use : </b> "+  data.alcohol_past_use;
-	if(data.tobacco_current_use) details +=  "<br><b>Tobacco use : </b> "+  data.tobacco_current_use;
-	if(data.tobacco_past_use) details +=  "<br><b>Tobacco past use : </b> "+  data.tobacco_past_use;
-	if(data.medical_history) details +=  "<br><br><b>Medical history : </b> "+  data.medical_history;
-	if(data.surgical_history) details +=  "<br><b>Surgical history : </b> "+  data.surgical_history;
-	if(data.surrounding_factors) details +=  "<br><br><b>Occupational hazards : </b> "+  data.surrounding_factors;
-	if(data.other_risk_factors) details += "<br><b>Other risk factors : </b> " + data.other_risk_factors;
-	if(data.patient_details) details += "<br><br><b>More info : </b> " + data.patient_details;
-
-	if(details){
-		details = "<div style='padding-left:10px; font-size:13px;' align='left'></br><b class='text-muted'>Patient Details</b>" + details + "</div>";
-	}
-
-	var vitals = "";
-	if(data.temperature) vitals += "<br><b>Temperature :</b> " + data.temperature;
-	if(data.pulse) vitals += ", <b>Pulse :</b> " + data.pulse;
-	if(data.respiratory_rate) vitals += ", <b>Respiratory Rate :</b> " + data.respiratory_rate;
-	if(data.bp) vitals += ", <b>BP :</b> " + data.bp;
-	if(data.bmi) vitals += "<br><b>BMI :</b> " + data.bmi;
-	if(data.nutrition_note) vitals += " (" + data.nutrition_note + ")";
-	if(data.height) vitals += ", <b>Height :</b> " + data.height;
-	if(data.weight) vitals += ", <b>Weight :</b> " + data.weight;
-	if(data.signs_date) vitals += "<br><b>Date :</b> " + data.signs_date;
-
-	if(vitals){
-		vitals = "<div style='padding-left:10px; font-size:13px;' align='left'></br><b class='text-muted'>Vital Signs</b>" + vitals + "<br></div>";
-	}
-	details = personal_details + vitals + details;
-	cur_frm.fields_dict.patient_details_html.$wrapper.html(details);
-};
-
 frappe.ui.form.on("Consultation", "appointment", function(frm){
 	if(frm.doc.appointment){
 		frappe.call({
@@ -266,7 +213,6 @@
 				}
 				frappe.model.set_value(frm.doctype,frm.docname, "patient_age", age);
 				frappe.model.set_value(frm.doctype,frm.docname, "patient_sex", data.message.sex);
-				if(frm.doc.__islocal) show_details(data.message);
 			}
 		});
 	}
diff --git a/erpnext/healthcare/doctype/consultation/consultation.json b/erpnext/healthcare/doctype/consultation/consultation.json
index 1eff21d..184f484 100644
--- a/erpnext/healthcare/doctype/consultation/consultation.json
+++ b/erpnext/healthcare/doctype/consultation/consultation.json
@@ -450,65 +450,6 @@
    "bold": 0, 
    "collapsible": 1, 
    "columns": 0, 
-   "fieldname": "patient_details", 
-   "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": "Patient Details", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "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": 0, 
-   "fieldname": "patient_details_html", 
-   "fieldtype": "HTML", 
-   "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": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 1, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_bulk_edit": 0, 
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
    "fieldname": "sb_symptoms", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -1004,7 +945,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-11-22 14:03:30.434304", 
+ "modified": "2017-12-28 11:25:35.256848", 
  "modified_by": "Administrator", 
  "module": "Healthcare", 
  "name": "Consultation", 
@@ -1036,7 +977,7 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "restrict_to_domain": "Healthcare", 
- "search_fields": "patient, physician, visit_department", 
+ "search_fields": "patient, physician, visit_department, consultation_date, consultation_time", 
  "show_name_in_global_search": 1, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
diff --git a/erpnext/healthcare/doctype/consultation/consultation.py b/erpnext/healthcare/doctype/consultation/consultation.py
index 69d7ecb..809074e 100755
--- a/erpnext/healthcare/doctype/consultation/consultation.py
+++ b/erpnext/healthcare/doctype/consultation/consultation.py
@@ -123,10 +123,10 @@
 def set_subject_field(consultation):
 	subject = "No Diagnosis "
 	if(consultation.diagnosis):
-		subject = "Diagnosis: \n"+ str(consultation.diagnosis)+". "
+		subject = "Diagnosis: "+ str(consultation.diagnosis)+". "
 	if(consultation.drug_prescription):
 		subject +="\nDrug(s) Prescribed. "
 	if(consultation.test_prescription):
-		subject += " Test(s) Prescribed."
+		subject += "\nTest(s) Prescribed."
 
 	return subject
diff --git a/erpnext/healthcare/doctype/lab_test/lab_test.py b/erpnext/healthcare/doctype/lab_test/lab_test.py
index 6fd9535..766491d 100644
--- a/erpnext/healthcare/doctype/lab_test/lab_test.py
+++ b/erpnext/healthcare/doctype/lab_test/lab_test.py
@@ -230,7 +230,7 @@
 def insert_lab_test_to_medical_record(doc):
 	subject = str(doc.test_name)
 	if(doc.test_comment):
-		subject += ", \n"+str(doc.test_comment)
+		subject += ", "+str(doc.test_comment)
 	medical_record = frappe.new_doc("Patient Medical Record")
 	medical_record.patient = doc.patient
 	medical_record.subject = subject
diff --git a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json
index 14c48b8..1dcdbb5 100644
--- a/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json
+++ b/erpnext/healthcare/doctype/patient_appointment/patient_appointment.json
@@ -698,7 +698,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-11-22 16:32:57.240736", 
+ "modified": "2017-12-28 11:26:20.262978", 
  "modified_by": "Administrator", 
  "module": "Healthcare", 
  "name": "Patient Appointment", 
@@ -750,7 +750,7 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "restrict_to_domain": "Healthcare", 
- "search_fields": "patient, physician, appointment_datetime,department", 
+ "search_fields": "patient, physician, department, appointment_date, appointment_time", 
  "show_name_in_global_search": 1, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
diff --git a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json
index 6edc0cc..8aa4ede 100644
--- a/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json
+++ b/erpnext/healthcare/doctype/patient_medical_record/patient_medical_record.json
@@ -186,7 +186,7 @@
    "read_only": 0, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -389,7 +389,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2017-11-15 12:48:59.945615", 
+ "modified": "2017-12-27 14:37:40.468854", 
  "modified_by": "Administrator", 
  "module": "Healthcare", 
  "name": "Patient Medical Record", 
diff --git a/erpnext/healthcare/doctype/vital_signs/vital_signs.py b/erpnext/healthcare/doctype/vital_signs/vital_signs.py
index 436f79f..a42ff02 100644
--- a/erpnext/healthcare/doctype/vital_signs/vital_signs.py
+++ b/erpnext/healthcare/doctype/vital_signs/vital_signs.py
@@ -31,18 +31,18 @@
 		frappe.delete_doc("Patient Medical Record", medical_record_id[0][0])
 
 def set_subject_field(doc):
-	subject = " "
+	subject = ""
 	if(doc.temperature):
-		subject += "Temperature: \n"+ str(doc.temperature)+". "
+		subject += "Temperature: "+ str(doc.temperature)+".\n"
 	if(doc.pulse):
-		subject += "Pulse: \n"+ str(doc.pulse)+". "
+		subject += "Pulse: "+ str(doc.pulse)+".\n"
 	if(doc.respiratory_rate):
-		subject += "Respiratory Rate: \n"+ str(doc.respiratory_rate)+". "
+		subject += "Respiratory Rate: "+ str(doc.respiratory_rate)+".\n"
 	if(doc.bp):
-		subject += "BP: \n"+ str(doc.bp)+". "
+		subject += "BP: "+ str(doc.bp)+".\n"
 	if(doc.bmi):
-		subject += "BMI: \n"+ str(doc.bmi)+". "
+		subject += "BMI: "+ str(doc.bmi)+".\n"
 	if(doc.nutrition_note):
-		subject += "Note: \n"+ str(doc.nutrition_note)+". "
+		subject += "Note: "+ str(doc.nutrition_note)+"."
 
 	return subject
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.js b/erpnext/hr/doctype/salary_slip/test_salary_slip.js
index 43cc27d..06a1c7d 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.js
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.js
@@ -46,7 +46,7 @@
 		() => frappe.timeout(5),
 		() => frappe.set_route('List', 'Salary Slip', 'List'),
 		() => frappe.timeout(2),
-		() => {$('.list-select-all').click();},
+		() => {$('.list-row-checkbox').click();},
 		() => frappe.timeout(2),
 		() => frappe.click_button('Delete'),
 		() => frappe.click_button('Yes'),
diff --git a/erpnext/non_profit/doctype/membership/membership.py b/erpnext/non_profit/doctype/membership/membership.py
index a6be164..db67905 100644
--- a/erpnext/non_profit/doctype/membership/membership.py
+++ b/erpnext/non_profit/doctype/membership/membership.py
@@ -12,6 +12,20 @@
 
 class Membership(Document):
 	def validate(self):
+		member_name = frappe.get_value('Member', dict(email=frappe.session.user))
+
+		if not member_name:
+			user = frappe.get_doc('User', frappe.session.user)
+			member = frappe.get_doc(dict(
+				doctype='Member',
+				email=frappe.session.user,
+				membership_type=self.membership_type,
+				member_name=user.get_fullname()
+			)).insert(ignore_permissions=True)
+			member_name = member.name
+
+		if self.get("__islocal"):
+			self.member = member_name
 
 		# get last membership (if active)
 		last_membership = erpnext.get_last_membership()
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 b7ad866..271701f 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -745,7 +745,7 @@
 		// toggle read only property for conversion factor field if the uom and stock uom are same
 		if(this.frm.get_field('items').grid.fields_map.conversion_factor) {
 			this.frm.fields_dict.items.grid.toggle_enable("conversion_factor",
-				(item.uom != item.stock_uom)? true: false);
+				((item.uom != item.stock_uom) && !frappe.meta.get_docfield(cur_frm.fields_dict.items.grid.doctype, "conversion_factor").read_only)? true: false);
 		}
 
 	},
@@ -1259,13 +1259,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/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js
index e21caad..a974b99 100644
--- a/erpnext/public/js/utils/serial_no_batch_selector.js
+++ b/erpnext/public/js/utils/serial_no_batch_selector.js
@@ -215,7 +215,7 @@
 						in_list_view:1,
 						get_query: function() {
 							return {
-							    filters: {item: me.item_code },
+							    filters: {item_code: me.item_code },
 							    query: 'erpnext.controllers.queries.get_batch_numbers'
 					        };
 						},
@@ -357,4 +357,4 @@
 			}
 		];
 	}
-});
\ No newline at end of file
+});
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/item/item.json b/erpnext/stock/doctype/item/item.json
index 7d18dd6..eb00e5c 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -457,6 +457,7 @@
    "bold": 1, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:doc.__islocal", 
    "fieldname": "standard_rate", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -3453,7 +3454,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 1, 
- "modified": "2017-12-27 15:47:17.039337", 
+ "modified": "2017-12-29 14:18:37.731142", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item", 
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/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/doctype/stock_reconciliation/test_stock_reconciliation.js b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.js
index d4d1a0a..80001d6 100644
--- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.js
+++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.js
@@ -5,6 +5,7 @@
 	let done = assert.async();
 	frappe.run_serially([
 		() => frappe.set_route('List', 'Stock Reconciliation'),
+		() => frappe.timeout(1),
 		() => frappe.click_button('New'),
 		() => cur_frm.set_value('company','For Testing'),
 		() => frappe.click_button('Items'),
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/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/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(