Merge pull request #7691 from bcornwellmott/stock_reports

Stock reports
diff --git a/erpnext/__init__.py b/erpnext/__init__.py
index bc7ef57..a7ae6e1 100644
--- a/erpnext/__init__.py
+++ b/erpnext/__init__.py
@@ -2,7 +2,7 @@
 from __future__ import unicode_literals
 import frappe
 
-__version__ = '7.2.8'
+__version__ = '7.2.21'
 
 def get_default_company(user=None):
 	'''Get default company for user'''
@@ -24,3 +24,18 @@
 	company = get_default_company()
 	if company:
 		return frappe.db.get_value('Company', company, 'default_currency')
+
+def set_perpetual_inventory(enable=1):
+	accounts_settings = frappe.get_doc("Accounts Settings")
+	accounts_settings.auto_accounting_for_stock = enable
+	accounts_settings.save()
+
+def encode_company_abbr(name, company):
+	'''Returns name encoded with company abbreviation'''
+	company_abbr = frappe.db.get_value("Company", company, "abbr")
+	parts = name.rsplit(" - ", 1)
+
+	if parts[-1].lower() != company_abbr.lower():
+		parts.append(company_abbr)
+
+	return " - ".join([parts[0], company_abbr])
diff --git a/erpnext/accounts/doctype/account/account.py b/erpnext/accounts/doctype/account/account.py
index cedaf60..11f376d 100644
--- a/erpnext/accounts/doctype/account/account.py
+++ b/erpnext/accounts/doctype/account/account.py
@@ -3,11 +3,12 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import cstr, cint
+from frappe.utils import cint, fmt_money
 from frappe import throw, _
 from frappe.model.document import Document
 
 class RootNotEditable(frappe.ValidationError): pass
+class BalanceMismatchError(frappe.ValidationError): pass
 
 class Account(Document):
 	nsm_parent_field = 'parent_account'
@@ -162,23 +163,38 @@
 			throw(_("Report Type is mandatory"))
 
 	def validate_warehouse_account(self):
+		'''If perpetual inventory is set, and warehouse is linked,
+		the account balance and stock balance as of now must always match.
+		'''
+		from erpnext.accounts.utils import get_balance_on
+		from erpnext.stock.utils import get_stock_value_on
 		if not cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
 			return
-			
-		if self.account_type == "Stock" and not cint(self.is_group):
-			if not self.warehouse:
-				throw(_("Warehouse is mandatory"))
-				
-			old_warehouse = cstr(frappe.db.get_value("Account", self.name, "warehouse"))
-			if old_warehouse != cstr(self.warehouse):
-				if old_warehouse and frappe.db.exists("Warehouse", old_warehouse):
-					self.validate_warehouse(old_warehouse)
-				if self.warehouse:
-					self.validate_warehouse(self.warehouse)
-					
+
+		if self.account_type == "Stock":
+			if self.is_group == 0 and not self.warehouse:
+				frappe.throw(_("Warehouse is mandatory for non group Accounts of type Stock"))
+
+			if self.warehouse:
+				# company must be same
+				if frappe.get_value('Warehouse', self.warehouse, 'company') != self.company:
+					frappe.throw(_("Warehouse company must be same as Account company"))
+
+				# balance must be same
+				stock_balance = get_stock_value_on(self.warehouse)
+				if self.is_new():
+					account_balance = 0.0
+				else:
+					account_balance = get_balance_on(self.name)
+
+				if account_balance != stock_balance:
+					frappe.throw(_('Account balance ({0}) and stock value ({1}) must be same')\
+						.format(fmt_money(account_balance, self.account_currency),
+							fmt_money(stock_balance, self.account_currency)))
+
 		elif self.warehouse:
 			self.warehouse = None
-	
+
 	def validate_warehouse(self, warehouse):
 		lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
 
diff --git a/erpnext/accounts/doctype/asset/asset.json b/erpnext/accounts/doctype/asset/asset.json
index d093e69..ce12c8e 100644
--- a/erpnext/accounts/doctype/asset/asset.json
+++ b/erpnext/accounts/doctype/asset/asset.json
@@ -21,7 +21,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Asset Name", 
@@ -49,7 +48,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Item Code", 
@@ -73,12 +71,39 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "item_name", 
+   "fieldtype": "Read Only", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Item Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "item_code.item_name", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "asset_category", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Asset Category", 
@@ -108,7 +133,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Status", 
@@ -137,7 +161,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Image", 
@@ -165,7 +188,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -192,7 +214,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -221,7 +242,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Warehouse", 
@@ -250,7 +270,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Existing Asset", 
@@ -278,7 +297,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Purchase Date", 
@@ -306,7 +324,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Supplier", 
@@ -335,7 +352,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Purchase Invoice", 
@@ -364,7 +380,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Disposal Date", 
@@ -392,7 +407,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Journal Entry for Scrap", 
@@ -421,7 +435,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -448,7 +461,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Gross Purchase Amount", 
@@ -478,7 +490,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Expected Value After Useful Life", 
@@ -508,7 +519,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Opening Accumulated Depreciation", 
@@ -537,7 +547,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Value After Depreciation", 
@@ -566,7 +575,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -595,7 +603,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Depreciation Method", 
@@ -624,7 +631,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Number of Depreciations", 
@@ -653,7 +659,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Number of Depreciations Booked", 
@@ -681,7 +686,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Frequency of Depreciation (Months)", 
@@ -710,7 +714,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Next Depreciation Date", 
@@ -738,7 +741,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Depreciation Schedule", 
@@ -766,7 +768,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Depreciation Schedules", 
@@ -795,7 +796,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -825,7 +825,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-18 15:59:19.774500", 
+ "modified": "2017-02-15 01:19:53.498966", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Asset", 
@@ -842,7 +842,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 1, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -859,5 +858,6 @@
  "read_only_onload": 1, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
index abc6eba..11dcfe7 100644
--- a/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
+++ b/erpnext/accounts/doctype/bank_reconciliation/bank_reconciliation.py
@@ -74,6 +74,9 @@
 		clearance_date_updated = False
 		for d in self.get('payment_entries'):
 			if d.clearance_date:
+				if not d.payment_document:
+					frappe.throw(_("Row #{0}: Payment document is required to complete the trasaction"))
+
 				if d.cheque_date and getdate(d.clearance_date) < getdate(d.cheque_date):
 					frappe.throw(_("Row #{0}: Clearance date {1} cannot be before Cheque Date {2}")
 						.format(d.idx, d.clearance_date, d.cheque_date))
diff --git a/erpnext/accounts/doctype/budget/budget.js b/erpnext/accounts/doctype/budget/budget.js
index 6697b17..cadf1e7 100644
--- a/erpnext/accounts/doctype/budget/budget.js
+++ b/erpnext/accounts/doctype/budget/budget.js
@@ -43,9 +43,18 @@
 	},
 
 	budget_against: function(frm) {
+		frm.trigger("set_null_value")
 		frm.trigger("toggle_reqd_fields")
 	},
 
+	set_null_value: function(frm) {
+		if(frm.doc.budget_against == 'Cost Center') {
+			frm.set_value('project', null)
+		} else {
+			frm.set_value('cost_center', null)
+		}
+	},
+
 	toggle_reqd_fields: function(frm) {
 		frm.toggle_reqd("cost_center", frm.doc.budget_against=="Cost Center");
 		frm.toggle_reqd("project", frm.doc.budget_against=="Project");
diff --git a/erpnext/accounts/doctype/budget/budget.py b/erpnext/accounts/doctype/budget/budget.py
index 5fc4fbf..a6348f1 100644
--- a/erpnext/accounts/doctype/budget/budget.py
+++ b/erpnext/accounts/doctype/budget/budget.py
@@ -22,6 +22,7 @@
 			frappe.throw(_("{0} is mandatory").format(self.budget_against))
 		self.validate_duplicate()
 		self.validate_accounts()
+		self.set_null_value()
 
 	def validate_duplicate(self):
 		budget_against_field = frappe.scrub(self.budget_against)
@@ -54,25 +55,31 @@
 				else:
 					account_list.append(d.account)
 
+	def set_null_value(self):
+		if self.budget_against == 'Cost Center':
+			self.project = None
+		else:
+			self.cost_center = None
+
 def validate_expense_against_budget(args):
 	args = frappe._dict(args)
 	if not args.cost_center and not args.project:
 		return
-	for budget_against in [args.project, args.cost_center]:
-		if budget_against \
+	for budget_against in ['project', 'cost_center']:
+		if args.get(budget_against) \
 				and frappe.db.get_value("Account", {"name": args.account, "root_type": "Expense"}):
 
-			if args.project:
-				condition = "and exists(select name from `tabProject` where name=b.project)"
+			if args.project and budget_against == 'project':
+				condition = "and b.project='%s'" % frappe.db.escape(args.project)
 				args.budget_against_field = "Project"
 			
-			elif args.cost_center:
+			elif args.cost_center and budget_against == 'cost_center':
 				cc_lft, cc_rgt = frappe.db.get_value("Cost Center", args.cost_center, ["lft", "rgt"])
 				condition = """and exists(select name from `tabCost Center` 
 					where lft<=%s and rgt>=%s and name=b.cost_center)""" % (cc_lft, cc_rgt)
 				args.budget_against_field = "Cost Center"
-			
-			args.budget_against = budget_against
+
+			args.budget_against = args.get(budget_against)
 
 			budget_records = frappe.db.sql("""
 				select
@@ -88,12 +95,13 @@
 			""".format(condition=condition, 
 				budget_against_field=frappe.scrub(args.get("budget_against_field"))),
 				(args.fiscal_year, args.account), as_dict=True)
-
-			validate_budget_records(args, budget_records)
+				
+			if budget_records:
+				validate_budget_records(args, budget_records)
 
 def validate_budget_records(args, budget_records):
 	for budget in budget_records:
-		if budget.budget_amount:
+		if flt(budget.budget_amount):
 			yearly_action = budget.action_if_annual_budget_exceeded
 			monthly_action = budget.action_if_accumulated_monthly_budget_exceeded
 
diff --git a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.py b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.py
index 752ecda..5b7d73f 100644
--- a/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.py
+++ b/erpnext/accounts/doctype/cheque_print_template/cheque_print_template.py
@@ -35,7 +35,7 @@
 		</span>
 		<span style="top:%(date_dist_from_top_edge)s cm; left:%(date_dist_from_left_edge)scm;
 			position: absolute;">
-			{{doc.reference_date or '' }}
+			{{ frappe.utils.formatdate(doc.reference_date) or '' }}
 		</span>
 		<span style="top:%(acc_no_dist_from_top_edge)scm;left:%(acc_no_dist_from_left_edge)scm;
 			position: absolute;">
diff --git a/erpnext/accounts/doctype/cost_center/cost_center.json b/erpnext/accounts/doctype/cost_center/cost_center.json
index f590b5d..9aaaed2 100644
--- a/erpnext/accounts/doctype/cost_center/cost_center.json
+++ b/erpnext/accounts/doctype/cost_center/cost_center.json
@@ -278,14 +278,14 @@
  "icon": "fa fa-money", 
  "idx": 1, 
  "image_view": 0, 
- "in_create": 1, 
+ "in_create": 0, 
  "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-07 05:20:40.282432", 
+ "modified": "2017-01-30 11:27:36.615323", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Cost Center", 
diff --git a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
index 2ff98da..517a2a3 100644
--- a/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
+++ b/erpnext/accounts/doctype/fiscal_year/fiscal_year.py
@@ -43,11 +43,13 @@
 
 	def on_update(self):
 		check_duplicate_fiscal_year(self)
+		frappe.cache().delete_value("fiscal_years")
 	
 	def on_trash(self):
 		global_defaults = frappe.get_doc("Global Defaults")
 		if global_defaults.current_fiscal_year == self.name:
 			frappe.throw(_("You cannot delete Fiscal Year {0}. Fiscal Year {0} is set as default in Global Settings").format(self.name))
+		frappe.cache().delete_value("fiscal_years")
 
 	def validate_overlap(self):
 		existing_fiscal_years = frappe.db.sql("""select name from `tabFiscal Year`
diff --git a/erpnext/accounts/doctype/gl_entry/gl_entry.py b/erpnext/accounts/doctype/gl_entry/gl_entry.py
index 5773813..ce60298 100644
--- a/erpnext/accounts/doctype/gl_entry/gl_entry.py
+++ b/erpnext/accounts/doctype/gl_entry/gl_entry.py
@@ -18,22 +18,27 @@
 	def validate(self):
 		self.flags.ignore_submit_comment = True
 		self.check_mandatory()
-		self.pl_must_have_cost_center()
-		self.check_pl_account()
-		self.validate_cost_center()
-		self.validate_party()
-		self.validate_currency()
 		self.validate_and_set_fiscal_year()
+		
+		if not self.flags.from_repost:
+			self.pl_must_have_cost_center()
+			self.check_pl_account()
+			self.validate_cost_center()
+			self.validate_party()
+			self.validate_currency()
 
-	def on_update_with_args(self, adv_adj, update_outstanding = 'Yes'):
-		self.validate_account_details(adv_adj)
+
+	def on_update_with_args(self, adv_adj, update_outstanding = 'Yes', from_repost=False):
+		if not from_repost:
+			self.validate_account_details(adv_adj)
+			check_freezing_date(self.posting_date, adv_adj)
+			
 		validate_frozen_account(self.account, adv_adj)
-		check_freezing_date(self.posting_date, adv_adj)
 		validate_balance_type(self.account, adv_adj)
 
 		# Update outstanding amt on against voucher
 		if self.against_voucher_type in ['Journal Entry', 'Sales Invoice', 'Purchase Invoice'] \
-			and self.against_voucher and update_outstanding == 'Yes':
+			and self.against_voucher and update_outstanding == 'Yes' and not from_repost:
 				update_outstanding_amt(self.account, self.party_type, self.party, self.against_voucher_type,
 					self.against_voucher)
 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.js b/erpnext/accounts/doctype/journal_entry/journal_entry.js
index c98e77f..fc261a5 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.js
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.js
@@ -86,9 +86,9 @@
 			};
 		});
 
-		me.frm.set_query("party_type", "accounts", function(doc, cdt, cdn) {
-			return {
-				filters: {"name": ["in", ["Customer", "Supplier"]]}
+		me.frm.set_query("party_type", "accounts", function() {
+			return{
+				query: "erpnext.setup.doctype.party_type.party_type.get_party_type"
 			}
 		});
 
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index a176680..0cf34dd 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -9,6 +9,7 @@
 from erpnext.accounts.utils import get_balance_on, get_account_currency
 from erpnext.setup.utils import get_company_currency
 from erpnext.accounts.party import get_party_account
+from erpnext.hr.doctype.expense_claim.expense_claim import update_reimbursed_amount
 
 class JournalEntry(AccountsController):
 	def __init__(self, arg1, arg2=None):
@@ -45,6 +46,9 @@
 		self.accounts = [account for account in self.accounts
 			if not (account.debit_in_account_currency==0.0 and account.credit_in_account_currency==0.0)]
 
+		if not self.accounts:
+			frappe.throw("Debit or Credit amount is not found in account table")
+
 	def on_submit(self):
 		self.check_credit_limit()
 		self.make_gl_entries()
@@ -375,7 +379,7 @@
 		bank_amount = party_amount = total_amount = 0.0
 		currency = bank_account_currency = party_account_currency = pay_to_recd_from= None
 		for d in self.get('accounts'):
-			if d.party_type and d.party:
+			if d.party_type in ['Customer', 'Supplier'] and d.party:
 				if not pay_to_recd_from:
 					pay_to_recd_from = frappe.db.get_value(d.party_type, d.party,
 						"customer_name" if d.party_type=="Customer" else "supplier_name")
@@ -503,11 +507,9 @@
 
 	def update_expense_claim(self):
 		for d in self.accounts:
-			if d.reference_type=="Expense Claim":
-				amt = frappe.db.sql("""select sum(debit) as amt from `tabJournal Entry Account`
-					where reference_type = "Expense Claim" and
-					reference_name = %s and docstatus = 1""", d.reference_name ,as_dict=1)[0].amt
-				frappe.db.set_value("Expense Claim", d.reference_name , "total_amount_reimbursed", amt)
+			if d.reference_type=="Expense Claim" and d.party:
+				doc = frappe.get_doc("Expense Claim", d.reference_name)
+				update_reimbursed_amount(doc)
 
 	def validate_expense_claim(self):
 		for d in self.accounts:
diff --git a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
index b4bb542..8756ca4 100644
--- a/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/test_journal_entry.py
@@ -171,7 +171,7 @@
 		})
 
 		jv.submit()
-		
+
 	def test_clear_blank_rows(self):
 		je = make_journal_entry("_Test Bank - _TC", "_Test Account Stock Expenses - _TC", 100, save=False)
 		je.append("accounts", {
@@ -180,11 +180,11 @@
 			"credit_in_account_currency": 0,
 			"exchange_rate": 1
 		})
-		
+
 		self.assertEqual(len(je.get("accounts")), 3)
 		je.save()
-		self.assertEqual(len(je.get("accounts")), 2)		
-		
+		self.assertEqual(len(je.get("accounts")), 2)
+
 
 def make_journal_entry(account1, account2, amount, cost_center=None, posting_date=None, exchange_rate=1, save=True, submit=False, project=None):
 	if not cost_center:
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.js b/erpnext/accounts/doctype/payment_entry/payment_entry.js
index d3dbd31..0130366 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.js
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.js
@@ -26,6 +26,12 @@
 			}
 		});
 
+		frm.set_query("party_type", function() {
+			return{
+				query: "erpnext.setup.doctype.party_type.party_type.get_party_type"
+			}
+		});
+
 		frm.set_query("paid_to", function() {
 			var account_types = in_list(["Receive", "Internal Transfer"], frm.doc.payment_type) ?
 	 			["Bank", "Cash"] : party_account_type;
@@ -79,8 +85,13 @@
 		frm.events.show_general_ledger(frm);
 	},
 
+	company: function(frm) {
+		frm.events.hide_unhide_fields(frm);
+		frm.events.set_dynamic_labels(frm);
+	},
+
 	hide_unhide_fields: function(frm) {
-		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
+		var company_currency = frm.doc.company? frappe.get_doc(":Company", frm.doc.company).default_currency: "";
 
 		frm.toggle_display("source_exchange_rate",
 			(frm.doc.paid_amount && frm.doc.paid_from_account_currency != company_currency));
@@ -118,7 +129,7 @@
 	},
 
 	set_dynamic_labels: function(frm) {
-		var company_currency = frappe.get_doc(":Company", frm.doc.company).default_currency;
+		var company_currency = frm.doc.company? frappe.get_doc(":Company", frm.doc.company).default_currency: "";
 
 		frm.set_currency_labels(["base_paid_amount", "base_received_amount", "base_total_allocated_amount",
 			"difference_amount"], company_currency);
@@ -131,6 +142,10 @@
 
 		frm.set_currency_labels(["total_allocated_amount", "unallocated_amount"], party_account_currency);
 
+		var currency_field = (frm.doc.payment_type=="Receive") ? "paid_from_account_currency" : "paid_to_account_currency"
+		frm.set_df_property("total_allocated_amount", "options", currency_field);
+		frm.set_df_property("unallocated_amount", "options", currency_field);
+
 		frm.set_currency_labels(["total_amount", "outstanding_amount", "allocated_amount"],
 			party_account_currency, "references");
 
@@ -741,4 +756,4 @@
 	deductions_remove: function(frm) {
 		frm.events.set_difference_amount(frm);
 	}
-})
\ No newline at end of file
+})
diff --git a/erpnext/accounts/doctype/payment_entry/payment_entry.json b/erpnext/accounts/doctype/payment_entry/payment_entry.json
index c56a83d..c9db47e 100644
--- a/erpnext/accounts/doctype/payment_entry/payment_entry.json
+++ b/erpnext/accounts/doctype/payment_entry/payment_entry.json
@@ -22,6 +22,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Type of Payment", 
@@ -50,6 +51,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Series", 
@@ -79,6 +81,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Payment Type", 
@@ -102,101 +105,13 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
-   "fieldname": "party_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Party Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Customer\nSupplier", 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type", 
-   "fieldname": "party", 
-   "fieldtype": "Dynamic Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Party", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "party_type", 
-   "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_on_submit": 1, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "", 
-   "fieldname": "party_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Party Name", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "column_break_5", 
    "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, 
@@ -225,6 +140,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Posting Date", 
@@ -253,6 +169,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -282,6 +199,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Mode of Payment", 
@@ -303,6 +221,158 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
+   "fieldname": "party_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": "Payment From / To", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "", 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type)", 
+   "fieldname": "party_type", 
+   "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": 1, 
+   "label": "Party Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "DocType", 
+   "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_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type", 
+   "fieldname": "party", 
+   "fieldtype": "Dynamic 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": 1, 
+   "label": "Party", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "party_type", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_11", 
+   "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_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "eval:in_list([\"Receive\", \"Pay\"], doc.payment_type) && doc.party_type", 
+   "description": "", 
+   "fieldname": "party_name", 
+   "fieldtype": "Data", 
+   "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": "Party Name", 
+   "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_on_submit": 0, 
+   "bold": 0, 
    "collapsible": 1, 
    "columns": 0, 
    "fieldname": "payment_accounts_section", 
@@ -311,6 +381,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Accounts", 
@@ -340,6 +411,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Party Balance", 
@@ -369,6 +441,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Paid From", 
@@ -399,6 +472,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Currency", 
@@ -429,6 +503,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Balance", 
@@ -458,6 +533,7 @@
    "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, 
@@ -486,6 +562,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Paid To", 
@@ -516,6 +593,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Currency", 
@@ -546,6 +624,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account Balance", 
@@ -577,6 +656,7 @@
    "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", 
@@ -606,6 +686,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Paid Amount", 
@@ -636,6 +717,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Exchange Rate", 
@@ -665,6 +747,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Paid Amount (Company Currency)", 
@@ -694,6 +777,7 @@
    "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, 
@@ -722,6 +806,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Received Amount", 
@@ -752,6 +837,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Exchange Rate", 
@@ -781,6 +867,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Received Amount (Company Currency)", 
@@ -812,6 +899,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Reference", 
@@ -842,6 +930,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Allocate Payment Amount", 
@@ -871,6 +960,7 @@
    "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 References", 
@@ -901,6 +991,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Writeoff", 
@@ -930,6 +1021,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Allocated Amount", 
@@ -959,6 +1051,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Allocated Amount (Company Currency)", 
@@ -988,6 +1081,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Set Exchange Gain / Loss", 
@@ -1016,6 +1110,7 @@
    "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, 
@@ -1044,6 +1139,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Unallocated Amount", 
@@ -1073,6 +1169,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Difference Amount (Company Currency)", 
@@ -1103,6 +1200,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Difference Amount", 
@@ -1133,6 +1231,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Deductions or Loss", 
@@ -1161,6 +1260,7 @@
    "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 Deductions or Loss", 
@@ -1190,6 +1290,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Transaction ID", 
@@ -1219,6 +1320,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Cheque/Reference No", 
@@ -1247,6 +1349,7 @@
    "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, 
@@ -1275,6 +1378,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Cheque/Reference Date", 
@@ -1304,6 +1408,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Clearance Date", 
@@ -1334,6 +1439,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "More Information", 
@@ -1363,6 +1469,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Project", 
@@ -1392,6 +1499,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Remarks", 
@@ -1420,6 +1528,7 @@
    "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, 
@@ -1447,6 +1556,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Letter Head", 
@@ -1476,6 +1586,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Print Heading", 
@@ -1505,6 +1616,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -1533,6 +1645,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Title", 
@@ -1561,7 +1674,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:33:40.371480", 
+ "modified": "2017-02-17 14:47:05.379934", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Entry", 
@@ -1578,7 +1691,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 1, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1599,7 +1711,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 1, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1614,8 +1725,10 @@
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "show_name_in_global_search": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "title", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
index 6a951a0..272e474 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.js
@@ -6,12 +6,10 @@
 erpnext.accounts.PaymentReconciliationController = frappe.ui.form.Controller.extend({
 	onload: function() {
 		var me = this
-		this.frm.set_query('party_type', function() {
-			return {
-				filters: {
-					"name": ["in", ["Customer", "Supplier"]]
-				}
-			};
+		this.frm.set_query("party_type", function() {
+			return{
+				query: "erpnext.setup.doctype.party_type.party_type.get_party_type"
+			}
 		});
 
 		this.frm.set_query('receivable_payable_account', function() {
diff --git a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
index f77560c..57fce65 100644
--- a/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
+++ b/erpnext/accounts/doctype/payment_reconciliation_payment/payment_reconciliation_payment.json
@@ -22,6 +22,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Reference Type", 
    "length": 0, 
    "no_copy": 0, 
@@ -30,6 +31,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, 
@@ -48,7 +50,8 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Reference_name", 
+   "in_standard_filter": 0, 
+   "label": "Reference Name", 
    "length": 0, 
    "no_copy": 0, 
    "options": "reference_type", 
@@ -57,6 +60,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, 
@@ -75,6 +79,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Posting Date", 
    "length": 0, 
    "no_copy": 0, 
@@ -82,6 +87,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, 
@@ -100,6 +106,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Is Advance", 
    "length": 0, 
    "no_copy": 0, 
@@ -107,6 +114,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, 
@@ -125,6 +133,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Reference Row", 
    "length": 0, 
    "no_copy": 0, 
@@ -132,6 +141,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, 
@@ -150,6 +160,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "", 
    "length": 0, 
    "no_copy": 0, 
@@ -157,6 +168,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, 
@@ -175,6 +187,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Invoice Number", 
    "length": 0, 
    "no_copy": 0, 
@@ -183,6 +196,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -201,6 +215,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -208,6 +223,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, 
@@ -226,6 +242,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Allocated amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -234,6 +251,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -252,6 +270,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "", 
    "length": 0, 
    "no_copy": 0, 
@@ -259,6 +278,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, 
@@ -277,6 +297,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Remark", 
    "length": 0, 
    "no_copy": 0, 
@@ -284,6 +305,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, 
@@ -302,7 +324,7 @@
  "istable": 1, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-08-26 02:08:35.879133", 
+ "modified": "2017-01-30 01:04:22.557237", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Payment Reconciliation Payment", 
@@ -314,5 +336,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
index 04d4ed7..03d0918 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/period_closing_voucher.py
@@ -35,9 +35,9 @@
 	def validate_posting_date(self):
 		from erpnext.accounts.utils import get_fiscal_year, validate_fiscal_year
 
-		validate_fiscal_year(self.posting_date, self.fiscal_year, label=_("Posting Date"), doc=self)
+		validate_fiscal_year(self.posting_date, self.fiscal_year, self.company, label=_("Posting Date"), doc=self)
 
-		self.year_start_date = get_fiscal_year(self.posting_date, self.fiscal_year)[1]
+		self.year_start_date = get_fiscal_year(self.posting_date, self.fiscal_year, company=self.company)[1]
 
 		pce = frappe.db.sql("""select name from `tabPeriod Closing Voucher`
 			where posting_date > %s and fiscal_year = %s and docstatus = 1""",
diff --git a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
index d68e291..9ef66ed 100644
--- a/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
+++ b/erpnext/accounts/doctype/period_closing_voucher/test_period_closing_voucher.py
@@ -11,7 +11,7 @@
 
 class TestPeriodClosingVoucher(unittest.TestCase):
 	def test_closing_entry(self):
-		year_start_date = get_fiscal_year(today())[1]
+		year_start_date = get_fiscal_year(today(), company="_Test Company")[1]
 
 		make_journal_entry("_Test Bank - _TC", "Sales - _TC", 400,
 			"_Test Cost Center - _TC", posting_date=now(), submit=True)
@@ -70,7 +70,7 @@
 			"doctype": "Period Closing Voucher",
 			"closing_account_head": "_Test Account Reserves and Surplus - _TC",
 			"company": "_Test Company",
-			"fiscal_year": get_fiscal_year(today())[0],
+			"fiscal_year": get_fiscal_year(today(), company="_Test Company")[0],
 			"posting_date": today(),
 			"remarks": "test"
 		})
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
index 5a3e651..03bb7ae 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.js
@@ -91,8 +91,8 @@
 }
 
 //Dynamically change the description based on type of margin
-cur_frm.cscript.type = function(doc){
-	cur_frm.set_df_property('rate', 'description', doc.type=='Percentage'?'In Percentage %':'In Amount')
+cur_frm.cscript.margin_type = function(doc){
+	cur_frm.set_df_property('margin_rate_or_amount', 'description', doc.margin_type=='Percentage'?'In Percentage %':'In Amount')
 }
 
 frappe.ui.form.on('Pricing Rule', 'price_or_discount', function(frm){
@@ -112,4 +112,4 @@
 			}
 		}
 	}
-})
\ No newline at end of file
+})
diff --git a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
index 3c62297..c5d2b31 100644
--- a/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
+++ b/erpnext/accounts/doctype/pricing_rule/pricing_rule.py
@@ -123,12 +123,13 @@
 	
 def get_serial_no_for_item(args):
 	from erpnext.stock.get_item_details import get_serial_no
+
 	item_details = frappe._dict({
 		"doctype": args.doctype,
 		"name": args.name,
 		"serial_no": args.serial_no
 	})
-	if args.get("parenttype") in ("Sales Invoice", "Delivery Note"):
+	if args.get("parenttype") in ("Sales Invoice", "Delivery Note") and args.qty > 0:
 		item_details.serial_no = get_serial_no(args)
 	return item_details
 
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
index b6378f1..c322370 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.js
@@ -8,7 +8,7 @@
 erpnext.accounts.PurchaseInvoice = erpnext.buying.BuyingController.extend({
 	onload: function() {
 		this._super();
-		
+
 		if(!this.frm.doc.__islocal) {
 			// show credit_to in print format
 			if(!this.frm.doc.supplier && this.frm.doc.credit_to) {
@@ -32,7 +32,7 @@
 		if(doc.update_stock==1 && doc.docstatus==1) {
 			this.show_stock_ledger();
 		}
-		
+
 		if(!doc.is_return && doc.docstatus==1) {
 			if(doc.outstanding_amount != 0) {
 				this.frm.add_custom_button(__('Payment'), this.make_payment_entry, __("Make"));
@@ -218,18 +218,6 @@
 	}
 }
 
-cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
-	return{
-		filters:{'supplier':  doc.supplier}
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return{
-		filters:{'supplier':  doc.supplier}
-	}
-}
-
 cur_frm.fields_dict['items'].grid.get_field("item_code").get_query = function(doc, cdt, cdn) {
 	return {
 		query: "erpnext.controllers.queries.item_query",
diff --git a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
index 14459fa..c0693d1 100644
--- a/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
+++ b/erpnext/accounts/doctype/purchase_invoice/purchase_invoice.py
@@ -302,11 +302,11 @@
 				asset.flags.ignore_validate_update_after_submit = True
 				asset.save()
 
-	def make_gl_entries(self, repost_future_gle=True):
+	def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
 		if not self.grand_total:
 			return
-		
-		gl_entries = self.get_gl_entries()
+		if not gl_entries:
+			gl_entries = self.get_gl_entries()
 		
 		if gl_entries:
 			update_outstanding = "No" if (cint(self.is_paid) or self.write_off_account) else "Yes"
diff --git a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
index 6f8e219..a91d974 100755
--- a/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
+++ b/erpnext/accounts/doctype/purchase_invoice_item/purchase_invoice_item.json
@@ -1316,6 +1316,34 @@
    "unique": 0
   }, 
   {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "is_sample_item", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Sample Item", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -1788,7 +1816,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-11-16 16:04:52.465169", 
+ "modified": "2017-02-07 01:21:03.737800", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Purchase Invoice Item", 
diff --git a/erpnext/accounts/doctype/sales_invoice/pos.py b/erpnext/accounts/doctype/sales_invoice/pos.py
index f5721e8..070dbeb 100644
--- a/erpnext/accounts/doctype/sales_invoice/pos.py
+++ b/erpnext/accounts/doctype/sales_invoice/pos.py
@@ -30,6 +30,7 @@
 		'doc': doc,
 		'default_customer': pos_profile.get('customer'),
 		'items': get_items_list(pos_profile),
+		'item_groups': get_item_group(pos_profile),
 		'customers': get_customers_list(pos_profile),
 		'serial_no_data': get_serial_no_data(pos_profile, doc.company),
 		'batch_no_data': get_batch_no_data(),
@@ -39,14 +40,21 @@
 		'pricing_rules': get_pricing_rule_data(doc),
 		'print_template': print_template,
 		'pos_profile': pos_profile,
-		'meta': {
-			'invoice': frappe.get_meta('Sales Invoice'),
-			'customer': frappe.get_meta('Customer'),
-			'items': frappe.get_meta('Sales Invoice Item'),
-			'taxes': frappe.get_meta('Sales Taxes and Charges')
-		}
+		'meta': get_meta()
 	}
 
+def get_meta():
+	doctype_meta = {
+		'customer': frappe.get_meta('Customer'),
+		'invoice': frappe.get_meta('Sales Invoice')
+	}
+
+	for row in frappe.get_all('DocField', fields = ['fieldname', 'options'],
+		filters = {'parent': 'Sales Invoice', 'fieldtype': 'Table'}):
+		doctype_meta[row.fieldname] = frappe.get_meta(row.options)
+
+	return doctype_meta
+
 def get_company_data(company):
 	return frappe.get_all('Company', fields = ["*"], filters= {'name': company})[0]
 
@@ -63,10 +71,10 @@
 
 	doc.currency = pos_profile.get('currency') or company_data.default_currency
 	doc.conversion_rate = 1.0
-	
+
 	if doc.currency != company_data.default_currency:
 		doc.conversion_rate = get_exchange_rate(doc.currency, company_data.default_currency, doc.posting_date)
-		
+
 	doc.selling_price_list = pos_profile.get('selling_price_list') or \
 		frappe.db.get_value('Selling Settings', None, 'selling_price_list')
 	doc.naming_series = pos_profile.get('naming_series') or 'SINV-'
@@ -75,6 +83,7 @@
 	doc.apply_discount_on = pos_profile.get('apply_discount_on') if pos_profile.get('apply_discount') else ''
 	doc.customer_group = pos_profile.get('customer_group') or get_root('Customer Group')
 	doc.territory = pos_profile.get('territory') or get_root('Territory')
+	doc.terms = frappe.db.get_value('Terms and Conditions', pos_profile.get('tc_name'), 'terms') or doc.terms or ''
 
 def get_root(table):
 	root = frappe.db.sql(""" select name from `tab%(table)s` having
@@ -132,6 +141,15 @@
 			disabled = 0 and has_variants = 0 and is_sales_item = 1 and {cond}
 		""".format(cond=cond), tuple(item_groups), as_dict=1)
 
+def get_item_group(pos_profile):
+	if pos_profile.get('item_groups'):
+		item_groups = []
+		for d in pos_profile.get('item_groups'):
+			item_groups.extend(get_child_nodes('Item Group', d.item_group))
+		return item_groups
+	else:
+		return frappe.db.sql_list("""Select name from `tabItem Group` order by name""")
+
 def get_customers_list(pos_profile):
 	cond = "1=1"
 	customer_groups = []
@@ -268,11 +286,33 @@
 		customer_doc = frappe.new_doc('Customer')
 		customer_doc.customer_name = doc.get('customer')
 		customer_doc.customer_type = 'Company'
-		customer_doc.customer_group = doc.get('customer_group')
-		customer_doc.territory = doc.get('territory')
+		customer_doc.customer_group = frappe.db.get_single_value('Selling Settings', 'customer_group')
+		customer_doc.territory = frappe.db.get_single_value('Selling Settings', 'territory')
+		customer_doc.flags.ignore_mandatory = True
 		customer_doc.save(ignore_permissions = True)
 		frappe.db.commit()
 		doc['customer'] = customer_doc.name
+		if doc.get('contact_details'):
+			args = json.loads(doc.get("contact_details"))
+			make_address(doc, args, customer_doc.name)
+
+def make_address(doc, args, customer):
+	if args.get("address_line1"):
+		address = frappe.new_doc('Address')
+		address.address_line1 = args.get('address_line1')
+		address.address_line2 = args.get('address_line2')
+		address.city = args.get('city')
+		address.state = args.get('state')
+		address.zip_code = args.get('zip_code')
+		address.email_id = args.get('email_id')
+		address.flags.ignore_mandatory = True
+		address.country = frappe.db.get_value('Company', doc.get('company'), 'country')
+		address.append('links',{
+			'link_doctype': 'Customer',
+			'link_name': customer
+		})
+		address.save(ignore_permissions = True)
+		frappe.db.commit()
 
 def validate_item(doc):
 	for item in doc.get('items'):
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
index 2a07389..4fb3dba 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.json
@@ -6,7 +6,7 @@
  "beta": 0, 
  "creation": "2013-05-24 19:29:05", 
  "custom": 0, 
- "default_print_format": "Standard", 
+ "default_print_format": "Sample Print", 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "", 
@@ -22,7 +22,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -51,7 +50,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Title", 
@@ -79,7 +77,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Series", 
@@ -109,7 +106,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Customer", 
@@ -140,7 +136,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Customer Name", 
@@ -169,7 +164,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is POS", 
@@ -199,7 +193,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Return", 
@@ -227,7 +220,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Offline POS Name", 
@@ -255,7 +247,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -283,7 +274,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Date", 
@@ -312,7 +302,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Payment Due Date", 
@@ -341,7 +330,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -371,7 +359,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Project", 
@@ -401,7 +388,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -432,7 +418,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Return Against Sales Invoice", 
@@ -462,7 +447,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Address and Contact", 
@@ -490,7 +474,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Customer Address", 
@@ -518,7 +501,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Address", 
@@ -545,7 +527,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Contact Person", 
@@ -573,7 +554,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Contact", 
@@ -600,7 +580,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Mobile No", 
@@ -627,7 +606,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Contact Email", 
@@ -655,7 +633,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -682,7 +659,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Shipping Address Name", 
@@ -711,7 +687,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Shipping Address", 
@@ -740,7 +715,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Customer Group", 
@@ -768,7 +742,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Territory", 
@@ -777,7 +750,7 @@
    "options": "Territory", 
    "permlevel": 0, 
    "precision": "", 
-   "print_hide": 0, 
+   "print_hide": 1, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
@@ -798,7 +771,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Currency and Price List", 
@@ -826,7 +798,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Currency", 
@@ -857,7 +828,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Exchange Rate", 
@@ -887,7 +857,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -914,7 +883,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Price List", 
@@ -944,7 +912,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Price List Currency", 
@@ -973,7 +940,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Price List Exchange Rate", 
@@ -1001,7 +967,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Ignore Pricing Rule", 
@@ -1028,7 +993,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -1057,7 +1021,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Update Stock", 
@@ -1086,7 +1049,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Items", 
@@ -1116,7 +1078,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Packing List", 
@@ -1144,7 +1105,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Packed Items", 
@@ -1172,7 +1132,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Product Bundle Help", 
@@ -1201,7 +1160,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Time Sheet List", 
@@ -1229,7 +1187,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Time Sheets", 
@@ -1259,7 +1216,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Billing Amount", 
@@ -1287,7 +1243,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1313,7 +1268,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total (Company Currency)", 
@@ -1342,7 +1296,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Net Total (Company Currency)", 
@@ -1372,7 +1325,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1398,7 +1350,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Net Total", 
@@ -1426,7 +1377,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total", 
@@ -1455,7 +1405,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -1484,7 +1433,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Taxes and Charges", 
@@ -1514,7 +1462,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1540,7 +1487,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Shipping Rule", 
@@ -1569,7 +1515,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1595,7 +1540,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Taxes and Charges", 
@@ -1625,7 +1569,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Taxes and Charges Calculation", 
@@ -1653,7 +1596,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1679,7 +1621,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Taxes and Charges (Company Currency)", 
@@ -1709,7 +1650,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1736,7 +1676,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Taxes and Charges", 
@@ -1765,7 +1704,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Additional Discount", 
@@ -1794,7 +1732,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Apply Additional Discount On", 
@@ -1823,7 +1760,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Additional Discount Amount (Company Currency)", 
@@ -1852,7 +1788,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1878,7 +1813,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Additional Discount Percentage", 
@@ -1906,7 +1840,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Additional Discount Amount", 
@@ -1934,7 +1867,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -1963,7 +1895,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Grand Total (Company Currency)", 
@@ -1993,7 +1924,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Rounded Total (Company Currency)", 
@@ -2024,7 +1954,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "In Words (Company Currency)", 
@@ -2053,7 +1982,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2081,7 +2009,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Grand Total", 
@@ -2111,7 +2038,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Rounded Total", 
@@ -2141,7 +2067,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "In Words", 
@@ -2170,7 +2095,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Advance", 
@@ -2200,7 +2124,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Outstanding Amount", 
@@ -2231,7 +2154,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Advance Payments", 
@@ -2260,7 +2182,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Get Advances Received", 
@@ -2289,7 +2210,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Advances", 
@@ -2321,7 +2241,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Payments", 
@@ -2350,7 +2269,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Cash/Bank Account", 
@@ -2380,7 +2298,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Invoice Payment", 
@@ -2409,7 +2326,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2436,7 +2352,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Paid Amount (Company Currency)", 
@@ -2465,7 +2380,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2493,7 +2407,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Paid Amount", 
@@ -2523,7 +2436,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2550,7 +2462,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Base Change Amount (Company Currency)", 
@@ -2579,7 +2490,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2606,7 +2516,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Change Amount", 
@@ -2635,7 +2544,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account for Change Amount", 
@@ -2666,7 +2574,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off", 
@@ -2695,7 +2602,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Amount", 
@@ -2723,7 +2629,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Amount (Company Currency)", 
@@ -2753,7 +2658,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Outstanding Amount", 
@@ -2781,7 +2685,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -2809,7 +2712,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Account", 
@@ -2838,7 +2740,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Write Off Cost Center", 
@@ -2867,7 +2768,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Terms", 
@@ -2896,7 +2796,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Terms", 
@@ -2926,7 +2825,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Terms and Conditions Details", 
@@ -2955,7 +2853,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Printing Settings", 
@@ -2983,7 +2880,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Letter Head", 
@@ -3013,7 +2909,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Print Language", 
@@ -3041,7 +2936,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -3068,7 +2962,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Print Heading", 
@@ -3099,7 +2992,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "More Information", 
@@ -3128,7 +3020,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Campaign", 
@@ -3158,7 +3049,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -3186,8 +3076,8 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -3214,7 +3104,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Source", 
@@ -3244,7 +3133,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Accounting Details", 
@@ -3274,7 +3162,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Debit To", 
@@ -3304,7 +3191,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Party Account Currency", 
@@ -3335,7 +3221,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Opening Entry", 
@@ -3365,7 +3250,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "C-Form Applicable", 
@@ -3393,7 +3277,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "C-Form No", 
@@ -3421,7 +3304,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -3448,7 +3330,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Posting Time", 
@@ -3477,7 +3358,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Remarks", 
@@ -3507,7 +3387,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Commission", 
@@ -3536,7 +3415,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Partner", 
@@ -3566,7 +3444,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -3594,7 +3471,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Commission Rate (%)", 
@@ -3623,7 +3499,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Commission", 
@@ -3654,7 +3529,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Team", 
@@ -3681,7 +3555,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Team1", 
@@ -3713,7 +3586,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Recurring", 
@@ -3741,7 +3613,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Settings", 
@@ -3771,7 +3642,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Recurring", 
@@ -3800,7 +3670,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Reference Document", 
@@ -3830,7 +3699,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Frequency", 
@@ -3860,7 +3728,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Repeat on Day of Month", 
@@ -3889,7 +3756,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "End Date", 
@@ -3917,7 +3783,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Submit on creation", 
@@ -3947,7 +3812,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Notify by email", 
@@ -3977,7 +3841,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Notification Email Address", 
@@ -4006,7 +3869,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Recurring Print Format", 
@@ -4035,7 +3897,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "This Document", 
@@ -4065,7 +3926,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "From Date", 
@@ -4094,7 +3954,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "To Date", 
@@ -4123,7 +3982,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Next Date", 
@@ -4150,7 +4008,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Against Income Account", 
@@ -4182,7 +4039,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-09 14:18:24.760263", 
+ "modified": "2017-02-02 17:03:01.892758", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice", 
@@ -4198,7 +4055,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -4219,7 +4075,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -4240,7 +4095,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
@@ -4261,7 +4115,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
@@ -4281,5 +4134,6 @@
  "sort_order": "DESC", 
  "timeline_field": "customer", 
  "title_field": "title", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
index db6d594..890641b 100644
--- a/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/sales_invoice.py
@@ -532,10 +532,12 @@
 			if d.delivery_note and frappe.db.get_value("Delivery Note", d.delivery_note, "docstatus") != 1:
 				throw(_("Delivery Note {0} is not submitted").format(d.delivery_note))
 
-	def make_gl_entries(self, repost_future_gle=True):
+	def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
 		if not self.grand_total:
 			return
-		gl_entries = self.get_gl_entries()
+			
+		if not gl_entries:
+			gl_entries = self.get_gl_entries()
 
 		if gl_entries:
 			from erpnext.accounts.general_ledger import make_gl_entries
@@ -651,32 +653,34 @@
 	def make_pos_gl_entries(self, gl_entries):
 		if cint(self.is_pos):
 			for payment_mode in self.payments:
-				# POS, make payment entries
-				gl_entries.append(
-					self.get_gl_dict({
-						"account": self.debit_to,
-						"party_type": "Customer",
-						"party": self.customer,
-						"against": payment_mode.account,
-						"credit": payment_mode.base_amount,
-						"credit_in_account_currency": payment_mode.base_amount \
-							if self.party_account_currency==self.company_currency \
-							else payment_mode.amount,
-						"against_voucher": self.return_against if cint(self.is_return) else self.name,
-						"against_voucher_type": self.doctype,
-					}, self.party_account_currency)
-				)
+				if payment_mode.amount:
+					# POS, make payment entries
+					gl_entries.append(
+						self.get_gl_dict({
+							"account": self.debit_to,
+							"party_type": "Customer",
+							"party": self.customer,
+							"against": payment_mode.account,
+							"credit": payment_mode.base_amount,
+							"credit_in_account_currency": payment_mode.base_amount \
+								if self.party_account_currency==self.company_currency \
+								else payment_mode.amount,
+							"against_voucher": self.return_against if cint(self.is_return) else self.name,
+							"against_voucher_type": self.doctype,
+						}, self.party_account_currency)
+					)
 
-				payment_mode_account_currency = get_account_currency(payment_mode.account)
-				gl_entries.append(
-					self.get_gl_dict({
-						"account": payment_mode.account,
-						"against": self.customer,
-						"debit": payment_mode.base_amount,
-						"debit_in_account_currency": payment_mode.base_amount \
-							if payment_mode_account_currency==self.company_currency else payment_mode.amount
-					}, payment_mode_account_currency)
-				)
+					payment_mode_account_currency = get_account_currency(payment_mode.account)
+					gl_entries.append(
+						self.get_gl_dict({
+							"account": payment_mode.account,
+							"against": self.customer,
+							"debit": payment_mode.base_amount,
+							"debit_in_account_currency": payment_mode.base_amount \
+								if payment_mode_account_currency==self.company_currency \
+								else payment_mode.amount
+						}, payment_mode_account_currency)
+					)
 				
 	def make_gle_for_change_amount(self, gl_entries):
 		if cint(self.is_pos) and self.change_amount:
diff --git a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
index 3eb2f7d..3dfe680 100644
--- a/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
+++ b/erpnext/accounts/doctype/sales_invoice/test_sales_invoice.py
@@ -963,40 +963,6 @@
 		si.insert()
 		self.assertEqual(si.get("items")[0].rate, flt((price_list_rate*25)/100 + price_list_rate))
 
-	def test_party_status(self):
-		from erpnext.accounts.doctype.payment_entry.payment_entry import get_payment_entry
-		from frappe.utils import random_string
-
-		customer_name = 'test customer for status'
-
-		if frappe.db.exists('Customer', customer_name):
-			customer = frappe.get_doc('Customer', customer_name)
-			customer.db_set('status', 'Active')
-		else:
-			customer = frappe.get_doc({
-				'doctype': 'Customer',
-				'customer_name': customer_name,
-				'customer_group': 'Commercial',
-				'customer_type': 'Individual',
-				'territory': 'Rest of the World'
-			}).insert()
-
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
-
-		invoice = create_sales_invoice(customer="test customer for status",
-			debit_to="_Test Receivable - _TC",
-			currency="USD", conversion_rate=50)
-
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Open')
-
-		pe = get_payment_entry(invoice.doctype, invoice.name)
-		pe.reference_no = random_string(10)
-		pe.reference_date = invoice.posting_date
-		pe.insert()
-		pe.submit()
-
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
-
 	def test_outstanding_amount_after_advance_jv_cancelation(self):
 		from erpnext.accounts.doctype.journal_entry.test_journal_entry \
 			import test_records as jv_test_records
diff --git a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
index 944230b..bf6d986 100644
--- a/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
+++ b/erpnext/accounts/doctype/sales_invoice_item/sales_invoice_item.json
@@ -1382,6 +1382,34 @@
    "unique": 0
   }, 
   {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "is_sample_item", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Sample Item", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -1882,7 +1910,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-11-16 16:04:02.438952", 
+ "modified": "2017-02-07 01:21:47.142162", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Sales Invoice Item", 
diff --git a/erpnext/accounts/doctype/tax_rule/tax_rule.py b/erpnext/accounts/doctype/tax_rule/tax_rule.py
index 7ec833e..606d067 100644
--- a/erpnext/accounts/doctype/tax_rule/tax_rule.py
+++ b/erpnext/accounts/doctype/tax_rule/tax_rule.py
@@ -7,6 +7,7 @@
 from frappe import _
 from frappe.model.document import Document
 from frappe.utils import cstr, cint
+from frappe.geo.doctype.address.address import get_default_address
 
 class IncorrectCustomerGroup(frappe.ValidationError): pass
 class IncorrectSupplierType(frappe.ValidationError): pass
@@ -96,27 +97,31 @@
 @frappe.whitelist()
 def get_party_details(party, party_type, args=None):
 	out = {}
+	billing_address, shipping_address = None, None
 	if args:
-		billing_filters=	{"name": args.get("billing_address")}
-		shipping_filters=	{"name": args.get("shipping_address")}
+		if args.get('billing_address'):
+			billing_address = frappe.get_doc('Address', args.get('billing_address'))
+		if args.get('shipping_address'):
+			shipping_address = frappe.get_doc('Address', args.get('shipping_address'))
 	else:
-		billing_filters=	{party_type: party, "is_primary_address": 1}
-		shipping_filters=	{party_type:party, "is_shipping_address": 1}
-
-	billing_address=	frappe.get_all("Address", fields=["city", "county", "state", "country"], filters= billing_filters)
-	shipping_address=	frappe.get_all("Address", fields=["city", "county", "state", "country"], filters= shipping_filters)
+		billing_address_name = get_default_address(party_type, party)
+		shipping_address_name = get_default_address(party_type, party, 'is_shipping_address')
+		if billing_address_name:
+			billing_address = frappe.get_doc('Address', billing_address_name)
+		if shipping_address_name:
+			shipping_address = frappe.get_doc('Address', shipping_address_name)
 
 	if billing_address:
-		out["billing_city"]= billing_address[0].city
-		out["billing_county"]= billing_address[0].county
-		out["billing_state"]= billing_address[0].state
-		out["billing_country"]= billing_address[0].country
+		out["billing_city"]= billing_address.city
+		out["billing_county"]= billing_address.county
+		out["billing_state"]= billing_address.state
+		out["billing_country"]= billing_address.country
 
 	if shipping_address:
-		out["shipping_city"]= shipping_address[0].city
-		out["shipping_county"]= shipping_address[0].county
-		out["shipping_state"]= shipping_address[0].state
-		out["shipping_country"]= shipping_address[0].country
+		out["shipping_city"]= shipping_address.city
+		out["shipping_county"]= shipping_address.county
+		out["shipping_state"]= shipping_address.state
+		out["shipping_country"]= shipping_address.country
 
 	return out
 
diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py
index 392902c..4c5535d 100644
--- a/erpnext/accounts/general_ledger.py
+++ b/erpnext/accounts/general_ledger.py
@@ -11,12 +11,12 @@
 
 class StockAccountInvalidTransaction(frappe.ValidationError): pass
 
-def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes'):
+def make_gl_entries(gl_map, cancel=False, adv_adj=False, merge_entries=True, update_outstanding='Yes', from_repost=False):
 	if gl_map:
 		if not cancel:
 			gl_map = process_gl_map(gl_map, merge_entries)
 			if gl_map and len(gl_map) > 1:
-				save_entries(gl_map, adv_adj, update_outstanding)
+				save_entries(gl_map, adv_adj, update_outstanding, from_repost)
 			else:
 				frappe.throw(_("Incorrect number of General Ledger Entries found. You might have selected a wrong Account in the transaction."))
 		else:
@@ -78,21 +78,26 @@
 			and cstr(e.get('project')) == cstr(gle.get('project')):
 				return e
 
-def save_entries(gl_map, adv_adj, update_outstanding):
-	validate_account_for_auto_accounting_for_stock(gl_map)
+def save_entries(gl_map, adv_adj, update_outstanding, from_repost=False):
+	if not from_repost:
+		validate_account_for_auto_accounting_for_stock(gl_map)
+		
 	round_off_debit_credit(gl_map)
 
 	for entry in gl_map:
-		make_entry(entry, adv_adj, update_outstanding)
+		make_entry(entry, adv_adj, update_outstanding, from_repost)
+		
 		# check against budget
-		validate_expense_against_budget(entry)
+		if not from_repost:
+			validate_expense_against_budget(entry)
 
-def make_entry(args, adv_adj, update_outstanding):
+def make_entry(args, adv_adj, update_outstanding, from_repost=False):
 	args.update({"doctype": "GL Entry"})
 	gle = frappe.get_doc(args)
 	gle.flags.ignore_permissions = 1
+	gle.flags.from_repost = from_repost
 	gle.insert()
-	gle.run_method("on_update_with_args", adv_adj, update_outstanding)
+	gle.run_method("on_update_with_args", adv_adj, update_outstanding, from_repost)
 	gle.submit()
 
 def validate_account_for_auto_accounting_for_stock(gl_map):
diff --git a/erpnext/accounts/page/pos/pos.js b/erpnext/accounts/page/pos/pos.js
index 13abe14..ed54ab4 100644
--- a/erpnext/accounts/page/pos/pos.js
+++ b/erpnext/accounts/page/pos/pos.js
@@ -1,7 +1,7 @@
 frappe.provide("erpnext.pos");
 {% include "erpnext/public/js/controllers/taxes_and_totals.js" %}
 
-frappe.pages['pos'].on_page_load = function(wrapper) {
+frappe.pages['pos'].on_page_load = function (wrapper) {
 	var page = frappe.ui.make_app_page({
 		parent: wrapper,
 		title: __('Point of Sale'),
@@ -11,15 +11,15 @@
 	wrapper.pos = new erpnext.pos.PointOfSale(wrapper)
 }
 
-frappe.pages['pos'].refresh = function(wrapper) {
+frappe.pages['pos'].refresh = function (wrapper) {
 	window.onbeforeunload = function () {
 		return wrapper.pos.beforeunload()
 	}
 }
 
-
 erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({
-	init: function(wrapper){
+	init: function (wrapper) {
+		this.page_len = 20;
 		this.page = wrapper.page;
 		this.wrapper = $(wrapper).find('.page-content');
 		this.set_indicator();
@@ -28,13 +28,13 @@
 		this.si_docs = this.get_doc_from_localstorage();
 	},
 
-	beforeunload: function(e){
-		if(this.connection_status == false && frappe.get_route()[0] == "pos"){
+	beforeunload: function (e) {
+		if (this.connection_status == false && frappe.get_route()[0] == "pos") {
 			e = e || window.event;
 
 			// For IE and Firefox prior to version 4
 			if (e) {
-			    e.returnValue = __("You are in offline mode. You will not be able to reload until you have network.");
+				e.returnValue = __("You are in offline mode. You will not be able to reload until you have network.");
 				return
 			}
 
@@ -43,23 +43,23 @@
 		}
 	},
 
-	check_internet_connection: function(){
+	check_internet_connection: function () {
 		var me = this;
 		//Check Internet connection after every 30 seconds
-		setInterval(function(){
+		setInterval(function () {
 			me.set_indicator();
 		}, 5000)
 	},
 
-	set_indicator: function(){
+	set_indicator: function () {
 		var me = this;
 		// navigator.onLine
 		this.connection_status = false;
 		this.page.set_indicator(__("Offline"), "grey")
 		frappe.call({
-			method:"frappe.handler.ping",
-			callback: function(r){
-				if(r.message){
+			method: "frappe.handler.ping",
+			callback: function (r) {
+				if (r.message) {
 					me.connection_status = true;
 					me.page.set_indicator(__("Online"), "green")
 				}
@@ -67,27 +67,23 @@
 		})
 	},
 
-	onload: function(){
+	onload: function () {
 		var me = this;
-		this.get_data_from_server(function(){
+		this.get_data_from_server(function () {
 			me.create_new();
 		});
 	},
 
-	make_menu_list: function(){
+	make_menu_list: function () {
 		var me = this;
 
-		this.page.add_menu_item(__("New Sales Invoice"), function() {
+		this.page.add_menu_item(__("New Sales Invoice"), function () {
 			me.save_previous_entry();
 			me.create_new();
 		})
 
-		this.page.add_menu_item(__("View Offline Records"), function(){
-			me.show_unsync_invoice_list();
-		});
-
-		this.page.add_menu_item(__("Sync Master Data"), function(){
-			me.get_data_from_server(function(){
+		this.page.add_menu_item(__("Sync Master Data"), function () {
+			me.get_data_from_server(function () {
 				me.load_data(false);
 				me.make_customer();
 				me.make_item_list();
@@ -95,83 +91,29 @@
 			})
 		});
 
-		this.page.add_menu_item(__("Sync Offline Invoices"), function(){
+		this.page.add_menu_item(__("Sync Offline Invoices"), function () {
 			me.sync_sales_invoice()
 		});
 
-		this.page.add_menu_item(__("POS Profile"), function() {
+		this.page.add_menu_item(__("POS Profile"), function () {
 			frappe.set_route('List', 'POS Profile');
 		});
 	},
 
-	show_unsync_invoice_list: function(){
-		var me = this;
-		this.si_docs = this.get_doc_from_localstorage();
-		this.list_dialog = new frappe.ui.Dialog({
-			title: 'Invoice List'
-		});
-
-		this.list_dialog.show();
-		this.list_body = this.list_dialog.body;
-		if(me.pos_profile_data["allow_delete"]) {
-			this.list_dialog.set_primary_action(__("Delete"), function() {
-				frappe.confirm(__("Delete permanently?"), function () {
-					me.delete_records();
-				})
-			}).addClass("btn-danger");
-			this.toggle_primary_action();
-		}
-
-		if(this.si_docs.length > 0){
-			me.render_offline_data();
-			me.dialog_actions()
-		}else{
-			$(this.list_body).append(repl('<div class="media-heading">%(message)s</div>', {'message': __("All records are synced.")}))
-		}
-	},
-
-	render_offline_data: function() {
+	dialog_actions: function () {
 		var me = this;
 
-		this.removed_items = [];
-		$(this.list_body).empty();
-
-		$(this.list_body).append('<div class="row list-row list-row-head pos-invoice-list">\
-				<div class="col-xs-1"><input class="list-select-all" type="checkbox"></div>\
-				<div class="col-xs-3">Customer</div>\
-				<div class="col-xs-2 text-left">Status</div>\
-				<div class="col-xs-3 text-right">Paid Amount</div>\
-				<div class="col-xs-3 text-right">Grand Total</div>\
-		</div>')
-
-		$.each(this.si_docs, function(index, data){
-			for(key in data) {
-				$(frappe.render_template("pos_invoice_list", {
-					sr: index + 1,
-					name: key,
-					customer: data[key].customer,
-					paid_amount: format_currency(data[key].paid_amount, me.frm.doc.currency),
-					grand_total: format_currency(data[key].grand_total, me.frm.doc.currency),
-					data: me.get_doctype_status(data[key])
-				})).appendTo($(me.list_body));
-			}
-		})
-	},
-
-	dialog_actions: function() {
-		var me = this;
-
-		$(this.list_body).find('.list-column').click(function() {
+		$(this.list_body).find('.list-column').click(function () {
 			me.name = $(this).parents().attr('invoice-name')
 			me.edit_record();
 		})
 
-		$(this.list_body).find('.list-select-all').click(function() {
+		$(this.list_body).find('.list-select-all').click(function () {
 			me.removed_items = [];
 			$(me.list_body).find('.list-delete').prop("checked", $(this).is(":checked"))
-			if($(this).is(":checked")) {
-				$.each(me.si_docs, function(index, data){
-					for(key in data) {
+			if ($(this).is(":checked")) {
+				$.each(me.si_docs, function (index, data) {
+					for (key in data) {
 						me.removed_items.push(key)
 					}
 				})
@@ -180,9 +122,9 @@
 			me.toggle_primary_action();
 		})
 
-		$(this.list_body).find('.list-delete').click(function() {
+		$(this.list_body).find('.list-delete').click(function () {
 			me.name = $(this).parent().parent().attr('invoice-name');
-			if($(this).is(":checked")) {
+			if ($(this).is(":checked")) {
 				me.removed_items.push(me.name);
 			} else {
 				me.removed_items.pop(me.name)
@@ -192,101 +134,103 @@
 		})
 	},
 
-	edit_record: function() {
+	edit_record: function () {
 		var me = this;
 
 		doc_data = this.get_invoice_doc(this.si_docs);
-		if(doc_data){
+		if (doc_data) {
 			this.frm.doc = doc_data[0][this.name];
 			this.set_missing_values();
 			this.refresh(false);
 			this.disable_input_field();
-			this.list_dialog.hide();
+			this.list_dialog && this.list_dialog.hide();
 		}
 	},
 
-	delete_records: function() {
+	delete_records: function () {
 		var me = this;
 		this.remove_doc_from_localstorage()
 		this.update_localstorage();
-		this.render_offline_data();
 		this.dialog_actions();
 		this.toggle_primary_action();
 	},
 
-	toggle_primary_action: function() {
+	toggle_primary_action: function () {
 		var me = this;
-		if(this.removed_items && this.removed_items.length > 0) {
-			$(this.list_dialog.wrapper).find('.btn-danger').show();
+		if(this.frm.doc.allow_delete) {
+			if (this.removed_items && this.removed_items.length > 0) {
+				$(this.wrapper).find('.btn-danger').show();
+			} else {
+				$(this.wrapper).find('.btn-danger').hide();
+			}
+		}
+	},
+
+	get_doctype_status: function (doc) {
+		if (doc.docstatus == 0) {
+			return { status: "Draft", indicator: "red" }
+		} else if (doc.outstanding_amount == 0) {
+			return { status: "Paid", indicator: "green" }
 		} else {
-			$(this.list_dialog.wrapper).find('.btn-danger').hide();
+			return { status: "Submitted", indicator: "blue" }
 		}
 	},
 
-	get_doctype_status: function(doc){
-		if(doc.docstatus == 0) {
-			return {status: "Draft", indicator: "red"}
-		}else if(doc.outstanding_amount == 0) {
-			return {status: "Paid", indicator: "green"}
-		}else {
-			return {status: "Submitted", indicator: "blue"}
-		}
-	},
-
-	set_missing_values: function(){
+	set_missing_values: function () {
 		var me = this;
 		doc = JSON.parse(localStorage.getItem('doc'))
-		if(this.frm.doc.payments.length == 0){
+		if (this.frm.doc.payments.length == 0) {
 			this.frm.doc.payments = doc.payments;
 			this.calculate_outstanding_amount();
 		}
 
-		if(this.frm.doc.customer){
+		if (this.frm.doc.customer) {
 			this.party_field.$input.val(this.frm.doc.customer);
 		}
 
-		if(!this.frm.doc.write_off_account){
+		if (!this.frm.doc.write_off_account) {
 			this.frm.doc.write_off_account = doc.write_off_account
 		}
 
-		if(!this.frm.doc.account_for_change_amount){
+		if (!this.frm.doc.account_for_change_amount) {
 			this.frm.doc.account_for_change_amount = doc.account_for_change_amount
 		}
 	},
 
-	get_invoice_doc: function(si_docs){
+	get_invoice_doc: function (si_docs) {
 		var me = this;
 		this.si_docs = this.get_doc_from_localstorage();
 
-		return $.grep(this.si_docs, function(data){
-			for(key in data){
+		return $.grep(this.si_docs, function (data) {
+			for (key in data) {
 				return key == me.name
 			}
 		})
 	},
 
-	get_data_from_server: function(callback){
+	get_data_from_server: function (callback) {
 		var me = this;
 		frappe.call({
 			method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data",
 			freeze: true,
 			freeze_message: __("Master data syncing, it might take some time"),
-			callback: function(r){
+			callback: function (r) {
 				me.init_master_data(r)
 				localStorage.setItem('doc', JSON.stringify(r.message.doc));
 				me.set_interval_for_si_sync();
 				me.check_internet_connection();
-				if(callback){
+				if (callback) {
 					callback();
 				}
 			}
 		})
 	},
 
-	init_master_data: function(r){
+	init_master_data: function (r) {
 		var me = this;
 		this.meta = r.message.meta;
 		this.item_data = r.message.items;
+		this.item_groups = r.message.item_groups;
 		this.customers = r.message.customers;
 		this.serial_no_data = r.message.serial_no_data;
 		this.batch_no_data = r.message.batch_no_data;
@@ -301,48 +245,51 @@
 		this.letter_head = (this.pos_profile_data.length > 0) ? frappe.boot.letter_heads[this.pos_profile_data[letter_head]] : {};
 	},
 
-	save_previous_entry : function(){
-		if(this.frm.doc.docstatus < 1 && this.frm.doc.items.length > 0){
-			this.create_invoice()
+	save_previous_entry: function () {
+		if (this.frm.doc.docstatus < 1 && this.frm.doc.items.length > 0) {
+			this.create_invoice();
 		}
 	},
 
-	create_new: function(){
+	create_new: function () {
 		var me = this;
 		this.frm = {}
-		this.name = '';
+		this.name = null;
 		this.load_data(true);
 		this.setup();
 	},
 
-	load_data: function(load_doc){
+	load_data: function (load_doc) {
 		var me = this;
 
 		this.items = this.item_data;
 		this.actual_qty_dict = {};
 
-		if(load_doc) {
-			this.frm.doc =  JSON.parse(localStorage.getItem('doc'));
+		if (load_doc) {
+			this.frm.doc = JSON.parse(localStorage.getItem('doc'));
 		}
 
-		$.each(this.meta, function(i, data){
+		$.each(this.meta, function (i, data) {
 			frappe.meta.sync(data)
 			locals["DocType"][data.name] = data;
 		})
 
-		this.print_template_data = frappe.render_template("print_template", {content: this.print_template,
-			title:"POS", base_url: frappe.urllib.get_base_url(), print_css: frappe.boot.print_css,
-			print_settings: this.print_settings, header: this.letter_head.header, footer: this.letter_head.footer})
+		this.print_template_data = frappe.render_template("print_template", {
+			content: this.print_template,
+			title: "POS", base_url: frappe.urllib.get_base_url(), print_css: frappe.boot.print_css,
+			print_settings: this.print_settings, header: this.letter_head.header, footer: this.letter_head.footer
+		})
 	},
 
-	setup: function(){
+	setup: function () {
+		this.frm.doc.allow_delete = this.pos_profile_data["allow_delete"];
 		this.wrapper.html(frappe.render_template("pos", this.frm.doc));
 		this.set_transaction_defaults("Customer");
 		this.make();
 		this.set_primary_action();
 	},
 
-	set_transaction_defaults: function(party) {
+	set_transaction_defaults: function (party) {
 		var me = this;
 		this.party = party;
 		this.price_list = (party == "Customer" ?
@@ -351,34 +298,54 @@
 		this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase");
 	},
 
-	make: function() {
+	make: function () {
 		this.make_search();
+		this.make_list_customers();
 		this.make_customer();
 		this.make_item_list();
 		this.make_discount_field()
 	},
 
-	make_search: function() {
+	make_search: function () {
 		var me = this;
-		this.search = frappe.ui.form.make_control({
+		this.serach_item = frappe.ui.form.make_control({
 			df: {
 				"fieldtype": "Data",
 				"label": "Item",
 				"fieldname": "pos_item",
 				"placeholder": __("Search Item")
 			},
-			parent: this.wrapper.find(".search-area"),
+			parent: this.wrapper.find(".search-item"),
 			only_input: true,
 		});
 
-		this.search.make_input();
-		this.search.$input.on("keyup", function() {
-			setTimeout(function() {
+		this.serach_item.make_input();
+		this.serach_item.$input.on("keyup", function () {
+			setTimeout(function () {
 				me.items = me.get_items();
 				me.make_item_list();
 			}, 1000);
 		});
 
+		this.search_item_group = frappe.ui.form.make_control({
+			df: {
+				"fieldtype": "Select",
+				"options": me.item_groups,
+				"label": __("Item Group"),
+				"fieldname": "item_group",
+				"placeholder": __("Item Group")
+			},
+			parent: this.wrapper.find(".search-item-group"),
+			only_input: true,
+		});
+
+		this.search_item_group.make_input();
+		this.search_item_group.$input.on("change", function () {
+			me.page_len = 20;
+			me.items = me.get_items();
+			me.make_item_list();
+		});
+
 		this.party_field = frappe.ui.form.make_control({
 			df: {
 				"fieldtype": "Data",
@@ -392,21 +359,139 @@
 		});
 
 		this.party_field.make_input();
-		this.set_focus()
+		setTimeout(this.set_focus.bind(this), 500);
+
+		this.wrapper.find(".btn-more").on("click", function() {
+			me.page_len += 20;
+			me.items = me.get_items();
+			me.make_item_list();
+		})
 	},
 
-	set_focus: function(){
-		if(this.default_customer){
-			this.search.$input.focus();
-		}else{
+	make_list_customers: function () {
+		var me = this;
+		this.list_customers_btn = this.wrapper.find('.list-customers-btn');
+		this.add_customer_btn = this.wrapper.find('.add-customer-btn');
+		this.pos_bill = this.wrapper.find('.pos-bill').hide();
+		this.list_customers = this.wrapper.find('.list-customers');
+
+		this.list_customers_btn.on('click', function () {
+			$(this).toggleClass("view_customer");
+			if($(this).hasClass("view_customer")) {
+				me.render_list_customers();
+				me.bind_delete_event()
+				me.party_field.$input.attr('disabled', true);
+				me.list_customers.show();
+				me.pos_bill.hide();
+			} else {
+				if(me.frm.doc.docstatus == 0) {
+					me.party_field.$input.attr('disabled', false);
+				}
+				me.pos_bill.show();
+				me.list_customers.hide()
+			}
+		});
+		this.add_customer_btn.on('click', function() {
+			me.save_previous_entry();
+			me.create_new();
+			me.refresh();
+			me.set_focus();
+		});
+	},
+
+	render_list_customers: function () {
+		var me = this;
+
+		this.removed_items = [];
+		this.list_customers.empty();
+		this.si_docs = this.get_doc_from_localstorage();
+
+		if (!this.si_docs.length) {
+			this.list_customers.append(
+				'<div style="padding: 12px; margin-left:-12px;">' + __("No offline records.") + '</div>'
+			)
+			return;
+		}
+		var html = '<div class="row list-row list-row-head pos-invoice-list">\
+			<div class="col-xs-1"><input class="list-select-all" type="checkbox"></div>\
+			<div class="col-xs-3">Customer</div>\
+			<div class="col-xs-2 text-left">Status</div>\
+			<div class="col-xs-3 text-right">Paid Amount</div>\
+			<div class="col-xs-3 text-right">Grand Total</div>\
+		</div>';
+		this.si_docs.forEach(function (data, i) {
+			for (key in data) {
+				html += frappe.render_template("pos_invoice_list", {
+					sr: i + 1,
+					name: key,
+					customer: data[key].customer,
+					paid_amount: format_currency(data[key].paid_amount, me.frm.doc.currency),
+					grand_total: format_currency(data[key].grand_total, me.frm.doc.currency),
+					data: me.get_doctype_status(data[key])
+				});
+			}
+		});
+		this.list_customers.append(html);
+
+		this.list_customers.find('.list-column').click(function () {
+			me.list_customers.hide();
+			me.list_customers_btn.toggleClass("view_customer");
+			me.pos_bill.show();
+			me.list_customers_btn.show();
+			me.name = $(this).parents().attr('invoice-name')
+			me.edit_record();
+		})
+
+		//actions
+		$(this.wrapper).find('.list-select-all').click(function () {
+			me.list_customers.find('.list-delete').prop("checked", $(this).is(":checked"))
+			me.removed_items = [];
+			if ($(this).is(":checked")) {
+				$.each(me.si_docs, function (index, data) {
+					for (key in data) {
+						me.removed_items.push(key)
+					}
+				});
+			}
+
+			me.toggle_primary_action();
+		});
+
+		$(this.wrapper).find('.list-delete').click(function () {
+			me.name = $(this).parent().parent().attr('invoice-name');
+			if ($(this).is(":checked")) {
+				me.removed_items.push(me.name);
+			} else {
+				me.removed_items.pop(me.name)
+			}
+
+			me.toggle_primary_action();
+		});
+	},
+
+	bind_delete_event: function() {
+		var me = this;
+
+		$(this.wrapper).find('.btn-danger').click(function(){
+			frappe.confirm(__("Delete permanently?"), function () {
+				me.delete_records();
+				me.render_list_customers();
+			})
+		})
+	},
+
+	set_focus: function () {
+		if (this.default_customer || this.frm.doc.customer) {
+			this.serach_item.$input.focus();
+		} else {
 			this.party_field.$input.focus();
 		}
 	},
 
-	make_customer: function() {
+	make_customer: function () {
 		var me = this;
 
-		if(this.default_customer && !this.frm.doc.customer){
+		if (this.default_customer && !this.frm.doc.customer) {
 			this.party_field.$input.val(this.default_customer);
 			this.frm.doc.customer = this.default_customer;
 		}
@@ -417,14 +502,14 @@
 				maxItems: 99,
 				autoFirst: true,
 				list: [],
-				filter: function(item, input) {
+				filter: function (item, input) {
 					var value = item.value.toLowerCase();
-					if(value.indexOf('is_action') !== -1 ||
+					if (value.indexOf('is_action') !== -1 ||
 						value.indexOf(input) !== -1) {
 						return true;
 					}
 				},
-				item: function(item, input) {
+				item: function (item, input) {
 					var d = item;
 					var html = "<span>" + __(d.label || d.value) + "</span>";
 					return $('<li></li>')
@@ -433,7 +518,7 @@
 						.get(0);
 				}
 			});
-		var items = this.customers.map(function(c) {
+		var customers = this.customers.map(function (c) {
 			return {
 				label: c.name,
 				value: c.name,
@@ -441,44 +526,47 @@
 				territory: c.territory
 			}
 		});
-		items.push({
+
+		customers.push({
 			label: "<span class='text-primary link-option'>"
-				+ "<i class='fa fa-plus' style='margin-right: 5px;'></i> "
-				+ __("Create a new Customer")
-				+ "</span>",
+			+ "<i class='fa fa-plus' style='margin-right: 5px;'></i> "
+			+ __("Create a new Customer")
+			+ "</span>",
 			value: 'is_action',
 			action: me.new_customer
 		});
-		this.party_field.awesomeplete.list = items;
+		this.party_field.awesomeplete.list = customers;
 
 		this.party_field.$input
-			.on('input', function(e) {
-				me.party_field.awesomeplete.list = items;
+			.on('input', function (e) {
+				me.party_field.awesomeplete.list = customers;
 			})
-			.on('awesomplete-select', function(e) {
-				var item = me.party_field.awesomeplete
+			.on('awesomplete-select', function (e) {
+				var customer = me.party_field.awesomeplete
 					.get_item(e.originalEvent.text.value);
-				if(!item) return;
-				if(item.action) {
-					item.action.apply(me);
+				if (!customer) return;
+				// create customer link
+				if (customer.action) {
+					customer.action.apply(me);
 					return;
 				}
-				me.update_customer_data(item);
+				me.update_customer_data(customer);
 				me.refresh();
+				me.set_focus();
 			})
-			.on('change', function(e) {
-				if(!e.originalEvent.text) {
+			.on('change', function (e) {
+				if (!e.originalEvent.text) {
 					me.frm.doc.customer = $(this).val();
 				}
 			})
-			.on('focus', function(e) {
+			.on('focus', function (e) {
 				$(e.target).val('').trigger('input');
 			})
-			.on("awesomplete-selectcomplete", function(e) {
+			.on("awesomplete-selectcomplete", function (e) {
 				var item = me.party_field.awesomeplete
 					.get_item(e.originalEvent.text.value);
 				// clear text input if item is action
-				if(item.action) {
+				if (item.action) {
 					$(this).val("");
 				}
 			});
@@ -486,45 +574,119 @@
 
 	new_customer: function () {
 		var me = this;
-		if(!this.connection_status) return;
-		frappe.ui.form.quick_entry('Customer', function (doc) {
-			me.customers.push(doc);
-			me.party_field.$input.val(doc.name);
-			me.update_customer_data(doc);
+		if (!this.connection_status) return;
+
+		this.customer_doc = new frappe.ui.Dialog({
+			'title': 'Customer',
+			fields: [
+				{
+					"label": __("Full Name"),
+					"fieldname": "full_name",
+					"fieldtype": "Data",
+					"reqd": 1
+				},
+				{
+					"fieldtype": "Section Break"
+				},
+				{
+					"label": __("Email Id"),
+					"fieldname": "email_id",
+					"fieldtype": "Data"
+				},
+				{
+					"fieldtype": "Column Break"
+				},
+				{
+					"label": __("Contact Number"),
+					"fieldname": "contact_no",
+					"fieldtype": "Data"
+				},
+				{
+					"fieldtype": "Section Break"
+				},
+				{
+					"label": __("Address Line 1"),
+					"fieldname": "address_line1",
+					"fieldtype": "Data"
+				},
+				{
+					"label": __("Address Line 2"),
+					"fieldname": "address_line2",
+					"fieldtype": "Data"
+				},
+				{
+					"fieldtype": "Column Break"
+				},
+				{
+					"label": __("City"),
+					"fieldname": "city",
+					"fieldtype": "Data"
+				},
+				{
+					"label": __("State"),
+					"fieldname": "state",
+					"fieldtype": "Data"
+				},
+				{
+					"label": __("ZIP Code"),
+					"fieldname": "zip_code",
+					"fieldtype": "Data"
+				}
+			]
 		})
+
+		this.customer_doc.show()
+
+		this.customer_doc.set_primary_action(__("Save"), function () {
+			me.make_offline_customer();
+			me.pos_bill.show();
+		});
 	},
 
-	update_customer_data: function(doc) {
+	make_offline_customer: function() {
+		this.frm.doc.customer = this.customer_doc.get_values().full_name;
+		this.frm.doc.contact_details = JSON.stringify(this.customer_doc.get_values());
+		this.party_field.$input.val(this.frm.doc.customer);
+		this.customers.push({
+			name: this.frm.doc.customer,
+			customer_name: this.frm.doc.customer
+		});
+
+		this.customer_doc.hide()
+	},
+
+	update_customer_data: function (doc) {
 		var me = this;
 		this.frm.doc.customer = doc.label || doc.name;
 		this.frm.doc.customer_name = doc.customer_name;
 		this.frm.doc.customer_group = doc.customer_group;
 		this.frm.doc.territory = doc.territory;
+		this.pos_bill.show();
 	},
 
-	get_customers: function(key){
+	get_customers: function (key) {
 		var me = this;
 		key = key.toLowerCase().trim()
 		var re = new RegExp('%', 'g');
 		var reg = new RegExp(key.replace(re, '\\w*\\s*[a-zA-Z0-9]*'))
 
-		if(key){
-			return $.grep(this.customers, function(data) {
-				if(reg.test(data.name.toLowerCase())
+		if (key) {
+			return $.grep(this.customers, function (data) {
+				if (reg.test(data.name.toLowerCase())
 					|| reg.test(data.customer_name.toLowerCase())
-					|| (data.customer_group && reg.test(data.customer_group.toLowerCase()))){
+					|| (data.customer_group && reg.test(data.customer_group.toLowerCase()))) {
 					return data
 				}
 			})
-		}else{
-			customers = this.customers.sort(function(a,b){ return a.idx < b.idx })
+		} else {
+			customers = this.customers.sort(function (a, b) { return a.idx < b.idx })
 			return customers.slice(0, 20)
 		}
 	},
 
-	make_item_list: function() {
+	make_item_list: function () {
 		var me = this;
-		if(!this.price_list) {
+		if (!this.price_list) {
 			msgprint(__("Price List not found or disabled"));
 			return;
 		}
@@ -536,11 +698,11 @@
 
 		if (this.items.length > 0) {
 			$.each(this.items, function(index, obj) {
-				if(index < 30){
+				if(index < me.page_len){
 					$(frappe.render_template("pos_item", {
 						item_code: obj.name,
 						item_price: format_currency(me.price_list_data[obj.name], me.frm.doc.currency),
-						item_name: obj.name===obj.item_name ? "" : obj.item_name,
+						item_name: obj.name === obj.item_name ? "" : obj.item_name,
 						item_image: obj.image ? "url('" + obj.image + "')" : null,
 						color: frappe.get_palette(obj.item_name),
 						abbr: frappe.get_abbr(obj.item_name)
@@ -548,143 +710,173 @@
 				}
 			});
 		} else {
-			$("<h4>Searching record not found.</h4>").appendTo($wrap)
+			$("<p class='text-muted small' style='padding-left: 10px'>"
+				+__("Not items found")+"</p>").appendTo($wrap)
 		}
 
-		if(this.items.length == 1
-			&& this.search.$input.val()) {
-			this.search.$input.val("");
+		if (this.items.length == 1
+			&& this.serach_item.$input.val()) {
+			this.serach_item.$input.val("");
 			this.add_to_cart();
 		}
 
 		// if form is local then allow this function
-		$(me.wrapper).find("div.pos-item").on("click", function() {
+		$(me.wrapper).find("div.pos-item").on("click", function () {
+			if(me.list_customers_btn.hasClass("view_customer")) return;
+
 			me.customer_validate();
-			if(me.frm.doc.docstatus==0) {
+			if (me.frm.doc.docstatus == 0) {
 				me.items = me.get_items($(this).attr("data-item-code"))
 				me.add_to_cart();
 			}
 		});
 	},
 
-	get_items: function(item_code){
+	get_items: function (item_code) {
 		// To search item as per the key enter
 
 		var me = this;
 		this.item_serial_no = {};
 		this.item_batch_no = {};
 
-		if(item_code){
-			return $.grep(this.item_data, function(item){
-				if(item.item_code == item_code ){
+		if (item_code) {
+			return $.grep(this.item_data, function (item) {
+				if (item.item_code == item_code) {
 					return true
 				}
 			})
 		}
 
-		key =  this.search.$input.val().toLowerCase().replace(/[&\/\\#,+()\[\]$~.'":*?<>{}]/g,'\\$&');
+		this.items_list = this.apply_category();
+
+		key = this.serach_item.$input.val().toLowerCase().replace(/[&\/\\#,+()\[\]$~.'":*?<>{}]/g, '\\$&');
 		var re = new RegExp('%', 'g');
 		var reg = new RegExp(key.replace(re, '[\\w*\\s*[a-zA-Z0-9]*]*'))
 		search_status = true
 
-		if(key){
-			return $.grep(this.item_data, function(item){
-				if(search_status){
-					if(in_list(me.batch_no_data[item.item_code], me.search.$input.val())){
+		if (key) {
+			return $.grep(this.items_list, function (item) {
+				if (search_status) {
+					if (in_list(me.batch_no_data[item.item_code], me.serach_item.$input.val())) {
 						search_status = false;
-						return me.item_batch_no[item.item_code] = me.search.$input.val()
-					} else if( me.serial_no_data[item.item_code]
-						&& in_list(Object.keys(me.serial_no_data[item.item_code]), me.search.$input.val())) {
+						return me.item_batch_no[item.item_code] = me.serach_item.$input.val()
+					} else if (me.serial_no_data[item.item_code]
+						&& in_list(Object.keys(me.serial_no_data[item.item_code]), me.serach_item.$input.val())) {
 						search_status = false;
-						me.item_serial_no[item.item_code] = [me.search.$input.val(), me.serial_no_data[item.item_code][me.search.$input.val()]]
+						me.item_serial_no[item.item_code] = [me.serach_item.$input.val(), me.serial_no_data[item.item_code][me.serach_item.$input.val()]]
 						return true
-					} else if(item.barcode == me.search.$input.val()) {
+					} else if (item.barcode == me.serach_item.$input.val()) {
 						search_status = false;
-						return item.barcode == me.search.$input.val();
-					} else if(reg.test(item.item_code.toLowerCase()) || reg.test(item.description.toLowerCase()) ||
-					reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase()) ){
+						return item.barcode == me.serach_item.$input.val();
+					} else if (reg.test(item.item_code.toLowerCase()) || reg.test(item.description.toLowerCase()) ||
+						reg.test(item.item_name.toLowerCase()) || reg.test(item.item_group.toLowerCase())) {
 						return true
 					}
 				}
 			})
-		}else{
-			return this.item_data;
+		} else {
+			return this.items_list;
 		}
 	},
 
-	bind_qty_event: function() {
+	apply_category: function() {
+		var me = this;
+		category = this.search_item_group.$input.val();
+
+		if(category == 'All Item Groups') {
+			return this.item_data
+		} else {
+			return this.item_data.filter(function(element, index, array){
+				return element.item_group == category;
+			});
+		}
+	},
+
+	bind_qty_event: function () {
 		var me = this;
 
-		$(this.wrapper).find(".pos-item-qty").on("change", function(){
+		$(this.wrapper).find(".pos-item-qty").on("change", function () {
 			var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
 			var qty = $(this).val();
 			me.update_qty(item_code, qty)
 		})
 
-		$(this.wrapper).find("[data-action='increase-qty']").on("click", function(){
+		$(this.wrapper).find("[data-action='increase-qty']").on("click", function () {
 			var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
 			var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1;
 			me.update_qty(item_code, qty)
 		})
 
-		$(this.wrapper).find("[data-action='decrease-qty']").on("click", function(){
+		$(this.wrapper).find("[data-action='decrease-qty']").on("click", function () {
 			var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
 			var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1;
 			me.update_qty(item_code, qty)
 		})
-	},
 
-	update_qty: function(item_code, qty) {
-		var me = this;
-		this.items = this.get_items(item_code);
-		this.validate_serial_no()
-		this.update_qty_rate_against_item_code(item_code, "qty", qty);
-	},
-
-	update_rate: function() {
-		var me = this;
-
-		$(this.wrapper).find(".pos-item-rate").on("change", function(){
+		$(this.wrapper).find(".pos-item-discount").on("change", function () {
 			var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
-			me.update_qty_rate_against_item_code(item_code, "rate", $(this).val());
+			var discount = $(this).val();
+			me.update_discount(item_code, discount)
 		})
 	},
 
-	update_qty_rate_against_item_code: function(item_code, field, value){
+	update_qty: function (item_code, qty) {
 		var me = this;
-		if(value < 0){
+		this.items = this.get_items(item_code);
+		this.validate_serial_no()
+		this.set_item_details(item_code, "qty", qty);
+	},
+
+	update_discount: function(item_code, discount) {
+		var me = this;
+		this.items = this.get_items(item_code);
+		this.set_item_details(item_code, "discount_percentage", discount);
+	},
+
+	update_rate: function () {
+		var me = this;
+
+		$(this.wrapper).find(".pos-item-rate").on("change", function () {
+			var item_code = $(this).parents(".pos-bill-item").attr("data-item-code");
+			me.set_item_details(item_code, "rate", $(this).val());
+		})
+	},
+
+	set_item_details: function (item_code, field, value) {
+		var me = this;
+		if (value < 0) {
 			frappe.throw(__("Enter value must be positive"));
 		}
 
 		this.remove_item = []
-		$.each(this.frm.doc["items"] || [], function(i, d) {
-			if(d.serial_no && field == 'qty'){
-				me.validate_serial_no_qty(d, item_code, field, value)
-			}
-
+		$.each(this.frm.doc["items"] || [], function (i, d) {
 			if (d.item_code == item_code) {
+				if (d.serial_no && field == 'qty') {
+					me.validate_serial_no_qty(d, item_code, field, value)
+				}
+
 				d[field] = flt(value);
 				d.amount = flt(d.rate) * flt(d.qty);
-				if(d.qty==0){
+				if (d.qty == 0) {
 					me.remove_item.push(d.idx)
 				}
 			}
 		});
 
-		if(field == 'qty'){
+		if (field == 'qty') {
 			this.remove_zero_qty_item();
 		}
 
 		this.update_paid_amount_status(false)
 	},
 
-	remove_zero_qty_item: function(){
+	remove_zero_qty_item: function () {
 		var me = this;
 		idx = 0
 		this.items = []
 		idx = 0
-		$.each(this.frm.doc["items"] || [], function(i, d) {
-			if(!in_list(me.remove_item, d.idx)){
+		$.each(this.frm.doc["items"] || [], function (i, d) {
+			if (!in_list(me.remove_item, d.idx)) {
 				d.idx = idx;
 				me.items.push(d);
 				idx++;
@@ -694,23 +886,23 @@
 		this.frm.doc["items"] = this.items;
 	},
 
-	make_discount_field: function(){
+	make_discount_field: function () {
 		var me = this;
 
-		this.wrapper.find('input.discount-percentage').on("change", function() {
+		this.wrapper.find('input.discount-percentage').on("change", function () {
 			me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage"));
 			total = me.frm.doc.grand_total
 
-			if(me.frm.doc.apply_discount_on == 'Net Total'){
+			if (me.frm.doc.apply_discount_on == 'Net Total') {
 				total = me.frm.doc.net_total
 			}
 
-			me.frm.doc.discount_amount = flt(total*flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount"));
+			me.frm.doc.discount_amount = flt(total * flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount"));
 			me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount)
 			me.refresh();
 		});
 
-		this.wrapper.find('input.discount-amount').on("change", function() {
+		this.wrapper.find('input.discount-amount').on("change", function () {
 			me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount"));
 			me.frm.doc.additional_discount_percentage = 0.0;
 			me.wrapper.find('input.discount-percentage').val(0);
@@ -718,14 +910,14 @@
 		});
 	},
 
-	customer_validate: function(){
+	customer_validate: function () {
 		var me = this;
-		if(!this.frm.doc.customer){
+		if (!this.frm.doc.customer) {
 			frappe.throw(__("Please select customer"))
 		}
 	},
 
-	add_to_cart: function() {
+	add_to_cart: function () {
 		var me = this;
 		var caught = false;
 		var no_of_items = me.wrapper.find(".pos-bill-item").length;
@@ -736,17 +928,17 @@
 		this.validate_warehouse();
 
 		if (no_of_items != 0) {
-			$.each(this.frm.doc["items"] || [], function(i, d) {
+			$.each(this.frm.doc["items"] || [], function (i, d) {
 				if (d.item_code == me.items[0].item_code) {
 					caught = true;
 					d.qty += 1;
 					d.amount = flt(d.rate) * flt(d.qty);
-					if(me.item_serial_no[d.item_code]){
+					if (me.item_serial_no[d.item_code]) {
 						d.serial_no += '\n' + me.item_serial_no[d.item_code][0]
 						d.warehouse = me.item_serial_no[d.item_code][1]
 					}
 
-					if(me.item_batch_no.length){
+					if (me.item_batch_no.length) {
 						d.batch_no = me.item_batch_no[d.item_code]
 					}
 				}
@@ -760,7 +952,7 @@
 		this.update_paid_amount_status(false)
 	},
 
-	add_new_item_to_grid: function() {
+	add_new_item_to_grid: function () {
 		var me = this;
 		this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items");
 		this.child.item_code = this.items[0].item_code;
@@ -772,7 +964,7 @@
 		this.child.cost_center = this.pos_profile_data['cost_center'] || this.items[0].cost_center;
 		this.child.income_account = this.pos_profile_data['income_account'] || this.items[0].income_account;
 		this.child.warehouse = (this.item_serial_no[this.child.item_code]
-			? this.item_serial_no[this.child.item_code][1] : (this.pos_profile_data['warehouse'] || this.items[0].default_warehouse) );
+			? this.item_serial_no[this.child.item_code][1] : (this.pos_profile_data['warehouse'] || this.items[0].default_warehouse));
 		this.child.price_list_rate = flt(this.price_list_data[this.child.item_code], 9) / flt(this.frm.doc.conversion_rate, 9);
 		this.child.rate = flt(this.price_list_data[this.child.item_code], 9) / flt(this.frm.doc.conversion_rate, 9);
 		this.child.actual_qty = me.get_actual_qty(this.items[0]);
@@ -783,15 +975,15 @@
 		this.child.item_tax_rate = JSON.stringify(this.tax_data[this.child.item_code]);
 	},
 
-	update_paid_amount_status: function(update_paid_amount){
-		if(this.name){
+	update_paid_amount_status: function (update_paid_amount) {
+		if (this.name) {
 			update_paid_amount = update_paid_amount ? false : true;
 		}
 
 		this.refresh(update_paid_amount);
 	},
 
-	refresh: function(update_paid_amount) {
+	refresh: function (update_paid_amount) {
 		var me = this;
 		this.refresh_fields(update_paid_amount);
 		this.bind_qty_event();
@@ -799,7 +991,7 @@
 		this.set_primary_action();
 	},
 
-	refresh_fields: function(update_paid_amount) {
+	refresh_fields: function (update_paid_amount) {
 		this.apply_pricing_rule();
 		this.discount_amount_applied = false;
 		this._calculate_taxes_and_totals();
@@ -810,40 +1002,45 @@
 		this.set_totals();
 	},
 
-	get_company_currency: function() {
+	get_company_currency: function () {
 		return erpnext.get_currency(this.frm.doc.company);
 	},
 
-	show_item_wise_taxes: function(){
+	show_item_wise_taxes: function () {
 		return null;
 	},
 
-	show_items_in_item_cart: function() {
+	show_items_in_item_cart: function () {
 		var me = this;
 		var $items = this.wrapper.find(".items").empty();
-		$.each(this.frm.doc.items|| [], function(i, d) {
+		$.each(this.frm.doc.items || [], function (i, d) {
 			$(frappe.render_template("pos_bill_item", {
 				item_code: d.item_code,
-				item_name: (d.item_name===d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name),
+				item_name: (d.item_name === d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name),
 				qty: d.qty,
-				actual_qty: me.actual_qty_dict[d.item_code] || 0,
+				discount_percentage: d.discount_percentage || 0.0,
+				actual_qty: me.actual_qty_dict[d.item_code] || 0.0,
 				projected_qty: d.projected_qty,
 				rate: format_number(d.rate, me.frm.doc.currency),
-				enabled: me.pos_profile_data["allow_user_to_edit_rate"] ? true: false,
+				enabled: me.pos_profile_data["allow_user_to_edit_rate"] ? true : false,
 				amount: format_currency(d.amount, me.frm.doc.currency)
 			})).appendTo($items);
 		});
 
-		this.wrapper.find("input.pos-item-qty").on("focus", function() {
+		this.wrapper.find("input.pos-item-qty").on("focus", function () {
 			$(this).select();
 		});
 
-		this.wrapper.find("input.pos-item-rate").on("focus", function() {
+		this.wrapper.find("input.pos-item-discount").on("focus", function () {
+			$(this).select();
+		});
+
+		this.wrapper.find("input.pos-item-rate").on("focus", function () {
 			$(this).select();
 		});
 	},
 
-	set_taxes: function(){
+	set_taxes: function () {
 		var me = this;
 		me.frm.doc.total_taxes_and_charges = 0.0
 
@@ -852,7 +1049,7 @@
 			.find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true)
 			.find(".tax-table").empty();
 
-		$.each(taxes, function(i, d) {
+		$.each(taxes, function (i, d) {
 			if (d.tax_amount && cint(d.included_in_print_rate) == 0) {
 				$(frappe.render_template("pos_tax_row", {
 					description: d.description,
@@ -863,104 +1060,106 @@
 		});
 	},
 
-	set_totals: function() {
+	set_totals: function () {
 		var me = this;
 		this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency));
 		this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency));
 	},
 
-	set_primary_action: function() {
+	set_primary_action: function () {
 		var me = this;
 
-		if (this.frm.doc.docstatus==0) {
-			this.page.set_primary_action(__("Pay"), function() {
+		if (this.frm.doc.docstatus == 0) {
+			this.page.set_primary_action(__("Pay"), function () {
 				me.validate();
 				me.update_paid_amount_status(true);
 				me.create_invoice();
 				me.make_payment();
-			}, "octicon octfa fa-credit-card");
-		}else if(this.frm.doc.docstatus == 1) {
-			this.page.set_primary_action(__("Print"), function() {
+			}, "fa fa-credit-card");
+		} else if (this.frm.doc.docstatus == 1) {
+			this.page.set_primary_action(__("Print"), function () {
 				html = frappe.render(me.print_template_data, me.frm.doc)
 				me.print_document(html)
 			})
-		}else {
+		} else {
 			this.page.clear_primary_action()
 		}
 
-		this.page.set_secondary_action(__("New"), function() {
-			me.save_previous_entry();
-			me.create_new();
-		}, "octicon octfa fa-plus").addClass("btn-primary");
+		// this.page.set_secondary_action(__("New"), function () {
+		// 	me.save_previous_entry();
+		// 	me.create_new();
+		// }, "fa fa-plus").addClass("btn-primary");
 	},
 
-	print_dialog: function(){
+	print_dialog: function () {
 		var me = this;
 
 		msgprint = frappe.msgprint(format('<a class="btn btn-primary print_doc" \
 			style="margin-right: 5px;">{0}</a>\
 			<a class="btn btn-default new_doc">{1}</a>', [
-			__('Print'), __('New')
-		]));
+				__('Print'), __('New')
+			]));
 
-		$('.print_doc').click(function(){
+		$('.print_doc').click(function () {
 			html = frappe.render(me.print_template_data, me.frm.doc)
 			me.print_document(html)
 		})
 
-		$('.new_doc').click(function(){
+		$('.new_doc').click(function () {
 			msgprint.hide()
 			me.create_new();
 		})
 	},
 
-	print_document: function(html){
+	print_document: function (html) {
 		var w = window.open();
 		w.document.write(html);
 		w.document.close();
-		setTimeout(function(){
+		setTimeout(function () {
 			w.print();
 			w.close();
 		}, 1000)
 	},
 
-	submit_invoice: function(){
+	submit_invoice: function () {
 		var me = this;
 		this.change_status();
-		if(this.frm.doc.docstatus == 1){
+		if (this.frm.doc.docstatus == 1) {
 			this.print_dialog()
 		}
 	},
 
-	change_status: function(){
-		if(this.frm.doc.docstatus == 0){
+	change_status: function () {
+		if (this.frm.doc.docstatus == 0) {
 			this.frm.doc.docstatus = 1;
 			this.update_invoice();
 			this.disable_input_field();
 		}
 	},
 
-	disable_input_field: function(){
+	disable_input_field: function () {
 		var pointer_events = 'inherit'
 		$(this.wrapper).find('input').attr("disabled", false);
+		$(this.wrapper).find('select').attr("disabled", false);
 
-		if(this.frm.doc.docstatus == 1){
+		if (this.frm.doc.docstatus == 1) {
 			pointer_events = 'none';
 			$(this.wrapper).find('input').attr("disabled", true);
+			$(this.wrapper).find('select').attr("disabled", true);
 		}
 
-		$(this.wrapper).find('.pos-bill-wrapper').css('pointer-events', pointer_events);
+		$(this.wrapper).find('.pos-bill').css('pointer-events', pointer_events);
 		$(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events);
 		this.set_primary_action();
 	},
 
-	create_invoice: function(){
+	create_invoice: function () {
 		var me = this;
 		var invoice_data = {}
 		this.si_docs = this.get_doc_from_localstorage();
-		if(this.name){
+		if (this.name) {
 			this.update_invoice()
-		}else{
+		} else {
 			this.name = $.now();
 			this.frm.doc.offline_pos_name = this.name;
 			this.frm.doc.posting_date = frappe.datetime.get_today();
@@ -970,14 +1169,15 @@
 			this.update_localstorage();
 			this.set_primary_action();
 		}
+		return invoice_data;
 	},
 
-	update_invoice: function(){
+	update_invoice: function () {
 		var me = this;
 		this.si_docs = this.get_doc_from_localstorage();
-		$.each(this.si_docs, function(index, data){
-			for(key in data){
-				if(key == me.name){
+		$.each(this.si_docs, function (index, data) {
+			for (key in data) {
+				if (key == me.name) {
 					me.si_docs[index][key] = me.frm.doc;
 					me.update_localstorage();
 				}
@@ -985,41 +1185,41 @@
 		})
 	},
 
-	update_localstorage: function(){
-		try{
+	update_localstorage: function () {
+		try {
 			localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs));
-		}catch(e){
+		} catch (e) {
 			frappe.throw(__("LocalStorage is full , did not save"))
 		}
 	},
 
-	get_doc_from_localstorage: function(){
-		try{
+	get_doc_from_localstorage: function () {
+		try {
 			return JSON.parse(localStorage.getItem('sales_invoice_doc')) || [];
-		}catch(e){
+		} catch (e) {
 			return []
 		}
 	},
 
-	set_interval_for_si_sync: function(){
+	set_interval_for_si_sync: function () {
 		var me = this;
-		setInterval(function(){
+		setInterval(function () {
 			me.sync_sales_invoice()
 		}, 60000)
 	},
 
-	sync_sales_invoice: function(){
+	sync_sales_invoice: function () {
 		var me = this;
 		this.si_docs = this.get_submitted_invoice();
 
-		if(this.si_docs.length){
+		if (this.si_docs.length) {
 			frappe.call({
 				method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice",
 				args: {
 					doc_list: me.si_docs
 				},
-				callback: function(r){
-					if(r.message){
+				callback: function (r) {
+					if (r.message) {
 						me.removed_items = r.message;
 						me.remove_doc_from_localstorage();
 					}
@@ -1028,14 +1228,14 @@
 		}
 	},
 
-	get_submitted_invoice: function(){
+	get_submitted_invoice: function () {
 		var invoices = [];
 		var index = 1;
 		docs = this.get_doc_from_localstorage();
-		if(docs){
-			invoices = $.map(docs, function(data){
-				for(key in data){
-					if(data[key].docstatus == 1 && index < 50){
+		if (docs) {
+			invoices = $.map(docs, function (data) {
+				for (key in data) {
+					if (data[key].docstatus == 1 && index < 50) {
 						index++
 						data[key].docstatus = 0;
 						return data
@@ -1047,14 +1247,14 @@
 		return invoices
 	},
 
-	remove_doc_from_localstorage: function(){
+	remove_doc_from_localstorage: function () {
 		var me = this;
 		this.si_docs = this.get_doc_from_localstorage();
 		this.new_si_docs = [];
-		if(this.removed_items){
-			$.each(this.si_docs, function(index, data){
-				for(key in data){
-					if(!in_list(me.removed_items, key)){
+		if (this.removed_items) {
+			$.each(this.si_docs, function (index, data) {
+				for (key in data) {
+					if (!in_list(me.removed_items, key)) {
 						me.new_si_docs.push(data);
 					}
 				}
@@ -1064,44 +1264,44 @@
 		}
 	},
 
-	validate: function(){
+	validate: function () {
 		var me = this;
 		this.customer_validate();
 		this.item_validate();
 		this.validate_mode_of_payments();
 	},
 
-	item_validate: function(){
-		if(this.frm.doc.items.length == 0){
+	item_validate: function () {
+		if (this.frm.doc.items.length == 0) {
 			frappe.throw(__("Select items to save the invoice"))
 		}
 	},
 
-	validate_mode_of_payments: function(){
-		if (this.frm.doc.payments.length === 0){
+	validate_mode_of_payments: function () {
+		if (this.frm.doc.payments.length === 0) {
 			frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile."))
 		}
 	},
 
-	validate_serial_no: function(){
+	validate_serial_no: function () {
 		var me = this;
 		var item_code = serial_no = '';
-		for (key in this.item_serial_no){
+		for (key in this.item_serial_no) {
 			item_code = key;
 			serial_no = me.item_serial_no[key][0];
 		}
 
-		if(this.items[0].has_serial_no && serial_no == ""){
+		if (this.items[0].has_serial_no && serial_no == "") {
 			this.refresh();
 			frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", {
 				'item': this.items[0].item_code
 			})))
 		}
 
-		if(item_code && serial_no){
-			$.each(this.frm.doc.items, function(index, data){
-				if(data.item_code == item_code){
-					if(in_list(data.serial_no.split('\n'), serial_no)){
+		if (item_code && serial_no) {
+			$.each(this.frm.doc.items, function (index, data) {
+				if (data.item_code == item_code) {
+					if (in_list(data.serial_no.split('\n'), serial_no)) {
 						frappe.throw(__(repl("Serial no %(serial_no)s is already taken", {
 							'serial_no': serial_no
 						})))
@@ -1111,7 +1311,7 @@
 		}
 	},
 
-	validate_serial_no_qty: function(args, item_code, field, value){
+	validate_serial_no_qty: function (args, item_code, field, value) {
 		var me = this;
 		if (args.item_code == item_code && args.serial_no
 			&& field == 'qty' && cint(value) != value) {
@@ -1120,7 +1320,7 @@
 			frappe.throw(__("Serial no item cannot be a fraction"))
 		}
 
-		if(args.item_code == item_code && args.serial_no && args.serial_no.split('\n').length != cint(value)){
+		if (args.item_code == item_code && args.serial_no && args.serial_no.split('\n').length != cint(value)) {
 			args.qty = 0.0;
 			args.serial_no = ''
 			this.refresh();
@@ -1130,42 +1330,44 @@
 		}
 	},
 
-	mandatory_batch_no: function(){
+	mandatory_batch_no: function () {
 		var me = this;
-		if(this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]){
+		if (this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]) {
 			frappe.throw(__(repl("Error: Batch no is mandatory for item %(item)s", {
 				'item': this.items[0].item_code
 			})))
 		}
 	},
 
-	apply_pricing_rule: function(){
+	apply_pricing_rule: function () {
 		var me = this;
-		$.each(this.frm.doc["items"], function(n, item) {
+		$.each(this.frm.doc["items"], function (n, item) {
 			pricing_rule = me.get_pricing_rule(item)
 			me.validate_pricing_rule(pricing_rule)
-			if(pricing_rule.length){
+			if (pricing_rule.length) {
+				item.pricing_rule = pricing_rule[0].name;
 				item.margin_type = pricing_rule[0].margin_type;
 				item.price_list_rate = pricing_rule[0].price || item.price_list_rate;
 				item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount;
 				item.discount_percentage = pricing_rule[0].discount_percentage || 0.0;
-				me.apply_pricing_rule_on_item(item)
-			} else if(item.discount_percentage > 0 || item.margin_rate_or_amount > 0) {
+			} else if ((item.discount_percentage > 0 || item.margin_rate_or_amount > 0) && item.pricing_rule) {
 				item.margin_rate_or_amount = 0.0;
 				item.discount_percentage = 0.0;
-				me.apply_pricing_rule_on_item(item)
+				item.pricing_rule = null;
 			}
+
+			me.apply_pricing_rule_on_item(item)
 		})
 	},
 
-	get_pricing_rule: function(item){
+	get_pricing_rule: function (item) {
 		var me = this;
-		return $.grep(this.pricing_rules, function(data){
-			if(item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty)) ){
-				if(data.item_code == item.item_code || in_list(['All Item Groups', item.item_group], data.item_group)) {
-					if(in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)){
+		return $.grep(this.pricing_rules, function (data) {
+			if (item.qty >= data.min_qty && (item.qty <= (data.max_qty ? data.max_qty : item.qty))) {
+				if (data.item_code == item.item_code || in_list(['All Item Groups', item.item_group], data.item_group)) {
+					if (in_list(['Customer', 'Customer Group', 'Territory', 'Campaign'], data.applicable_for)) {
 						return me.validate_condition(data)
-					}else{
+					} else {
 						return true
 					}
 				}
@@ -1173,15 +1375,15 @@
 		})
 	},
 
-	validate_condition: function(data){
+	validate_condition: function (data) {
 		//This method check condition based on applicable for
 		condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for]
-		if(in_list(condition[1], condition[0])){
+		if (in_list(condition[1], condition[0])) {
 			return true
 		}
 	},
 
-	get_mapper_for_pricing_rule: function(data){
+	get_mapper_for_pricing_rule: function (data) {
 		return {
 			'Customer': [data.customer, [this.frm.doc.customer]],
 			'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']],
@@ -1190,32 +1392,32 @@
 		}
 	},
 
-	validate_pricing_rule: function(pricing_rule){
+	validate_pricing_rule: function (pricing_rule) {
 		//This method validate duplicate pricing rule
 		var pricing_rule_name = '';
 		var priority = 0;
 		var pricing_rule_list = [];
 		var priority_list = []
 
-		if(pricing_rule.length > 1){
+		if (pricing_rule.length > 1) {
 
-			$.each(pricing_rule, function(index, data){
+			$.each(pricing_rule, function (index, data) {
 				pricing_rule_name += data.name + ','
 				priority_list.push(data.priority)
-				if(priority <= data.priority){
+				if (priority <= data.priority) {
 					priority = data.priority
 					pricing_rule_list.push(data)
 				}
 			})
 
 			count = 0
-			$.each(priority_list, function(index, value){
-				if(value == priority){
+			$.each(priority_list, function (index, value) {
+				if (value == priority) {
 					count++
 				}
 			})
 
-			if(priority == 0 || count > 1){
+			if (priority == 0 || count > 1) {
 				frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", {
 					'pricing_rule': pricing_rule_name
 				})))
@@ -1225,17 +1427,17 @@
 		}
 	},
 
-	validate_warehouse: function(){
-		if(this.items[0].is_stock_item && !this.items[0].default_warehouse && !this.pos_profile_data['warehouse']){
+	validate_warehouse: function () {
+		if (this.items[0].is_stock_item && !this.items[0].default_warehouse && !this.pos_profile_data['warehouse']) {
 			frappe.throw(__("Default warehouse is required for selected item"))
 		}
 	},
 
-	get_actual_qty: function(item) {
+	get_actual_qty: function (item) {
 		this.actual_qty = 0.0;
 
 		var warehouse = this.pos_profile_data['warehouse'] || item.default_warehouse;
-		if(warehouse && this.bin_data[item.item_code]) {
+		if (warehouse && this.bin_data[item.item_code]) {
 			this.actual_qty = this.bin_data[item.item_code][warehouse] || 0;
 			this.actual_qty_dict[item.item_code] = this.actual_qty
 		}
diff --git a/erpnext/accounts/party.py b/erpnext/accounts/party.py
index c65a845..a8d166e 100644
--- a/erpnext/accounts/party.py
+++ b/erpnext/accounts/party.py
@@ -8,8 +8,8 @@
 from frappe import _, msgprint, scrub
 from frappe.defaults import get_user_permissions
 from frappe.utils import add_days, getdate, formatdate, get_first_day, date_diff, add_years
-from erpnext.utilities.doctype.address.address import get_address_display
-from erpnext.utilities.doctype.contact.contact import get_contact_details
+from frappe.geo.doctype.address.address import get_address_display, get_default_address
+from frappe.email.doctype.contact.contact import get_contact_details, get_default_contact
 from erpnext.exceptions import PartyFrozen, InvalidCurrency, PartyDisabled, InvalidAccountCurrency
 
 class DuplicatePartyAccountError(frappe.ValidationError): pass
@@ -60,21 +60,18 @@
 def set_address_details(out, party, party_type):
 	billing_address_field = "customer_address" if party_type == "Lead" \
 		else party_type.lower() + "_address"
-	out[billing_address_field] = frappe.db.get_value("Address",
-		{party_type.lower(): party.name, "is_primary_address":1}, "name")
+	out[billing_address_field] = get_default_address(party_type, party.name)
 
 	# address display
 	out.address_display = get_address_display(out[billing_address_field])
 
 	# shipping address
 	if party_type in ["Customer", "Lead"]:
-		out.shipping_address_name = frappe.db.get_value("Address",
-			{party_type.lower(): party.name, "is_shipping_address":1}, "name")
+		out.shipping_address_name = get_default_address(party_type, party.name, 'is_shipping_address')
 		out.shipping_address = get_address_display(out["shipping_address_name"])
 
 def set_contact_details(out, party, party_type):
-	out.contact_person = frappe.db.get_value("Contact",
-		{party_type.lower(): party.name, "is_primary_contact":1}, "name")
+	out.contact_person = get_default_contact(party_type, party.name)
 
 	if not out.contact_person:
 		out.update({
@@ -174,17 +171,17 @@
 		account = frappe.db.get_value("Party Account",
 			{"parenttype": party_type, "parent": party, "company": company}, "account")
 
-		if not account:
+		if not account and party_type in ['Customer', 'Supplier']:
 			party_group_doctype = "Customer Group" if party_type=="Customer" else "Supplier Type"
 			group = frappe.db.get_value(party_type, party, scrub(party_group_doctype))
 			account = frappe.db.get_value("Party Account",
 				{"parenttype": party_group_doctype, "parent": group, "company": company}, "account")
 
-		if not account:
+		if not account and party_type in ['Customer', 'Supplier']:
 			default_account_name = "default_receivable_account" \
 				if party_type=="Customer" else "default_payable_account"
 			account = frappe.db.get_value("Company", company, default_account_name)
-			
+
 		existing_gle_currency = get_party_gle_currency(party_type, party, company)
 		if existing_gle_currency:
 			if account:
@@ -211,7 +208,7 @@
 
 	return frappe.local_cache("party_gle_currency", (party_type, party, company), generator,
 		regenerate_if_none=True)
-		
+
 def get_party_gle_account(party_type, party, company):
 	def generator():
 		existing_gle_account = frappe.db.sql("""select account from `tabGL Entry`
@@ -252,7 +249,7 @@
 		if existing_gle_currency and party_account_currency != existing_gle_currency:
 			frappe.throw(_("Accounting entries have already been made in currency {0} for company {1}. Please select a receivable or payable account with currency {0}.").format(existing_gle_currency, account.company))
 
-		if doc.default_currency and party_account_currency and company_default_currency:
+		if doc.get("default_currency") and party_account_currency and company_default_currency:
 			if doc.default_currency != party_account_currency and doc.default_currency != company_default_currency:
 				frappe.throw(_("Billing currency must be equal to either default comapany's currency or party account currency"))
 
@@ -340,19 +337,24 @@
 
 def validate_party_frozen_disabled(party_type, party_name):
 	if party_type and party_name:
-		party = frappe.db.get_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True)
-		if party.disabled:
-			frappe.throw(_("{0} {1} is disabled").format(party_type, party_name), PartyDisabled)
-		elif party.is_frozen:
-			frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
-			if not frozen_accounts_modifier in frappe.get_roles():
-				frappe.throw(_("{0} {1} is frozen").format(party_type, party_name), PartyFrozen)
+		if party_type in ("Customer", "Supplier"):
+			party = frappe.db.get_value(party_type, party_name, ["is_frozen", "disabled"], as_dict=True)
+			if party.disabled:
+				frappe.throw(_("{0} {1} is disabled").format(party_type, party_name), PartyDisabled)
+			elif party.get("is_frozen"):
+				frozen_accounts_modifier = frappe.db.get_value( 'Accounts Settings', None,'frozen_accounts_modifier')
+				if not frozen_accounts_modifier in frappe.get_roles():
+					frappe.throw(_("{0} {1} is frozen").format(party_type, party_name), PartyFrozen)
+
+		elif party_type == "Employee":
+			if frappe.db.get_value("Employee", party_name, "status") == "Left":
+				frappe.msgprint(_("{0} {1} is not active").format(party_type, party_name), PartyDisabled, alert=True)
 
 def get_timeline_data(doctype, name):
 	'''returns timeline data for the past one year'''
 	from frappe.desk.form.load import get_communication_data
 	data = get_communication_data(doctype, name,
 		fields = 'unix_timestamp(date(creation)), count(name)',
-		after = add_years(None, -1).strftime('%Y-%m-%d'),
+		after = add_years(None, -1).strftime('%Y-%m-%d'), limit = 366,
 		group_by='group by date(creation)', as_dict=False)
 	return dict(data)
\ No newline at end of file
diff --git a/erpnext/accounts/party_status.py b/erpnext/accounts/party_status.py
deleted file mode 100644
index 6d9efb1..0000000
--- a/erpnext/accounts/party_status.py
+++ /dev/null
@@ -1,81 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-
-import frappe
-
-from frappe.utils import evaluate_filters
-from frappe.desk.notifications import get_filters_for
-
-# NOTE: if you change this also update triggers in erpnext/hooks.py
-status_depends_on = {
-	'Customer': ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'Project', 'Issue'),
-	'Supplier': ('Supplier Quotation', 'Purchase Order', 'Purchase Receipt', 'Purchase Invoice')
-}
-
-default_status = {
-	'Customer': 'Active',
-	'Supplier': None
-}
-
-def notify_status(doc, method=None):
-	'''Notify status to customer, supplier'''
-
-	party_type = None
-	for key, doctypes in status_depends_on.iteritems():
-		if doc.doctype in doctypes:
-			party_type = key
-			break
-
-	if not party_type:
-		return
-
-	name = doc.get(party_type.lower())
-	if not name:
-		return
-
-	party = frappe.get_doc(party_type, name)
-	filters = get_filters_for(doc.doctype)
-	party.flags.ignore_mandatory = True
-
-	status = None
-	if filters:
-		if evaluate_filters(doc, filters):
-			# filters match, passed document is open
-			status = 'Open'
-
-	if status=='Open':
-		if party.status != 'Open':
-			# party not open, make it open
-			party.status = 'Open'
-			party.save(ignore_permissions=True)
-
-	else:
-		if party.status == 'Open':
-			# may be open elsewhere, check
-			# default status
-			update_status(party)
-
-	party.update_modified()
-	party.notify_update()
-
-def get_party_status(doc):
-	'''return party status based on open documents'''
-	status = default_status[doc.doctype]
-	for doctype in status_depends_on[doc.doctype]:
-		filters = get_filters_for(doctype)
-		filters[doc.doctype.lower()] = doc.name
-		if filters:
-			open_count = frappe.get_all(doctype, fields='name', filters=filters, limit_page_length=1)
-			if len(open_count) > 0:
-				status = 'Open'
-				break
-
-	return status
-
-def update_status(doc):
-	'''Set status as open if there is any open notification'''
-	status = get_party_status(doc)
-	if doc.status != status:
-		doc.db_set('status', status)
diff --git a/erpnext/accounts/print_format/point_of_sale/point_of_sale.json b/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
index 367ce07..f7d5f63 100644
--- a/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
+++ b/erpnext/accounts/print_format/point_of_sale/point_of_sale.json
@@ -7,10 +7,10 @@
  "docstatus": 0, 
  "doctype": "Print Format", 
  "font": "Default", 
- "html": "<style>\n\t.print-format table, .print-format tr, \n\t.print-format td, .print-format div, .print-format p {\n\t\tfont-family: Monospace;\n\t\tline-height: 200%;\n\t\tvertical-align: middle;\n\t}\n\t@media screen {\n\t\t.print-format {\n\t\t\twidth: 4in;\n\t\t\tpadding: 0.25in;\n\t\t\tmin-height: 8in;\n\t\t}\n\t}\n</style>\n\n<p class=\"text-center\">\n\t{{ company }}<br>\n\t{{  __(\"POS No : \") }}{{offline_pos_name}}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>\n</p>\n\n<hr>\n<table class=\"table table-condensed cart no-border\">\n\t<thead>\n\t\t<tr>\n\t\t\t<th width=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ format_number(item.qty, precision(\"difference\")) }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\n<table class=\"table table-condensed no-border\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ __(\"Net Total\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in taxes %}\n\t\t{% if not row.included_in_print_rate %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ row.description }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if discount_amount %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t{{ __(\"Discount\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(discount_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Grand Total\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Paid Amount\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(paid_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>", 
+ "html": "<style>\n\t.print-format table, .print-format tr, \n\t.print-format td, .print-format div, .print-format p {\n\t\tfont-family: Monospace;\n\t\tline-height: 200%;\n\t\tvertical-align: middle;\n\t}\n\t@media screen {\n\t\t.print-format {\n\t\t\twidth: 4in;\n\t\t\tpadding: 0.25in;\n\t\t\tmin-height: 8in;\n\t\t}\n\t}\n</style>\n\n<p class=\"text-center\">\n\t{{ company }}<br>\n\t{{  __(\"POS No : \") }}{{offline_pos_name}}<br>\n</p>\n<p>\n\t<b>{{ __(\"Date\") }}:</b> {{ dateutil.global_date_format(posting_date) }}<br>\n</p>\n\n<hr>\n<table class=\"table table-condensed cart no-border\">\n\t<thead>\n\t\t<tr>\n\t\t\t<th width=\"50%\">{{ __(\"Item\") }}</b></th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Qty\") }}</th>\n\t\t\t<th width=\"25%\" class=\"text-right\">{{ __(\"Amount\") }}</th>\n\t\t</tr>\n\t</thead>\n\t<tbody>\n\t\t{% for item in items %}\n\t\t<tr>\n\t\t\t<td>\n\t\t\t\t{{ item.item_name }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">{{ format_number(item.qty, precision(\"difference\")) }}<br>@ {{ format_currency(item.rate, currency) }}</td>\n\t\t\t<td class=\"text-right\">{{ format_currency(item.amount, currency) }}</td>\n\t\t</tr>\n\t\t{% endfor %}\n\t</tbody>\n</table>\n\n<table class=\"table table-condensed no-border\">\n\t<tbody>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ __(\"Net Total\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% for row in taxes %}\n\t\t{% if not row.included_in_print_rate %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 70%\">\n\t\t\t\t{{ row.description }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(row.tax_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t{% endfor %}\n\t\t{% if discount_amount %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t{{ __(\"Discount\") }}\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(discount_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t{% endif %}\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Grand Total\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(grand_total, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t\t<tr>\n\t\t\t<td class=\"text-right\" style=\"width: 75%\">\n\t\t\t\t<b>{{ __(\"Paid Amount\") }}</b>\n\t\t\t</td>\n\t\t\t<td class=\"text-right\">\n\t\t\t\t{{ format_currency(paid_amount, currency) }}\n\t\t\t</td>\n\t\t</tr>\n\t</tbody>\n</table>\n\n\n<hr>\n<p>{{ terms }}</p>\n<p class=\"text-center\">{{ __(\"Thank you, please visit again.\") }}</p>", 
  "idx": 0, 
  "line_breaks": 0, 
- "modified": "2016-12-27 17:22:17.391673", 
+ "modified": "2017-01-12 14:56:12.571032", 
  "modified_by": "Administrator", 
  "module": "Accounts", 
  "name": "Point of Sale", 
diff --git a/erpnext/accounts/report/cash_flow/cash_flow.py b/erpnext/accounts/report/cash_flow/cash_flow.py
index 182878a..7a776f5 100644
--- a/erpnext/accounts/report/cash_flow/cash_flow.py
+++ b/erpnext/accounts/report/cash_flow/cash_flow.py
@@ -10,7 +10,8 @@
 
 
 def execute(filters=None):
-	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity)
+	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, 
+		filters.periodicity)
 
 	operation_accounts = {
 		"section_name": "Operations",
@@ -103,7 +104,7 @@
 	data = {}
 	total = 0
 	for period in period_list:
-		start_date = get_start_date(period, accumulated_values)
+		start_date = get_start_date(period, accumulated_values, company)
 		gl_sum = frappe.db.sql_list("""
 			select sum(credit) - sum(debit)
 			from `tabGL Entry`
@@ -126,10 +127,10 @@
 	data["total"] = total
 	return data
 
-def get_start_date(period, accumulated_values):
+def get_start_date(period, accumulated_values, company):
 	start_date = period["year_start_date"]
 	if accumulated_values:
-		start_date = get_fiscal_year(period.to_date)[1]
+		start_date = get_fiscal_year(period.to_date, company=company)[1]
 
 	return start_date
 
diff --git a/erpnext/accounts/report/financial_statements.py b/erpnext/accounts/report/financial_statements.py
index bc4a220..c897d1c 100644
--- a/erpnext/accounts/report/financial_statements.py
+++ b/erpnext/accounts/report/financial_statements.py
@@ -3,10 +3,8 @@
 
 from __future__ import unicode_literals
 import frappe
-import math
 from frappe import _
-from frappe.utils import (flt, getdate, get_first_day, get_last_day, date_diff,
-	add_months, add_days, formatdate, cint)
+from frappe.utils import flt, getdate, get_first_day, add_months, add_days, formatdate
 
 def get_period_list(from_fiscal_year, to_fiscal_year, periodicity):
 	"""Get a list of dict {"from_date": from_date, "to_date": to_date, "key": key, "label": label}
@@ -149,7 +147,6 @@
 				
 def get_date_fiscal_year(date):
 	from erpnext.accounts.utils import get_fiscal_year
-	
 	return get_fiscal_year(date)[0]
 
 def accumulate_values_into_parents(accounts, accounts_by_name, period_list, accumulated_values):
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.js b/erpnext/accounts/report/general_ledger/general_ledger.js
index dc79d1f..a422871 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.js
+++ b/erpnext/accounts/report/general_ledger/general_ledger.js
@@ -48,13 +48,19 @@
 			"fieldtype": "Data",
 		},
 		{
+			"fieldname":"project",
+			"label": __("Project"),
+			"fieldtype": "Link",
+			"options": "Project"
+		},
+		{
 			"fieldtype": "Break",
 		},
 		{
 			"fieldname":"party_type",
 			"label": __("Party Type"),
-			"fieldtype": "Select",
-			"options": ["", "Customer", "Supplier"],
+			"fieldtype": "Link",
+			"options": "Party Type",
 			"default": ""
 		},
 		{
diff --git a/erpnext/accounts/report/general_ledger/general_ledger.py b/erpnext/accounts/report/general_ledger/general_ledger.py
index 00c17e8..d09ac70 100644
--- a/erpnext/accounts/report/general_ledger/general_ledger.py
+++ b/erpnext/accounts/report/general_ledger/general_ledger.py
@@ -149,6 +149,9 @@
 	if not (filters.get("account") or filters.get("party") or filters.get("group_by_account")):
 		conditions.append("posting_date >=%(from_date)s")
 
+	if filters.get("project"):
+		conditions.append("project=%(project)s")
+
 	from frappe.desk.reportview import build_match_conditions
 	match_conditions = build_match_conditions("GL Entry")
 	if match_conditions: conditions.append(match_conditions)
diff --git a/erpnext/accounts/report/gross_profit/gross_profit.py b/erpnext/accounts/report/gross_profit/gross_profit.py
index 3451238..df6cb3c 100644
--- a/erpnext/accounts/report/gross_profit/gross_profit.py
+++ b/erpnext/accounts/report/gross_profit/gross_profit.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _, scrub
+from erpnext.stock.utils import get_incoming_rate
 from frappe.utils import flt
 
 
@@ -208,21 +209,18 @@
 								flt(my_sle[i+1].stock_value) or 0.0
 							return  previous_stock_value - flt(sle.stock_value)
 			else:
-				return flt(row.qty) * self.get_average_buying_rate(item_code)
-
+				return flt(row.qty) * self.get_average_buying_rate(row, item_code)
 
 		return 0.0
 
-	def get_average_buying_rate(self, item_code):
+	def get_average_buying_rate(self, row, item_code):
 		if not item_code in self.average_buying_rate:
 			if item_code in self.non_stock_items:
 				self.average_buying_rate[item_code] = flt(frappe.db.sql("""select sum(base_net_amount) / sum(qty * conversion_factor)
 					from `tabPurchase Invoice Item`
 					where item_code = %s and docstatus=1""", item_code)[0][0])
 			else:
-				self.average_buying_rate[item_code] = flt(frappe.db.sql("""select avg(valuation_rate)
-					from `tabStock Ledger Entry`
-					where item_code = %s and qty_after_transaction > 0""", item_code)[0][0])
+				self.average_buying_rate[item_code] = get_incoming_rate(row)
 
 		return self.average_buying_rate[item_code]
 
diff --git a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
index 85c7daa..a7d1820 100644
--- a/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
+++ b/erpnext/accounts/report/payment_period_based_on_invoice_date/payment_period_based_on_invoice_date.py
@@ -46,7 +46,7 @@
 
 def get_columns(filters):
 	return [
-		_("Payment Document") + ":Link/DocType: 100",
+		_("Payment Document") + ":: 100",
 		_("Payment Entry") + ":Dynamic Link/"+_("Payment Document")+":140",
 		_("Party Type") + "::100", 
 		_("Party") + ":Dynamic Link/Party Type:140",
diff --git a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
index 747eb43..254523f 100644
--- a/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
+++ b/erpnext/accounts/report/profit_and_loss_statement/profit_and_loss_statement.py
@@ -9,12 +9,12 @@
 
 def execute(filters=None):
 	period_list = get_period_list(filters.from_fiscal_year, filters.to_fiscal_year, filters.periodicity)
-	
+
 	income = get_data(filters.company, "Income", "Credit", period_list, filters = filters,
 		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
 	expense = get_data(filters.company, "Expense", "Debit", period_list, filters=filters,
 		accumulated_values=filters.accumulated_values, ignore_closing_entries=True, ignore_accumulated_values_for_fy= True)
-	
+
 	net_profit_loss = get_net_profit_loss(income, expense, period_list, filters.company)
 
 	data = []
@@ -24,7 +24,7 @@
 		data.append(net_profit_loss)
 
 	columns = get_columns(filters.periodicity, period_list, filters.accumulated_values, filters.company)
-	
+
 	chart = get_chart_data(filters, columns, income, expense, net_profit_loss)
 
 	return columns, data, None, chart
@@ -43,21 +43,21 @@
 
 		for period in period_list:
 			net_profit_loss[period.key] = flt(income[-2][period.key] - expense[-2][period.key], 3)
-			
+
 			if net_profit_loss[period.key]:
 				has_value=True
-			
+
 			total += flt(net_profit_loss[period.key])
 			net_profit_loss["total"] = total
-		
+
 		if has_value:
 			return net_profit_loss
 
 def get_chart_data(filters, columns, income, expense, net_profit_loss):
 	x_intervals = ['x'] + [d.get("label") for d in columns[2:]]
-	
+
 	income_data, expense_data, net_profit = [], [], []
-	
+
 	for p in columns[2:]:
 		if income:
 			income_data.append(income[-2].get(p.get("fieldname")))
@@ -65,7 +65,7 @@
 			expense_data.append(expense[-2].get(p.get("fieldname")))
 		if net_profit_loss:
 			net_profit.append(net_profit_loss.get(p.get("fieldname")))
-			
+
 	columns = [x_intervals]
 	if income_data:
 		columns.append(["Income"] + income_data)
@@ -73,15 +73,20 @@
 		columns.append(["Expense"] + expense_data)
 	if net_profit:
 		columns.append(["Net Profit/Loss"] + net_profit)
-		
+
 	chart = {
 		"data": {
 			'x': 'x',
-			'columns': columns
+			'columns': columns,
+			'colors': {
+				'Income': '#5E64FF',
+				'Expense': '#b8c2cc',
+				'Net Profit/Loss': '#ff5858'
+			}
 		}
 	}
-	
+
 	if not filters.accumulated_values:
 		chart["chart_type"] = "bar"
-		
+
 	return chart
\ No newline at end of file
diff --git a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
index 4f9fd15..c0a4212 100644
--- a/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
+++ b/erpnext/accounts/report/profitability_analysis/profitability_analysis.py
@@ -11,9 +11,11 @@
 value_fields = ("income", "expense", "gross_profit_loss")
 
 def execute(filters=None):
+	if not filters.get('based_on'): filters["based_on"] = 'Cost Center'
+
 	based_on = filters.based_on.replace(' ', '_').lower()
 	validate_filters(filters)
-	accounts = get_accounts_data(based_on, filters.company)
+	accounts = get_accounts_data(based_on, filters.get("company"))
 	data = get_data(accounts, filters, based_on)
 	columns = get_columns(filters)
 	return columns, data
@@ -21,20 +23,20 @@
 def get_accounts_data(based_on, company):
 	if based_on == 'cost_center':
 		return frappe.db.sql("""select name, parent_cost_center as parent_account, cost_center_name as account_name, lft, rgt
-			from `tabCost Center` where company=%s order by lft""", company, as_dict=True)
+			from `tabCost Center` where company=%s order by name""", company, as_dict=True)
 	else:
-		return frappe.get_all('Project', fields = ["name"], filters = {'company': company})
+		return frappe.get_all('Project', fields = ["name"], filters = {'company': company}, order_by = 'name')
 
 def get_data(accounts, filters, based_on):
 	if not accounts:
-		return None
+		return []
 
 	accounts, accounts_by_name, parent_children_map = filter_accounts(accounts)
 
 	gl_entries_by_account = {}
 
-	set_gl_entries_by_account(filters.company, filters.from_date,
-		filters.to_date, based_on, gl_entries_by_account, ignore_closing_entries=not flt(filters.with_period_closing_entry))
+	set_gl_entries_by_account(filters.get("company"), filters.get("from_date"),
+		filters.get("to_date"), based_on, gl_entries_by_account, ignore_closing_entries=not flt(filters.get("with_period_closing_entry")))
 
 	total_row = calculate_values(accounts, gl_entries_by_account, filters)
 	accumulate_values_into_parents(accounts, accounts_by_name)
@@ -90,7 +92,7 @@
 
 def prepare_data(accounts, filters, total_row, parent_children_map, based_on):
 	data = []
-	company_currency = frappe.db.get_value("Company", filters.company, "default_currency")
+	company_currency = frappe.db.get_value("Company", filters.get("company"), "default_currency")
 
 	for d in accounts:
 		has_value = False
@@ -99,7 +101,7 @@
 			"account": d.name,
 			"parent_account": d.parent_account,
 			"indent": d.indent,
-			"fiscal_year": filters.fiscal_year,
+			"fiscal_year": filters.get("fiscal_year"),
 			"currency": company_currency,
 			"based_on": based_on
 		}
@@ -122,9 +124,9 @@
 	return [
 		{
 			"fieldname": "account",
-			"label": _(filters.based_on),
+			"label": _(filters.get("based_on")),
 			"fieldtype": "Link",
-			"options": filters.based_on,
+			"options": filters.get("based_on"),
 			"width": 300
 		},
 		{
diff --git a/erpnext/docs/assets/img/fleet-management/__init__.py b/erpnext/accounts/report/unpaid_expense_claim/__init__.py
similarity index 100%
copy from erpnext/docs/assets/img/fleet-management/__init__.py
copy to erpnext/accounts/report/unpaid_expense_claim/__init__.py
diff --git a/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.js b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.js
new file mode 100644
index 0000000..811414a
--- /dev/null
+++ b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.js
@@ -0,0 +1,12 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Unpaid Expense Claim"] = {
+	"filters": [
+		{
+			"fieldname":"employee",
+			"label": __("Employee"),
+			"fieldtype": "Link"
+		}
+	]
+}
diff --git a/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.json b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.json
new file mode 100644
index 0000000..a1087c0
--- /dev/null
+++ b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.json
@@ -0,0 +1,18 @@
+{
+ "add_total_row": 0, 
+ "apply_user_permissions": 1, 
+ "creation": "2017-01-04 16:26:18.309717", 
+ "disabled": 0, 
+ "docstatus": 0, 
+ "doctype": "Report", 
+ "idx": 0, 
+ "is_standard": "Yes", 
+ "modified": "2017-01-04 16:26:18.309717", 
+ "modified_by": "Administrator", 
+ "module": "Accounts", 
+ "name": "Unpaid Expense Claim", 
+ "owner": "Administrator", 
+ "ref_doctype": "Expense Claim", 
+ "report_name": "Unpaid Expense Claim", 
+ "report_type": "Script Report"
+}
\ No newline at end of file
diff --git a/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.py b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.py
new file mode 100644
index 0000000..eee620b
--- /dev/null
+++ b/erpnext/accounts/report/unpaid_expense_claim/unpaid_expense_claim.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2013, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+
+def execute(filters=None):
+	columns, data = [], []
+	columns = get_columns()
+	data = get_unclaimed_expese_claims(filters)
+	return columns, data
+
+def get_columns():
+	return [_("Employee") + ":Link/Employee:120", _("Employee Name") + "::120",_("Expense Claim") + ":Link/Expense Claim:120",
+		_("Sanctioned Amount") + ":Currency:120", _("Paid Amount") + ":Currency:120", _("Outstanding Amount") + ":Currency:150"]
+
+def get_unclaimed_expese_claims(filters):
+	cond = "1=1"
+	if filters.get("employee"):
+		cond = "ec.employee = %(employee)s"
+
+	return frappe.db.sql(""" 
+		select
+			ec.employee, ec.employee_name, ec.name, ec.total_sanctioned_amount, ec.total_amount_reimbursed,
+			sum(gle.credit_in_account_currency - gle.debit_in_account_currency) as outstanding_amt
+		from 
+			`tabExpense Claim` ec, `tabGL Entry` gle
+		where
+			gle.against_voucher_type = "Expense Claim" and gle.against_voucher = ec.name
+			and gle.party is not null and ec.docstatus = 1 and ec.is_paid = 0 and {cond} group by ec.name
+		having
+			outstanding_amt > 0
+	""".format(cond=cond), filters, as_list=1)
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 8e59d8f..c2812d4 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -20,32 +20,63 @@
 	return get_fiscal_years(date, fiscal_year, label, verbose, company, as_dict=as_dict)[0]
 
 def get_fiscal_years(transaction_date=None, fiscal_year=None, label="Date", verbose=1, company=None, as_dict=False):
-	# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
-	cond = " disabled = 0"
-	if fiscal_year:
-		cond += " and fy.name = %(fiscal_year)s"
-	else:
-		cond += " and %(transaction_date)s >= fy.year_start_date and %(transaction_date)s <= fy.year_end_date"
+	fiscal_years = frappe.cache().hget("fiscal_years", company) or []
+	
+	if not fiscal_years:		
+		# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
+		cond = ""
+		if fiscal_year:
+			cond += " and fy.name = {0}".format(frappe.db.escape(fiscal_year))
+		if company:
+			cond += """
+				and (not exists (select name 
+					from `tabFiscal Year Company` fyc 
+					where fyc.parent = fy.name) 
+				or exists(select company 
+					from `tabFiscal Year Company` fyc 
+					where fyc.parent = fy.name 
+					and fyc.company=%(company)s)
+				)
+			"""
 
-	if company:
-		cond += """ and (not exists(select name from `tabFiscal Year Company` fyc where fyc.parent = fy.name)
-			or exists(select company from `tabFiscal Year Company` fyc where fyc.parent = fy.name and fyc.company=%(company)s ))"""
+		fiscal_years = frappe.db.sql("""
+			select 
+				fy.name, fy.year_start_date, fy.year_end_date 
+			from 
+				`tabFiscal Year` fy
+			where 
+				disabled = 0 {0}
+			order by 
+				fy.year_start_date desc""".format(cond), {
+				"company": company
+			}, as_dict=True)
+			
+		frappe.cache().hset("fiscal_years", company, fiscal_years)
 
-	fy = frappe.db.sql("""select fy.name, fy.year_start_date, fy.year_end_date from `tabFiscal Year` fy
-		where %s order by fy.year_start_date desc""" % cond, {
-			"fiscal_year": fiscal_year,
-			"transaction_date": transaction_date,
-			"company": company
-		}, as_dict=as_dict)
+	if transaction_date:
+		transaction_date = getdate(transaction_date)
 
-	if not fy:
-		error_msg = _("""{0} {1} not in any active Fiscal Year. For more details check {2}.""").format(label, formatdate(transaction_date), "https://frappe.github.io/erpnext/user/manual/en/accounts/articles/fiscal-year-error")
-		if verbose==1: frappe.msgprint(error_msg)
-		raise FiscalYearError, error_msg
-	return fy
+	for fy in fiscal_years:
+		matched = False
+		if fiscal_year and fy.name == fiscal_year:
+			matched = True
 
-def validate_fiscal_year(date, fiscal_year, label=_("Date"), doc=None):
-	years = [f[0] for f in get_fiscal_years(date, label=label)]
+		if (transaction_date and getdate(fy.year_start_date) <= transaction_date 
+			and getdate(fy.year_end_date) >= transaction_date):
+			matched = True
+			
+		if matched:
+			if as_dict:
+				return (fy,)
+			else:
+				return ((fy.name, fy.year_start_date, fy.year_end_date),)
+
+	error_msg = _("""{0} {1} not in any active Fiscal Year.""").format(label, formatdate(transaction_date))
+	if verbose==1: frappe.msgprint(error_msg)
+	raise FiscalYearError, error_msg
+
+def validate_fiscal_year(date, fiscal_year, company, label=_("Date"), doc=None):
+	years = [f[0] for f in get_fiscal_years(date, label=label, company=company)]
 	if fiscal_year not in years:
 		if doc:
 			doc.fiscal_year = years[0]
@@ -206,9 +237,13 @@
 
 @frappe.whitelist()
 def add_ac(args=None):
+	from frappe.desk.treeview import make_tree_args
+
 	if not args:
 		args = frappe.local.form_dict
-		args.pop("cmd")
+
+	args.doctype = "Account"
+	args = make_tree_args(**args)
 
 	ac = frappe.new_doc("Account")
 
@@ -233,9 +268,13 @@
 
 @frappe.whitelist()
 def add_cc(args=None):
+	from frappe.desk.treeview import make_tree_args
+
 	if not args:
 		args = frappe.local.form_dict
-		args.pop("cmd")
+	
+	args.doctype = "Cost Center"
+	args = make_tree_args(**args)
 
 	cc = frappe.new_doc("Cost Center")
 	cc.update(args)
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.js b/erpnext/buying/doctype/purchase_common/purchase_common.js
index 5d74760..c03ccc8 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.js
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.js
@@ -21,20 +21,12 @@
 		if(this.frm.get_field('shipping_address')) {
 			this.frm.set_query("shipping_address", function(){
 				if(me.frm.doc.customer){
-					return{
-						filters:{
-							"customer": me.frm.doc.customer
-						}
-					}
-				}
-				else{
-					return{
-						filters:{
-							"is_your_company_address": 1,
-							"company": me.frm.doc.company
-						}
-					}
-				}
+					return {
+						query: 'frappe.geo.doctype.address.address.address_query',
+						filters: { link_doctype: 'Customer', link_name: me.frm.doc.customer }
+					};
+				} else
+					return erpnext.queries.company_address_query(me.frm.doc)
 			});
 		}
 	},
@@ -50,13 +42,9 @@
 			});
 		}
 
-		$.each([["supplier", "supplier"],
-			["contact_person", "supplier_filter"],
-			["supplier_address", "supplier_filter"]],
-			function(i, opts) {
-				if(me.frm.fields_dict[opts[0]])
-					me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
-			});
+		me.frm.set_query('supplier', erpnext.queries.supplier);
+		me.frm.set_query('contact_person', erpnext.queries.contact_query);
+		me.frm.set_query('supplier_address', erpnext.queries.address_query);
 
 		if(this.frm.fields_dict.supplier) {
 			this.frm.set_query("supplier", function() {
@@ -79,6 +67,8 @@
 	},
 
 	refresh: function(doc) {
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'supplier', doctype: 'Supplier'};
+
 		this.frm.toggle_display("supplier_name",
 			(this.frm.doc.supplier_name && this.frm.doc.supplier_name!==this.frm.doc.supplier));
 
diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js
index 15356fd..0a577c3 100644
--- a/erpnext/buying/doctype/purchase_order/purchase_order.js
+++ b/erpnext/buying/doctype/purchase_order/purchase_order.js
@@ -66,7 +66,7 @@
 
 		if(doc.docstatus == 1 && doc.status != "Closed") {
 			if(flt(doc.per_received, 2) < 100 && allow_receipt) {
-				cur_frm.add_custom_button(__('Receive'), this.make_purchase_receipt, __("Make"));
+				cur_frm.add_custom_button(__('Receipt'), this.make_purchase_receipt, __("Make"));
 
 				if(doc.is_subcontracted==="Yes") {
 					cur_frm.add_custom_button(__('Material to Supplier'),
@@ -226,18 +226,6 @@
 	})
 }
 
-cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters: {'supplier': doc.supplier}
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters: {'supplier': doc.supplier}
-	}
-}
-
 cur_frm.fields_dict['items'].grid.get_field('project').get_query = function(doc, cdt, cdn) {
 	return {
 		filters:[
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
index 6847a98..113dbe0 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.js
@@ -134,6 +134,42 @@
 						}
 					})
 				}, __("Get items from"));
+				
+				// Get items from open Material Requests based on supplier
+				cur_frm.add_custom_button(__('Possible Supplier'), function() {
+					// Create a dialog window for the user to pick their supplier
+					var d = new frappe.ui.Dialog({
+						title: __('Select Possible Supplier'),
+						fields: [
+						{fieldname: 'supplier', fieldtype:'Link', options:'Supplier', label:'Supplier', reqd:1},
+						{fieldname: 'ok_button', fieldtype:'Button', label:'Get Items from Material Requests'},
+						]
+					});
+					
+					// On the user clicking the ok button
+					d.fields_dict.ok_button.input.onclick = function() {
+						var btn = d.fields_dict.ok_button.input;
+						var v = d.get_values();
+						if(v) {
+							$(btn).set_working();
+							
+							erpnext.utils.map_current_doc({
+								method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.get_item_from_material_requests_based_on_supplier",
+								source_name: v.supplier,
+								get_query_filters: {
+									material_request_type: "Purchase",
+									docstatus: 1,
+									status: ["!=", "Stopped"],
+									per_ordered: ["<", 99.99],
+									company: cur_frm.doc.company
+								}
+							});
+							$(btn).done_working();
+							d.hide();
+						}
+					}	
+					d.show();
+				}, __("Get items from"));
 		}
 	},
 
diff --git a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
index 3ff45f5..6300864 100644
--- a/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
+++ b/erpnext/buying/doctype/request_for_quotation/request_for_quotation.py
@@ -6,7 +6,7 @@
 import frappe, json
 from frappe import _
 from frappe.model.mapper import get_mapped_doc
-from frappe.utils import get_url, random_string, cint
+from frappe.utils import get_url, cint
 from frappe.utils.user import get_user_fullname
 from frappe.utils.print_format import download_pdf
 from frappe.desk.form.load import get_attachments
@@ -244,3 +244,49 @@
 		args = doc.get('suppliers')[cint(supplier_idx) - 1]
 		doc.update_supplier_part_no(args)
 		return doc
+		
+@frappe.whitelist()
+def get_item_from_material_requests_based_on_supplier(source_name, target_doc = None):
+	mr_items_list = frappe.db.sql("""
+		SELECT
+			mr.name, mr_item.item_code
+		FROM
+			`tabItem` as item, 
+			`tabItem Supplier` as item_supp, 
+			`tabMaterial Request Item` as mr_item, 
+			`tabMaterial Request`  as mr 
+		WHERE item_supp.supplier = %(supplier)s 
+			AND item.name = item_supp.parent 
+			AND mr_item.parent = mr.name 
+			AND mr_item.item_code = item.name 
+			AND mr.status != "Stopped" 
+			AND mr.material_request_type = "Purchase" 
+			AND mr.docstatus = 1 
+			AND mr.per_ordered < 99.99""", {"supplier": source_name}, as_dict=1)
+	
+	material_requests = {}
+	for d in mr_items_list:
+		material_requests.setdefault(d.name, []).append(d.item_code)
+
+	for mr, items in material_requests.items():
+		target_doc = get_mapped_doc("Material Request", mr, {
+			"Material Request": {
+				"doctype": "Request for Quotation",
+				"validation": {
+					"docstatus": ["=", 1],
+					"material_request_type": ["=", "Purchase"],
+				}
+			},
+			"Material Request Item": {
+				"doctype": "Request for Quotation Item",
+				"condition": lambda row: row.item_code in items,
+				"field_map": [
+					["name", "material_request_item"],
+					["parent", "material_request"],
+					["uom", "uom"]
+				]
+			}
+		}, target_doc)
+		
+	return target_doc
+		
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier.js b/erpnext/buying/doctype/supplier/supplier.js
index b176e00..7e5e045 100644
--- a/erpnext/buying/doctype/supplier/supplier.js
+++ b/erpnext/buying/doctype/supplier/supplier.js
@@ -16,6 +16,8 @@
 		});
 	},
 	refresh: function(frm) {
+		frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Supplier'}
+
 		if(frappe.defaults.get_default("supp_master_name")!="Naming Series") {
 			frm.toggle_display("naming_series", false);
 		} else {
@@ -24,11 +26,11 @@
 
 		if(frm.doc.__islocal){
 	    	hide_field(['address_html','contact_html']);
-			erpnext.utils.clear_address_and_contact(frm);
+			frappe.geo.clear_address_and_contact(frm);
 		}
 		else {
 		  	unhide_field(['address_html','contact_html']);
-			erpnext.utils.render_address_and_contact(frm);
+			frappe.geo.render_address_and_contact(frm);
 
 			// custom buttons
 			frm.add_custom_button(__('Accounting Ledger'), function() {
diff --git a/erpnext/buying/doctype/supplier/supplier.json b/erpnext/buying/doctype/supplier/supplier.json
index 4b8f8c5..277a5b9 100644
--- a/erpnext/buying/doctype/supplier/supplier.json
+++ b/erpnext/buying/doctype/supplier/supplier.json
@@ -163,35 +163,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "status", 
-   "fieldtype": "Select", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Status", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nOpen", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -796,7 +767,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:24:30.465053", 
+ "modified": "2017-01-30 00:52:31.193443", 
  "modified_by": "Administrator", 
  "module": "Buying", 
  "name": "Supplier", 
@@ -813,7 +784,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -834,7 +804,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -855,7 +824,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -876,7 +844,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -897,7 +864,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -918,7 +884,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -939,7 +904,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -957,5 +921,6 @@
  "search_fields": "supplier_name, supplier_type", 
  "sort_order": "ASC", 
  "title_field": "supplier_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier.py b/erpnext/buying/doctype/supplier/supplier.py
index 3677ee2..704e828 100644
--- a/erpnext/buying/doctype/supplier/supplier.py
+++ b/erpnext/buying/doctype/supplier/supplier.py
@@ -6,10 +6,11 @@
 import frappe.defaults
 from frappe import msgprint, _
 from frappe.model.naming import make_autoname
-from erpnext.utilities.address_and_contact import load_address_and_contact
+from frappe.geo.address_and_contact import (load_address_and_contact,
+	delete_contact_and_address)
+
 from erpnext.utilities.transaction_base import TransactionBase
 from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
-from erpnext.accounts.party_status import get_party_status
 
 class Supplier(TransactionBase):
 	def get_feed(self):
@@ -46,21 +47,10 @@
 		else:
 			self.name = make_autoname(self.naming_series + '.#####')
 
-	def update_address(self):
-		frappe.db.sql("""update `tabAddress` set supplier_name=%s, modified=NOW()
-			where supplier=%s""", (self.supplier_name, self.name))
-
-	def update_contact(self):
-		frappe.db.sql("""update `tabContact` set supplier_name=%s, modified=NOW()
-			where supplier=%s""", (self.supplier_name, self.name))
-
 	def on_update(self):
 		if not self.naming_series:
 			self.naming_series = ''
 
-		self.update_address()
-		self.update_contact()
-
 	def validate(self):
 		#validation for Naming Series mandatory field...
 		if frappe.defaults.get_global_default('supp_master_name') == 'Naming Series':
@@ -68,38 +58,10 @@
 				msgprint(_("Series is mandatory"), raise_exception=1)
 
 		validate_party_accounts(self)
-		self.status = get_party_status(self)
-
-	def get_contacts(self,nm):
-		if nm:
-			contact_details =frappe.db.convert_to_lists(frappe.db.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = %s", nm))
-
-			return contact_details
-		else:
-			return ''
-
-	def delete_supplier_address(self):
-		for rec in frappe.db.sql("select * from `tabAddress` where supplier=%s", (self.name,), as_dict=1):
-			frappe.db.sql("delete from `tabAddress` where name=%s",(rec['name']))
-
-	def delete_supplier_contact(self):
-		for contact in frappe.db.sql_list("""select name from `tabContact`
-			where supplier=%s""", self.name):
-				frappe.delete_doc("Contact", contact)
 
 	def on_trash(self):
-		self.delete_supplier_address()
-		self.delete_supplier_contact()
+		delete_contact_and_address('Supplier', self.name)
 
 	def after_rename(self, olddn, newdn, merge=False):
-		set_field = ''
 		if frappe.defaults.get_global_default('supp_master_name') == 'Supplier Name':
 			frappe.db.set(self, "supplier_name", newdn)
-			self.update_contact()
-			set_field = ", supplier_name=%(newdn)s"
-		self.update_supplier_address(newdn, set_field)
-
-	def update_supplier_address(self, newdn, set_field):
-		frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
-			{set_field} where supplier=%(newdn)s"""\
-			.format(set_field=set_field), ({"newdn": newdn}))
\ No newline at end of file
diff --git a/erpnext/buying/doctype/supplier/supplier_list.js b/erpnext/buying/doctype/supplier/supplier_list.js
index acf8e68..dd98c43 100644
--- a/erpnext/buying/doctype/supplier/supplier_list.js
+++ b/erpnext/buying/doctype/supplier/supplier_list.js
@@ -1,8 +1,3 @@
 frappe.listview_settings['Supplier'] = {
-	add_fields: ["supplier_name", "supplier_type", 'status'],
-	get_indicator: function(doc) {
-		if(doc.status==="Open") {
-			return [doc.status, "red", "status,=," + doc.status];
-		}
-	}
+	add_fields: ["supplier_name", "supplier_type"],
 };
diff --git a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
index fc9cc3b..b3bdeb0 100644
--- a/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
+++ b/erpnext/buying/doctype/supplier_quotation/supplier_quotation.js
@@ -59,15 +59,3 @@
 			]
 		}
 	}
-
-cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters:{'supplier': doc.supplier}
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters:{'supplier': doc.supplier}
-	}
-}
diff --git a/erpnext/buying/report/supplier_addresses_and_contacts/__init__.py b/erpnext/buying/report/supplier_addresses_and_contacts/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/buying/report/supplier_addresses_and_contacts/__init__.py
+++ /dev/null
diff --git a/erpnext/buying/report/supplier_addresses_and_contacts/supplier_addresses_and_contacts.json b/erpnext/buying/report/supplier_addresses_and_contacts/supplier_addresses_and_contacts.json
deleted file mode 100644
index 128548f..0000000
--- a/erpnext/buying/report/supplier_addresses_and_contacts/supplier_addresses_and_contacts.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "apply_user_permissions": 1, 
- "creation": "2013-10-09 10:38:40", 
- "docstatus": 0, 
- "doctype": "Report", 
- "idx": 1, 
- "is_standard": "Yes", 
- "modified": "2014-09-11 08:53:17.358554", 
- "modified_by": "Administrator",
- "module": "Buying", 
- "name": "Supplier Addresses and Contacts", 
- "owner": "Administrator", 
- "query": "SELECT\n    `tabSupplier`.name as \"Supplier:Link/Supplier:120\",\n\t`tabSupplier`.supplier_name as \"Supplier Name::120\",\n\t`tabSupplier`.supplier_type as \"Supplier Type:Link/Supplier Type:120\",\n\tconcat_ws(', ', \n\t\ttrim(',' from `tabAddress`.address_line1), \n\t\ttrim(',' from tabAddress.address_line2), \n\t\ttabAddress.state, tabAddress.pincode, tabAddress.country\n\t) as 'Address::180',\n    concat_ws(', ', `tabContact`.first_name, `tabContact`.last_name) as \"Contact Name::180\",\n\t`tabContact`.phone as \"Phone\",\n\t`tabContact`.mobile_no as \"Mobile No\",\n\t`tabContact`.email_id as \"Email Address::120\",\n\t`tabContact`.is_primary_contact as \"Is Primary Contact::120\"\nFROM\n\t`tabSupplier`\n\tleft join `tabAddress` on (\n\t\t`tabAddress`.supplier=`tabSupplier`.name\n\t)\n\tleft join `tabContact` on (\n\t\t`tabContact`.supplier=`tabSupplier`.name\n\t)\nWHERE\n\t`tabSupplier`.docstatus<2\nORDER BY\n\t`tabSupplier`.name asc", 
- "ref_doctype": "Supplier", 
- "report_name": "Supplier Addresses and Contacts", 
- "report_type": "Query Report"
-}
\ No newline at end of file
diff --git a/erpnext/config/buying.py b/erpnext/config/buying.py
index e246266..990ca7a 100644
--- a/erpnext/config/buying.py
+++ b/erpnext/config/buying.py
@@ -172,8 +172,12 @@
 				{
 					"type": "report",
 					"is_query_report": True,
-					"name": "Supplier Addresses and Contacts",
-					"doctype": "Supplier"
+					"name": "Addresses And Contacts",
+					"label": "Supplier Addresses And Contacts",
+					"doctype": "Address",
+					"route_options": {
+						"party_type": "Supplier"
+					}
 				},
 			]
 		},
diff --git a/erpnext/config/desktop.py b/erpnext/config/desktop.py
index 9397ffc..029ef74 100644
--- a/erpnext/config/desktop.py
+++ b/erpnext/config/desktop.py
@@ -229,15 +229,6 @@
 			"type": "list"
 		},
 		{
-			"module_name": "Assessment",
-			"color": "#8a70be",
-			"icon": "fa fa-file-text-alt",
-			"label": _("Assessment"),
-			"link": "List/Assessment",
-			"_doctype": "Assessment",
-			"type": "list"
-		},
-		{
 			"module_name": "Fees",
 			"color": "#83C21E",
 			"icon": "fa fa-money",
diff --git a/erpnext/config/hr.py b/erpnext/config/hr.py
index 55363ab..0a969ed 100644
--- a/erpnext/config/hr.py
+++ b/erpnext/config/hr.py
@@ -146,6 +146,11 @@
 					"name": "Appraisal Template",
 					"description": _("Template for performance appraisals.")
 				},
+				{
+					"type": "page",
+					"name": "team-updates",
+					"label": _("Team Updates")
+				},
 			]
 		},
 
@@ -168,6 +173,21 @@
 		},
 
 		{
+			"label": _("Fleet Management"),
+			"items": [
+				{
+					"type": "doctype",
+					"name": "Vehicle"
+				},
+				{
+					"type": "doctype",
+					"name": "Vehicle Log"
+				},
+			]
+		},
+
+
+		{
 			"label": _("Setup"),
 			"icon": "fa fa-cog",
 			"items": [
@@ -232,7 +252,7 @@
 				{
 					"type": "report",
 					"is_query_report": True,
-					"name": "Monthly Salary Register",
+					"name": "Salary Register",
 					"doctype": "Salary Slip"
 				},
 				{
@@ -241,10 +261,36 @@
 					"name": "Monthly Attendance Sheet",
 					"doctype": "Attendance"
 				},
+				{
+					"type": "report",
+					"is_query_report": True,
+					"name": "Vehicle Expenses",
+					"doctype": "Vehicle"
+				},
 
 			]
 		},
 		{
+			"label": _("Employee Loan Management"),
+			"icon": "icon-list",
+			"items": [
+				{
+					"type": "doctype",
+					"name": "Loan Type",
+					"description": _("Define various loan types")
+				},
+				{
+					"type": "doctype",
+					"name": "Employee Loan Application",
+					"description": _("Employee Loan Application")
+				},
+				{
+					"type": "doctype",
+					"name": "Employee Loan"
+				},
+			]
+		},
+		{
 			"label": _("Help"),
 			"icon": "fa fa-facetime-video",
 			"items": [
diff --git a/erpnext/config/learn.py b/erpnext/config/learn.py
index 426449b..86db808 100644
--- a/erpnext/config/learn.py
+++ b/erpnext/config/learn.py
@@ -44,7 +44,7 @@
 				},
 				{
 					"type": "help",
-					"label": _("Setting up Email"),
+					"label": _("Setting up Email Account"),
 					"youtube_id": "YFYe0DrB95o"
 				},
 				{
@@ -64,11 +64,6 @@
 				},
 				{
 					"type": "help",
-					"label": _("Email Account"),
-					"youtube_id": "YFYe0DrB95o"
-				},
-				{
-					"type": "help",
 					"label": _("File Manager"),
 					"youtube_id": "4-osLW3E_Rk"
 				},
diff --git a/erpnext/config/schools.py b/erpnext/config/schools.py
index 366810d..e95b734 100644
--- a/erpnext/config/schools.py
+++ b/erpnext/config/schools.py
@@ -112,7 +112,7 @@
 			"items": [
 				{
 					"type": "doctype",
-					"name": "Assessment"
+					"name": "Assessment Plan"
 				},
 				{
 					"type": "doctype",
@@ -120,7 +120,23 @@
 				},
 				{
 					"type": "doctype",
-					"name": "Grading Structure"
+					"name": "Assessment Result"
+				},
+				{
+					"type": "doctype",
+					"name": "Grading Scale"
+				},
+				{
+					"type": "doctype",
+					"name": "Assessment Criteria"
+				},
+				{
+					"type": "doctype",
+					"name": "Assessment Criteria Group"
+				},
+				{
+					"type": "doctype",
+					"name": "Assessment Result Tool"
 				}
 			]
 		},
@@ -148,23 +164,6 @@
 			]
 		},
 		{
-			"label": _("LMS"),
-			"items": [
-				{
-					"type": "doctype",
-					"name": "Announcement"
-				},
-				{
-					"type": "doctype",
-					"name": "Topic"
-				},
-				{
-					"type": "doctype",
-					"name": "Discussion"
-				}
-			]
-		},
-		{
 			"label": _("Setup"),
 			"items": [
 				{
diff --git a/erpnext/config/selling.py b/erpnext/config/selling.py
index c406d09..bbae245 100644
--- a/erpnext/config/selling.py
+++ b/erpnext/config/selling.py
@@ -120,6 +120,16 @@
 				{
 					"type": "report",
 					"is_query_report": True,
+					"name": "Addresses And Contacts",
+					"label": "Sales Partner Addresses And Contacts",
+					"doctype": "Address",
+					"route_options": {
+						"party_type": "Sales Partner"
+					}
+				},
+				{
+					"type": "report",
+					"is_query_report": True,
 					"name": "Territory Target Variance (Item Group-Wise)",
 					"route": "query-report/Territory Target Variance Item Group-Wise",
 					"doctype": "Territory"
@@ -215,8 +225,12 @@
 				{
 					"type": "report",
 					"is_query_report": True,
-					"name": "Customer Addresses And Contacts",
-					"doctype": "Contact"
+					"name": "Addresses And Contacts",
+					"label": "Customer Addresses And Contacts",
+					"doctype": "Address",
+					"route_options": {
+						"party_type": "Customer"
+					}
 				},
 				{
 					"type": "report",
diff --git a/erpnext/config/setup.py b/erpnext/config/setup.py
index 9c9bae2..878b2f2 100644
--- a/erpnext/config/setup.py
+++ b/erpnext/config/setup.py
@@ -96,6 +96,12 @@
 			"items": [
 				{
 					"type": "doctype",
+					"name": "Feedback Trigger",
+					"label": _("Feedback Trigger"),
+					"description": _("Automatically triggers the feedback request based on conditions.")
+				},
+				{
+					"type": "doctype",
 					"name": "Email Digest",
 					"description": _("Create and manage daily, weekly and monthly email digests.")
 				},
diff --git a/erpnext/config/stock.py b/erpnext/config/stock.py
index 14e7999..a98c40e 100644
--- a/erpnext/config/stock.py
+++ b/erpnext/config/stock.py
@@ -50,6 +50,11 @@
 					"doctype": "Item",
 				},
 				{
+					"type": "page",
+					"name": "stock-balance",
+					"label": _("Stock Summary")
+				},
+				{
 					"type": "report",
 					"is_query_report": True,
 					"name": "Stock Ageing",
diff --git a/erpnext/controllers/accounts_controller.py b/erpnext/controllers/accounts_controller.py
index 554529c..67d4822 100644
--- a/erpnext/controllers/accounts_controller.py
+++ b/erpnext/controllers/accounts_controller.py
@@ -113,7 +113,7 @@
 				date_field = "transaction_date"
 
 			if date_field and self.get(date_field):
-				validate_fiscal_year(self.get(date_field), self.fiscal_year,
+				validate_fiscal_year(self.get(date_field), self.fiscal_year, self.company,
 					self.meta.get_label(date_field), self)
 
 	def validate_due_date(self):
@@ -131,7 +131,7 @@
 			transaction_date = self.posting_date
 		else:
 			transaction_date = self.transaction_date
-		 
+
 		if self.meta.get_field("currency"):
 			# price list part
 			fieldname = "selling_price_list" if buying_or_selling.lower() == "selling" \
@@ -144,7 +144,7 @@
 					self.plc_conversion_rate = 1.0
 
 				elif not self.plc_conversion_rate:
-					self.plc_conversion_rate = get_exchange_rate(self.price_list_currency, 
+					self.plc_conversion_rate = get_exchange_rate(self.price_list_currency,
 						self.company_currency, transaction_date)
 
 			# currency
@@ -570,7 +570,7 @@
 							elif asset.status in ("Scrapped", "Cancelled", "Sold"):
 								frappe.throw(_("Row #{0}: Asset {1} cannot be submitted, it is already {2}")
 									.format(d.idx, d.asset, asset.status))
-									
+
 	def delink_advance_entries(self, linked_doc_name):
 		total_allocated_amount = 0
 		for adv in self.advances:
@@ -583,7 +583,7 @@
 			if consider_for_total_advance:
 				total_allocated_amount += flt(adv.allocated_amount, adv.precision("allocated_amount"))
 
-		frappe.db.set_value(self.doctype, self.name, "total_advance", 
+		frappe.db.set_value(self.doctype, self.name, "total_advance",
 			total_allocated_amount, update_modified=False)
 
 	def group_similar_items(self):
@@ -711,7 +711,7 @@
 			.format(order_doctype, order_condition))
 
 	reference_condition = " and (" + " or ".join(conditions) + ")" if conditions else ""
-	
+
 	journal_entries = frappe.db.sql("""
 		select
 			"Journal Entry" as reference_type, t1.name as reference_name,
@@ -771,8 +771,8 @@
 def update_invoice_status():
 	# Daily update the status of the invoices
 
-	frappe.db.sql(""" update `tabSales Invoice` set status = 'Overdue' 
+	frappe.db.sql(""" update `tabSales Invoice` set status = 'Overdue'
 		where due_date < CURDATE() and docstatus = 1 and outstanding_amount > 0""")
 
-	frappe.db.sql(""" update `tabPurchase Invoice` set status = 'Overdue' 
+	frappe.db.sql(""" update `tabPurchase Invoice` set status = 'Overdue'
 		where due_date < CURDATE() and docstatus = 1 and outstanding_amount > 0""")
\ No newline at end of file
diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py
index 865514b..c4ba9e7 100644
--- a/erpnext/controllers/buying_controller.py
+++ b/erpnext/controllers/buying_controller.py
@@ -223,7 +223,8 @@
 				})
 				if not rm.rate:
 					from erpnext.stock.stock_ledger import get_valuation_rate
-					rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse)
+					rm.rate = get_valuation_rate(bom_item.item_code, self.supplier_warehouse, 
+						self.doctype, self.name)
 			else:
 				rm.rate = bom_item.rate
 
diff --git a/erpnext/controllers/js/contact_address_common.js b/erpnext/controllers/js/contact_address_common.js
deleted file mode 100644
index c51ff46..0000000
--- a/erpnext/controllers/js/contact_address_common.js
+++ /dev/null
@@ -1,61 +0,0 @@
-// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-// License: GNU General Public License v3. See license.txt
-
-cur_frm.cscript.onload = function(doc, cdt, cdn) {
-	cur_frm.add_fetch('customer', 'customer_name', 'customer_name');
-	cur_frm.add_fetch('supplier', 'supplier_name', 'supplier_name');
-
-	cur_frm.fields_dict.customer.get_query = erpnext.queries.customer;
-	cur_frm.fields_dict.supplier.get_query = erpnext.queries.supplier;
-
-	if(cur_frm.fields_dict.lead) {
-		cur_frm.fields_dict.lead.get_query = erpnext.queries.lead;
-		cur_frm.add_fetch('lead', 'lead_name', 'lead_name');
-	}
-
-	if(doc.__islocal) {
-		var last_route = frappe.route_history.slice(-2, -1)[0];
-		if(last_route && last_route[0]==="Form") {
-			var doctype = last_route[1],
-				docname = last_route.slice(2).join("/");
-
-			if(["Customer", "Quotation", "Sales Order", "Sales Invoice", "Delivery Note",
-				"Installation Note", "Opportunity", "Warranty Claim", "Maintenance Visit",
-				"Maintenance Schedule"]
-				.indexOf(doctype)!==-1) {
-				var refdoc = frappe.get_doc(doctype, docname);
-				if((refdoc.doctype == "Quotation" && refdoc.quotation_to=="Customer") ||
-					(refdoc.doctype == "Opportunity" && refdoc.enquiry_from=="Customer") ||
-					!in_list(["Opportunity", "Quotation"], doctype)) {
-						cur_frm.set_value("customer", refdoc.customer || refdoc.name);
-						cur_frm.set_value("customer_name", refdoc.customer_name);
-						if(cur_frm.doc.doctype==="Address")
-							cur_frm.set_value("address_title", cur_frm.doc.customer_name);
-				}
-			}
-			else if(["Supplier", "Supplier Quotation", "Purchase Order", "Purchase Invoice", "Purchase Receipt"]
-				.indexOf(doctype)!==-1) {
-				var refdoc = frappe.get_doc(doctype, docname);
-				cur_frm.set_value("supplier", refdoc.supplier || refdoc.name);
-				cur_frm.set_value("supplier_name", refdoc.supplier_name);
-				if(cur_frm.doc.doctype==="Address")
-					cur_frm.set_value("address_title", cur_frm.doc.supplier_name);
-			}
-			else if(["Lead", "Opportunity", "Quotation"]
-				.indexOf(doctype)!==-1) {
-				var refdoc = frappe.get_doc(doctype, docname);
-
-				if((refdoc.doctype == "Quotation" && refdoc.quotation_to=="Lead") ||
-					(refdoc.doctype == "Opportunity" && refdoc.enquiry_from=="Lead") || (doctype=="Lead")) {
-						cur_frm.set_value("lead", refdoc.lead || refdoc.name);
-						cur_frm.set_value("lead_name", refdoc.customer_name || refdoc.company_name || refdoc.lead_name);
-						if(cur_frm.doc.doctype==="Address")
-							cur_frm.set_value("address_title", cur_frm.doc.lead_name);
-				}
-			}
-			else if(doctype == "Sales Partner") {
-				cur_frm.set_value("sales_partner", docname);
-			}
-		}
-	}
-}
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index 98390ff..cc3f277 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -3,32 +3,9 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.desk.reportview import get_match_cond
-from frappe.model.db_query import DatabaseQuery
+from frappe.desk.reportview import get_match_cond, get_filters_cond
 from frappe.utils import nowdate
 
-def get_filters_cond(doctype, filters, conditions):
-	if filters:
-		flt = filters
-		if isinstance(filters, dict):
-			filters = filters.items()
-			flt = []
-			for f in filters:
-				if isinstance(f[1], basestring) and f[1][0] == '!':
-					flt.append([doctype, f[0], '!=', f[1][1:]])
-				else:
-					value = frappe.db.escape(f[1]) if isinstance(f[1], basestring) else f[1]
-					flt.append([doctype, f[0], '=', value])
-
-		query = DatabaseQuery(doctype)
-		query.filters = flt
-		query.conditions = conditions
-		query.build_filter_conditions(flt, conditions)
-
-		cond = ' and ' + ' and '.join(query.conditions)
-	else:
-		cond = ''
-	return cond
 
  # searches for active employees
 def employee_query(doctype, txt, searchfield, start, page_len, filters):
@@ -88,7 +65,7 @@
 		fields = ["name", "customer_group", "territory"]
 	else:
 		fields = ["name", "customer_name", "customer_group", "territory"]
-		
+
 	meta = frappe.get_meta("Customer")
 	fields = fields + [f for f in meta.get_search_fields() if not f in fields]
 
diff --git a/erpnext/controllers/sales_and_purchase_return.py b/erpnext/controllers/sales_and_purchase_return.py
index 3e22681..4f9bce1 100644
--- a/erpnext/controllers/sales_and_purchase_return.py
+++ b/erpnext/controllers/sales_and_purchase_return.py
@@ -198,6 +198,7 @@
 			if tax.charge_type == "Actual":
 				tax.tax_amount = -1 * tax.tax_amount
 
+		doc.discount_amount = -1 * source.discount_amount
 		doc.run_method("calculate_taxes_and_totals")
 
 	def update_item(source_doc, target_doc, source_parent):
diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py
index 096bb2d..55bcaf3 100644
--- a/erpnext/controllers/status_updater.py
+++ b/erpnext/controllers/status_updater.py
@@ -6,7 +6,6 @@
 from frappe.utils import flt, comma_or, nowdate, getdate
 from frappe import _
 from frappe.model.document import Document
-from erpnext.accounts.party_status import notify_status
 
 def validate_status(status, options):
 	if status not in options:
@@ -103,6 +102,8 @@
 
 	def set_status(self, update=False, status=None, update_modified=True):
 		if self.is_new():
+			if self.get('amended_from'):
+				self.status = 'Draft'
 			return
 
 		if self.doctype in status_map:
@@ -285,7 +286,6 @@
 				target = frappe.get_doc(args["target_parent_dt"], args["name"])
 				target.set_status(update=True)
 				target.notify_update()
-				notify_status(target)
 
 	def _update_modified(self, args, update_modified):
 		args['update_modified'] = ''
diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py
index f0c8dbf..add882c 100644
--- a/erpnext/controllers/stock_controller.py
+++ b/erpnext/controllers/stock_controller.py
@@ -9,13 +9,14 @@
 from erpnext.accounts.utils import get_fiscal_year
 from erpnext.accounts.general_ledger import make_gl_entries, delete_gl_entries, process_gl_map
 from erpnext.controllers.accounts_controller import AccountsController
+from erpnext.stock.stock_ledger import get_valuation_rate
 
 class StockController(AccountsController):
 	def validate(self):
 		super(StockController, self).validate()
 		self.validate_inspection()
-	
-	def make_gl_entries(self, repost_future_gle=True):
+
+	def make_gl_entries(self, gl_entries=None, repost_future_gle=True, from_repost=False):
 		if self.docstatus == 2:
 			delete_gl_entries(voucher_type=self.doctype, voucher_no=self.name)
 
@@ -23,8 +24,9 @@
 			warehouse_account = get_warehouse_account()
 
 			if self.docstatus==1:
-				gl_entries = self.get_gl_entries(warehouse_account)
-				make_gl_entries(gl_entries)
+				if not gl_entries:
+					gl_entries = self.get_gl_entries(warehouse_account)
+				make_gl_entries(gl_entries, from_repost=from_repost)
 
 			if repost_future_gle:
 				items, warehouses = self.get_items_and_warehouses()
@@ -42,18 +44,26 @@
 
 		gl_list = []
 		warehouse_with_no_account = []
-		
+
 		for item_row in voucher_details:
 			sle_list = sle_map.get(item_row.name)
 			if sle_list:
 				for sle in sle_list:
 					if warehouse_account.get(sle.warehouse):
 						# from warehouse account
-						
+
 						self.check_expense_account(item_row)
-						
-						if not sle.stock_value_difference:
-							self.validate_negative_stock(sle)
+
+						# If item is not a sample item 
+						# and ( valuation rate not mentioned in an incoming entry
+						# or incoming entry not found while delivering the item), 
+						# try to pick valuation rate from previous sle or Item master and update in SLE
+						# Otherwise, throw an exception
+
+						if not sle.stock_value_difference and self.doctype != "Stock Reconciliation" \
+							and not item_row.get("is_sample_item"):
+
+							sle = self.update_stock_ledger_entries(sle)
 
 						gl_list.append(self.get_gl_dict({
 							"account": warehouse_account[sle.warehouse]["name"],
@@ -79,18 +89,32 @@
 			for wh in warehouse_with_no_account:
 				if frappe.db.get_value("Warehouse", wh, "company"):
 					frappe.throw(_("Warehouse {0} is not linked to any account, please create/link the corresponding (Asset) account for the warehouse.").format(wh))
-					
+
 			msgprint(_("No accounting entries for the following warehouses") + ": \n" +
 				"\n".join(warehouse_with_no_account))
 
 		return process_gl_map(gl_list)
-		
-	def validate_negative_stock(self, sle):
-		if sle.qty_after_transaction < 0 and sle.actual_qty < 0:
-			frappe.throw(_("For the Item {0}, valuation rate not found for warehouse {1}. To be able to do accounting entries (for booking expenses), we need valuation rate for item {2}. Please create an incoming stock transaction, on or before {3} {4}, and then try submiting {5}")
-			.format(sle.item_code, sle.warehouse, 
-				sle.item_code, sle.posting_date, sle.posting_time, self.name))
 
+	def update_stock_ledger_entries(self, sle):
+		sle.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, 
+			self.doctype, self.name)
+
+		sle.stock_value = flt(sle.qty_after_transaction) * flt(sle.valuation_rate)
+		sle.stock_value_difference = flt(sle.actual_qty) * flt(sle.valuation_rate)
+		
+		if sle.name:
+			frappe.db.sql("""
+				update 
+					`tabStock Ledger Entry` 
+				set 
+					stock_value = %(stock_value)s,
+					valuation_rate = %(valuation_rate)s, 
+					stock_value_difference = %(stock_value_difference)s 
+				where 
+					name = %(name)s""", (sle))
+					
+		return sle
+					
 	def get_voucher_details(self, default_expense_account, default_cost_center, sle_map):
 		if self.doctype == "Stock Reconciliation":
 			return [frappe._dict({ "name": voucher_detail_no, "expense_account": default_expense_account,
@@ -138,10 +162,18 @@
 
 	def get_stock_ledger_details(self):
 		stock_ledger = {}
-		for sle in frappe.db.sql("""select warehouse, stock_value_difference,
-			voucher_detail_no, item_code, posting_date, posting_time, actual_qty, qty_after_transaction
-			from `tabStock Ledger Entry` where voucher_type=%s and voucher_no=%s""",
-			(self.doctype, self.name), as_dict=True):
+		stock_ledger_entries = frappe.db.sql("""
+			select 
+				name, warehouse, stock_value_difference, valuation_rate,
+				voucher_detail_no, item_code, posting_date, posting_time, 
+				actual_qty, qty_after_transaction
+			from
+				`tabStock Ledger Entry`
+			where
+				voucher_type=%s and voucher_no=%s
+		""", (self.doctype, self.name), as_dict=True)
+
+		for sle in stock_ledger_entries:
 				stock_ledger.setdefault(sle.voucher_detail_no, []).append(sle)
 		return stock_ledger
 
@@ -224,7 +256,7 @@
 	def make_gl_entries_on_cancel(self, repost_future_gle=True):
 		if frappe.db.sql("""select name from `tabGL Entry` where voucher_type=%s
 			and voucher_no=%s""", (self.doctype, self.name)):
-				self.make_gl_entries(repost_future_gle)
+				self.make_gl_entries(repost_future_gle=repost_future_gle)
 
 	def get_serialized_items(self):
 		serialized_items = []
@@ -247,7 +279,7 @@
 			incoming_rate = incoming_rate[0][0] if incoming_rate else 0.0
 
 		return incoming_rate
-		
+
 	def validate_warehouse(self):
 		from erpnext.stock.utils import validate_warehouse_company
 
@@ -256,7 +288,7 @@
 
 		for w in warehouses:
 			validate_warehouse_company(w, self.company)
-			
+
 	def update_billing_percentage(self, update_modified=True):
 		self._update_percent_field({
 			"target_dt": self.doctype + " Item",
@@ -270,21 +302,21 @@
 	def validate_inspection(self):
 		'''Checks if quality inspection is set for Items that require inspection.
 		On submit, throw an exception'''
-		
+
 		inspection_required_fieldname = None
 		if self.doctype in ["Purchase Receipt", "Purchase Invoice"]:
 			inspection_required_fieldname = "inspection_required_before_purchase"
 		elif self.doctype in ["Delivery Note", "Sales Invoice"]:
 			inspection_required_fieldname = "inspection_required_before_delivery"
-		
+
 		if not inspection_required_fieldname or \
 			(self.doctype in ["Sales Invoice", "Purchase Invoice"] and not self.update_stock):
 				return
-		
+
 		for d in self.get('items'):
-			if (frappe.db.get_value("Item", d.item_code, inspection_required_fieldname) 
+			if (frappe.db.get_value("Item", d.item_code, inspection_required_fieldname)
 				and not d.quality_inspection):
-				
+
 				frappe.msgprint(_("Quality Inspection required for Item {0}").format(d.item_code))
 				if self.docstatus==1:
 					raise frappe.ValidationError
@@ -300,7 +332,7 @@
 
 	future_stock_vouchers = get_future_stock_vouchers(posting_date, posting_time, for_warehouses, for_items)
 	gle = get_voucherwise_gl_entries(future_stock_vouchers, posting_date)
-	
+
 	for voucher_type, voucher_no in future_stock_vouchers:
 		existing_gle = gle.get((voucher_type, voucher_no), [])
 		voucher_obj = frappe.get_doc(voucher_type, voucher_no)
@@ -308,7 +340,7 @@
 		if expected_gle:
 			if not existing_gle or not compare_existing_and_expected_gle(existing_gle, expected_gle):
 				_delete_gl_entries(voucher_type, voucher_no)
-				voucher_obj.make_gl_entries(repost_future_gle=False)
+				voucher_obj.make_gl_entries(gl_entries=expected_gle, repost_future_gle=False, from_repost=True)
 		else:
 			_delete_gl_entries(voucher_type, voucher_no)
 
@@ -363,10 +395,19 @@
 	return gl_entries
 
 def get_warehouse_account():
-	warehouse_account = frappe._dict()
+	if not frappe.flags.warehouse_account_map or frappe.flags.in_test:
+		warehouse_account = frappe._dict()
 
-	for d in frappe.db.sql("""select warehouse, name, account_currency from tabAccount
-		where account_type = 'Stock' and (warehouse is not null and warehouse != ''
-		and is_group != 1) and is_group=0 """, as_dict=1):
+		for d in frappe.db.sql("""select
+				warehouse, name, account_currency
+			from
+				tabAccount
+			where
+				account_type = 'Stock'
+				and (warehouse is not null and warehouse != '')
+				and is_group=0 """, as_dict=1):
 			warehouse_account.setdefault(d.warehouse, d)
-	return warehouse_account
+
+		frappe.flags.warehouse_account_map = warehouse_account
+
+	return frappe.flags.warehouse_account_map
diff --git a/erpnext/controllers/taxes_and_totals.py b/erpnext/controllers/taxes_and_totals.py
index e9cef88..0e02df8 100644
--- a/erpnext/controllers/taxes_and_totals.py
+++ b/erpnext/controllers/taxes_and_totals.py
@@ -456,10 +456,12 @@
 
 	def calculate_paid_amount(self):
 		paid_amount = base_paid_amount = 0.0
-		for payment in self.doc.get('payments'):
-			payment.base_amount = flt(payment.amount * self.doc.conversion_rate)
-			paid_amount += payment.amount
-			base_paid_amount += payment.base_amount
+
+		if self.doc.is_pos:
+			for payment in self.doc.get('payments'):
+				payment.base_amount = flt(payment.amount * self.doc.conversion_rate)
+				paid_amount += payment.amount
+				base_paid_amount += payment.base_amount
 
 		self.doc.paid_amount = flt(paid_amount, self.doc.precision("paid_amount"))
 		self.doc.base_paid_amount = flt(base_paid_amount, self.doc.precision("base_paid_amount"))
diff --git a/erpnext/crm/doctype/lead/lead.js b/erpnext/crm/doctype/lead/lead.js
index be3cd82..7e22125 100644
--- a/erpnext/crm/doctype/lead/lead.js
+++ b/erpnext/crm/doctype/lead/lead.js
@@ -25,6 +25,7 @@
 	refresh: function() {
 		var doc = this.frm.doc;
 		erpnext.toggle_naming_series();
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'name', doctype: 'Lead'}
 
 		if(!this.frm.doc.__islocal && this.frm.doc.__onload && !this.frm.doc.__onload.is_customer) {
 			this.frm.add_custom_button(__("Customer"), this.create_customer, __("Make"));
@@ -34,9 +35,9 @@
 		}
 
 		if(!this.frm.doc.__islocal) {
-			erpnext.utils.render_address_and_contact(cur_frm);
+			frappe.geo.render_address_and_contact(cur_frm);
 		} else {
-			erpnext.utils.clear_address_and_contact(cur_frm);
+			frappe.geo.clear_address_and_contact(cur_frm);
 		}
 	},
 
diff --git a/erpnext/crm/doctype/lead/lead.py b/erpnext/crm/doctype/lead/lead.py
index 4b2899d..c306cbf 100644
--- a/erpnext/crm/doctype/lead/lead.py
+++ b/erpnext/crm/doctype/lead/lead.py
@@ -4,11 +4,12 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
-from frappe.utils import cstr, validate_email_add, cint, comma_and, has_gravatar, nowdate
+from frappe.utils import (cstr, validate_email_add, cint, comma_and, has_gravatar,
+	getdate, nowdate)
 from frappe.model.mapper import get_mapped_doc
 
 from erpnext.controllers.selling_controller import SellingController
-from erpnext.utilities.address_and_contact import load_address_and_contact
+from frappe.geo.address_and_contact import load_address_and_contact
 from erpnext.accounts.party import set_taxes
 
 sender_field = "email_id"
@@ -45,7 +46,7 @@
 
 			self.image = has_gravatar(self.email_id)
 
-		if self.contact_date and self.contact_date < nowdate():
+		if self.contact_date and getdate(self.contact_date) < nowdate():
 			frappe.throw(_("Next Contact Date cannot be in the past"))
 
 	def on_update(self):
@@ -87,7 +88,7 @@
 			"lead": self.name,
 			"docstatus": 1,
 			"status": ["!=", "Lost"]
-			
+
 		})
 
 	def has_lost_quotation(self):
@@ -127,7 +128,7 @@
 
 @frappe.whitelist()
 def make_opportunity(source_name, target_doc=None):
-	target_doc = get_mapped_doc("Lead", source_name,
+	target_doc = get_mapped_doc("Lead", source_name, 
 		{"Lead": {
 			"doctype": "Opportunity",
 			"field_map": {
@@ -154,6 +155,9 @@
 			}
 		}}, target_doc)
 	target_doc.quotation_to = "Lead"
+	target_doc.run_method("set_missing_values")
+	target_doc.run_method("set_other_charges")
+	target_doc.run_method("calculate_taxes_and_totals")
 
 	return target_doc
 
diff --git a/erpnext/crm/doctype/opportunity/opportunity.js b/erpnext/crm/doctype/opportunity/opportunity.js
index 21fba7b..def67d8 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.js
+++ b/erpnext/crm/doctype/opportunity/opportunity.js
@@ -6,9 +6,14 @@
 cur_frm.email_field = "contact_email";
 frappe.ui.form.on("Opportunity", {
 	customer: function(frm) {
+		frm.trigger('set_contact_link');
 		erpnext.utils.get_party_details(frm);
 	},
 
+	lead: function(frm) {
+		frm.trigger('set_contact_link');
+	},
+
 	customer_address: function(frm, cdt, cdn) {
 		erpnext.utils.get_address_display(frm, 'customer_address', 'address_display', false);
 	},
@@ -23,7 +28,9 @@
 	refresh: function(frm) {
 		var doc = frm.doc;
 		frm.events.enquiry_from(frm);
-		if(doc.status!=="Lost") {
+		frm.trigger('set_contact_link');
+
+		if(!doc.__islocal && doc.status!=="Lost") {
 			if(doc.with_items){
 				frm.add_custom_button(__('Supplier Quotation'),
 					function() {
@@ -35,7 +42,7 @@
 				cur_frm.cscript.create_quotation, __("Make"));
 
 			frm.page.set_inner_btn_group_as_primary(__("Make"));
-		
+
 			if(doc.status!=="Quotation") {
 				frm.add_custom_button(__('Lost'),
 					cur_frm.cscript['Declare Opportunity Lost']);
@@ -43,6 +50,14 @@
 		}
 	},
 
+	set_contact_link: function(frm) {
+		if(frm.doc.customer) {
+			frappe.dynamic_link = {doc: frm.doc, fieldname: 'customer', doctype: 'Customer'}
+		} else if(frm.doc.lead) {
+			frappe.dynamic_link = {doc: frm.doc, fieldname: 'lead', doctype: 'Lead'}
+		}
+	},
+
 	make_supplier_quotation: function(frm) {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.crm.doctype.opportunity.opportunity.make_supplier_quotation",
@@ -62,7 +77,7 @@
 		if(!this.frm.doc.status)
 			set_multiple(this.frm.doc.doctype, this.frm.doc.name, { status:'Open' });
 		if(!this.frm.doc.company && frappe.defaults.get_user_default("Company"))
-			set_multiple(this.frm.doc.doctype, this.frm.doc.name, 
+			set_multiple(this.frm.doc.doctype, this.frm.doc.name,
 				{ company:frappe.defaults.get_user_default("Company") });
 
 		this.setup_queries();
@@ -75,10 +90,7 @@
 			this.frm.set_query("contact_by", erpnext.queries.user);
 		}
 
-		this.frm.set_query("customer_address", function() {
-			if(me.frm.doc.lead) return {filters: { lead: me.frm.doc.lead } };
-			else if(me.frm.doc.customer) return {filters: { customer: me.frm.doc.customer } };
-		});
+		me.frm.set_query('customer_address', erpnext.queries.address_query);
 
 		this.frm.set_query("item_code", "items", function() {
 			return {
@@ -89,8 +101,7 @@
 
 		$.each([["lead", "lead"],
 			["customer", "customer"],
-			["contact_person", "customer_filter"],
-			["territory", "not_a_group_filter"]], function(i, opts) {
+			["contact_person", "customer_filter"]], function(i, opts) {
 				me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
 			});
 	},
@@ -109,7 +120,7 @@
 	erpnext.toggle_naming_series();
 
 	var frm = cur_frm;
-	if(frm.perm[0].write && doc.docstatus==0) {
+	if(!doc.__islocal && frm.perm[0].write && doc.docstatus==0) {
 		if(frm.doc.status==="Open") {
 			frm.add_custom_button(__("Close"), function() {
 				frm.set_value("status", "Closed");
diff --git a/erpnext/crm/doctype/opportunity/opportunity.py b/erpnext/crm/doctype/opportunity/opportunity.py
index 4bb6765..301dc82 100644
--- a/erpnext/crm/doctype/opportunity/opportunity.py
+++ b/erpnext/crm/doctype/opportunity/opportunity.py
@@ -106,30 +106,6 @@
 			lead_name, company_name = frappe.db.get_value("Lead", self.lead, ["lead_name", "company_name"])
 			self.customer_name = company_name or lead_name
 
-	def get_cust_address(self,name):
-		details = frappe.db.sql("""select customer_name, address, territory, customer_group
-			from `tabCustomer` where name = %s and docstatus != 2""", (name), as_dict = 1)
-		if details:
-			ret = {
-				'customer_name':	details and details[0]['customer_name'] or '',
-				'address'	:	details and details[0]['address'] or '',
-				'territory'			 :	details and details[0]['territory'] or '',
-				'customer_group'		:	details and details[0]['customer_group'] or ''
-			}
-			# ********** get primary contact details (this is done separately coz. , in case there is no primary contact thn it would not be able to fetch customer details in case of join query)
-
-			contact_det = frappe.db.sql("""select contact_name, contact_no, email_id
-				from `tabContact` where customer = %s and is_customer = 1
-					and is_primary_contact = 'Yes' and docstatus != 2""", name, as_dict = 1)
-
-			ret['contact_person'] = contact_det and contact_det[0]['contact_name'] or ''
-			ret['contact_no']		 = contact_det and contact_det[0]['contact_no'] or ''
-			ret['email_id']			 = contact_det and contact_det[0]['email_id'] or ''
-
-			return ret
-		else:
-			frappe.throw(_("Customer {0} does not exist").format(name), frappe.DoesNotExistError)
-
 	def on_update(self):
 		self.add_calendar_event()
 
diff --git a/erpnext/demo/data/address.json b/erpnext/demo/data/address.json
index be4d5ec..7618c2c 100644
--- a/erpnext/demo/data/address.json
+++ b/erpnext/demo/data/address.json
@@ -1,245 +1,218 @@
 [
  {
-  "address_line1": "254 Theotokopoulou Str.", 
-  "address_type": "Office", 
-  "city": "Larnaka", 
-  "country": "Cyprus", 
-  "customer": "Adaptas", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "254 Theotokopoulou Str.",
+  "address_type": "Office",
+  "city": "Larnaka",
+  "country": "Cyprus",
+  "links": [{"link_doctype": "Customer", "link_name": "Adaptas"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "R Patr\u00e3o Caramelho 116", 
-  "address_type": "Office", 
-  "city": "Fajozes", 
-  "country": "Portugal", 
-  "customer": "Asian Fusion", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "R Patr\u00e3o Caramelho 116",
+  "address_type": "Office",
+  "city": "Fajozes",
+  "country": "Portugal",
+  "links": [{"link_doctype": "Customer", "link_name": "Asian Fusion"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "30 Fulford Road", 
-  "address_type": "Office", 
-  "city": "PENTRE-PIOD", 
-  "country": "United Kingdom", 
-  "customer": "Asian Junction", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "30 Fulford Road",
+  "address_type": "Office",
+  "city": "PENTRE-PIOD",
+  "country": "United Kingdom",
+  "links": [{"link_doctype": "Customer", "link_name": "Asian Junction"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Schoenebergerstrasse 13", 
-  "address_type": "Office", 
-  "city": "Raschau", 
-  "country": "Germany", 
-  "customer": "Big D Supermarkets", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Schoenebergerstrasse 13",
+  "address_type": "Office",
+  "city": "Raschau",
+  "country": "Germany",
+  "links": [{"link_doctype": "Customer", "link_name": "Big D Supermarkets"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Hoheluftchaussee 43", 
-  "address_type": "Office", 
-  "city": "Kieritzsch", 
-  "country": "Germany", 
-  "customer": "Buttrey Food & Drug", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Hoheluftchaussee 43",
+  "address_type": "Office",
+  "city": "Kieritzsch",
+  "country": "Germany",
+  "links": [{"link_doctype": "Customer", "link_name": "Buttrey Food & Drug"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "R Cimo Vila 6", 
-  "address_type": "Office", 
-  "city": "Rebordosa", 
-  "country": "Portugal", 
-  "customer": "Chi-Chis", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "R Cimo Vila 6",
+  "address_type": "Office",
+  "city": "Rebordosa",
+  "country": "Portugal",
+  "links": [{"link_doctype": "Customer", "link_name": "Chi-Chis"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "R 5 Outubro 9", 
-  "address_type": "Office", 
-  "city": "Quinta Nova S\u00e3o Domingos", 
-  "country": "Portugal", 
-  "customer": "Choices", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "R 5 Outubro 9",
+  "address_type": "Office",
+  "city": "Quinta Nova S\u00e3o Domingos",
+  "country": "Portugal",
+  "links": [{"link_doctype": "Customer", "link_name": "Choices"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Avenida Macambira 953", 
-  "address_type": "Office", 
-  "city": "Goi\u00e2nia", 
-  "country": "Brazil", 
-  "customer": "Consumers and Consumers Express", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Avenida Macambira 953",
+  "address_type": "Office",
+  "city": "Goi\u00e2nia",
+  "country": "Brazil",
+  "links": [{"link_doctype": "Customer", "link_name": "Consumers and Consumers Express"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "2342 Goyeau Ave", 
-  "address_type": "Office", 
-  "city": "Windsor", 
-  "country": "Canada", 
-  "customer": "Crafts Canada", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "2342 Goyeau Ave",
+  "address_type": "Office",
+  "city": "Windsor",
+  "country": "Canada",
+  "links": [{"link_doctype": "Customer", "link_name": "Crafts Canada"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Laukaantie 82", 
-  "address_type": "Office", 
-  "city": "KOKKOLA", 
-  "country": "Finland", 
-  "customer": "Endicott Shoes", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Laukaantie 82",
+  "address_type": "Office",
+  "city": "KOKKOLA",
+  "country": "Finland",
+  "links": [{"link_doctype": "Customer", "link_name": "Endicott Shoes"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "9 Brown Street", 
-  "address_type": "Office", 
-  "city": "PETERSHAM", 
-  "country": "Australia", 
-  "customer": "Fayva", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "9 Brown Street",
+  "address_type": "Office",
+  "city": "PETERSHAM",
+  "country": "Australia",
+  "links": [{"link_doctype": "Customer", "link_name": "Fayva"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Via Donnalbina 41", 
-  "address_type": "Office", 
-  "city": "Cala Gonone", 
-  "country": "Italy", 
-  "customer": "Intelacard", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Via Donnalbina 41",
+  "address_type": "Office",
+  "city": "Cala Gonone",
+  "country": "Italy",
+  "links": [{"link_doctype": "Customer", "link_name": "Intelacard"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Liljerum Grenadj\u00e4rtorpet 69", 
-  "address_type": "Office", 
-  "city": "TOMTEBODA", 
-  "country": "Sweden", 
-  "customer": "Landskip Yard Care", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Liljerum Grenadj\u00e4rtorpet 69",
+  "address_type": "Office",
+  "city": "TOMTEBODA",
+  "country": "Sweden",
+  "links": [{"link_doctype": "Customer", "link_name": "Landskip Yard Care"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "72 Bishopgate Street", 
-  "address_type": "Office", 
-  "city": "SEAHAM", 
-  "country": "United Kingdom", 
-  "customer": "Life Plan Counselling", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "72 Bishopgate Street",
+  "address_type": "Office",
+  "city": "SEAHAM",
+  "country": "United Kingdom",
+  "links": [{"link_doctype": "Customer", "link_name": "Life Plan Counselling"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "\u03a3\u03ba\u03b1\u03c6\u03af\u03b4\u03b9\u03b1 105", 
-  "address_type": "Office", 
-  "city": "\u03a0\u0391\u03a1\u0395\u039a\u039a\u039b\u0397\u03a3\u0399\u0391", 
-  "country": "Cyprus", 
-  "customer": "Mr Fables", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "\u03a3\u03ba\u03b1\u03c6\u03af\u03b4\u03b9\u03b1 105",
+  "address_type": "Office",
+  "city": "\u03a0\u0391\u03a1\u0395\u039a\u039a\u039b\u0397\u03a3\u0399\u0391",
+  "country": "Cyprus",
+  "links": [{"link_doctype": "Customer", "link_name": "Mr Fables"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Mellemvej 7", 
-  "address_type": "Office", 
-  "city": "Aabybro", 
-  "country": "Denmark", 
-  "customer": "Nelson Brothers", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Mellemvej 7",
+  "address_type": "Office",
+  "city": "Aabybro",
+  "country": "Denmark",
+  "links": [{"link_doctype": "Customer", "link_name": "Nelson Brothers"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "Plougg\u00e5rdsvej 98", 
-  "address_type": "Office", 
-  "city": "Karby", 
-  "country": "Denmark", 
-  "customer": "Netobill", 
-  "phone": "23566775757", 
-  "supplier": null
- }, 
+  "address_line1": "Plougg\u00e5rdsvej 98",
+  "address_type": "Office",
+  "city": "Karby",
+  "country": "Denmark",
+  "links": [{"link_doctype": "Customer", "link_name": "Netobill"}],
+  "phone": "23566775757"
+ },
  {
-  "address_line1": "176 Michalakopoulou Street", 
-  "address_type": "Office", 
-  "city": "Agio Georgoudi", 
-  "country": "Cyprus", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Helios Air"
- }, 
+  "address_line1": "176 Michalakopoulou Street",
+  "address_type": "Office",
+  "city": "Agio Georgoudi",
+  "country": "Cyprus",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Helios Air"}]
+ },
  {
-  "address_line1": "Fibichova 1102", 
-  "address_type": "Office", 
-  "city": "Kokor\u00edn", 
-  "country": "Czech Republic", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Ks Merchandise"
- }, 
+  "address_line1": "Fibichova 1102",
+  "address_type": "Office",
+  "city": "Kokor\u00edn",
+  "country": "Czech Republic",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Ks Merchandise"}]
+ },
  {
-  "address_line1": "Zahradn\u00ed 888", 
-  "address_type": "Office", 
-  "city": "Cecht\u00edn", 
-  "country": "Czech Republic", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "HomeBase"
- }, 
+  "address_line1": "Zahradn\u00ed 888",
+  "address_type": "Office",
+  "city": "Cecht\u00edn",
+  "country": "Czech Republic",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "HomeBase"}]
+ },
  {
-  "address_line1": "ul. Grochowska 94", 
-  "address_type": "Office", 
-  "city": "Warszawa", 
-  "country": "Poland", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Scott Ties"
- }, 
+  "address_line1": "ul. Grochowska 94",
+  "address_type": "Office",
+  "city": "Warszawa",
+  "country": "Poland",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Scott Ties"}]
+ },
  {
-  "address_line1": "Norra Esplanaden 87", 
-  "address_type": "Office", 
-  "city": "HELSINKI", 
-  "country": "Finland", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Reliable Investments"
- }, 
+  "address_line1": "Norra Esplanaden 87",
+  "address_type": "Office",
+  "city": "HELSINKI",
+  "country": "Finland",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Reliable Investments"}]
+ },
  {
-  "address_line1": "2038 Fallon Drive", 
-  "address_type": "Office", 
-  "city": "Dresden", 
-  "country": "Canada", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Nan Duskin"
- }, 
+  "address_line1": "2038 Fallon Drive",
+  "address_type": "Office",
+  "city": "Dresden",
+  "country": "Canada",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Nan Duskin"}]
+ },
  {
-  "address_line1": "77 cours Franklin Roosevelt", 
-  "address_type": "Office", 
-  "city": "MARSEILLE", 
-  "country": "France", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Rainbow Records"
- }, 
+  "address_line1": "77 cours Franklin Roosevelt",
+  "address_type": "Office",
+  "city": "MARSEILLE",
+  "country": "France",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Rainbow Records"}]
+ },
  {
-  "address_line1": "ul. Tuwima Juliana 85", 
-  "address_type": "Office", 
-  "city": "\u0141\u00f3d\u017a", 
-  "country": "Poland", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "New World Realty"
- }, 
+  "address_line1": "ul. Tuwima Juliana 85",
+  "address_type": "Office",
+  "city": "\u0141\u00f3d\u017a",
+  "country": "Poland",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "New World Realty"}]
+ },
  {
-  "address_line1": "Gl. Sygehusvej 41", 
-  "address_type": "Office", 
-  "city": "Narsaq", 
-  "country": "Greenland", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Asiatic Solutions"
- }, 
+  "address_line1": "Gl. Sygehusvej 41",
+  "address_type": "Office",
+  "city": "Narsaq",
+  "country": "Greenland",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Asiatic Solutions"}]
+ },
  {
-  "address_line1": "Gosposka ulica 50", 
-  "address_type": "Office", 
-  "city": "Nova Gorica", 
-  "country": "Slovenia", 
-  "customer": null, 
-  "phone": "23566775757", 
-  "supplier": "Eagle Hardware"
+  "address_line1": "Gosposka ulica 50",
+  "address_type": "Office",
+  "city": "Nova Gorica",
+  "country": "Slovenia",
+  "phone": "23566775757",
+  "links": [{"link_doctype": "Supplier", "link_name": "Eagle Hardware"}]
  }
 ]
\ No newline at end of file
diff --git a/erpnext/demo/data/contact.json b/erpnext/demo/data/contact.json
index 130845b..113b561 100644
--- a/erpnext/demo/data/contact.json
+++ b/erpnext/demo/data/contact.json
@@ -1,191 +1,164 @@
 [
  {
-  "customer": "Adaptas", 
-  "email_id": "JanVaclavik@example.com", 
-  "first_name": "January", 
-  "last_name": "V\u00e1clav\u00edk", 
-  "supplier": null
- }, 
+  "email_id": "JanVaclavik@example.com",
+  "first_name": "January",
+  "last_name": "V\u00e1clav\u00edk",
+  "links": [{"link_doctype": "Customer", "link_name": "Adaptas"}]
+ },
  {
-  "customer": "Asian Fusion", 
-  "email_id": "ChidumagaTobeolisa@example.com", 
-  "first_name": "Chidumaga", 
-  "last_name": "Tobeolisa", 
-  "supplier": null
- }, 
+  "email_id": "ChidumagaTobeolisa@example.com",
+  "first_name": "Chidumaga",
+  "last_name": "Tobeolisa",
+  "links": [{"link_doctype": "Customer", "link_name": "Asian Fusion"}]
+ },
  {
-  "customer": "Asian Junction", 
-  "email_id": "JanaKubanova@example.com", 
-  "first_name": "Jana", 
-  "last_name": "Kub\u00e1\u0148ov\u00e1", 
-  "supplier": null
- }, 
+  "email_id": "JanaKubanova@example.com",
+  "first_name": "Jana",
+  "last_name": "Kub\u00e1\u0148ov\u00e1",
+  "links": [{"link_doctype": "Customer", "link_name": "Asian Junction"}]
+ },
  {
-  "customer": "Big D Supermarkets", 
-  "email_id": "XuChaoXuan@example.com", 
-  "first_name": "\u7d39\u8431", 
-  "last_name": "\u4e8e", 
-  "supplier": null
- }, 
+  "email_id": "XuChaoXuan@example.com",
+  "first_name": "\u7d39\u8431",
+  "last_name": "\u4e8e",
+  "links": [{"link_doctype": "Customer", "link_name": "Big D Supermarkets"}]
+ },
  {
-  "customer": "Buttrey Food & Drug", 
-  "email_id": "OzlemVerwijmeren@example.com", 
-  "first_name": "\u00d6zlem", 
-  "last_name": "Verwijmeren", 
-  "supplier": null
- }, 
+  "email_id": "OzlemVerwijmeren@example.com",
+  "first_name": "\u00d6zlem",
+  "last_name": "Verwijmeren",
+  "links": [{"link_doctype": "Customer", "link_name": "Buttrey Food & Drug"}]
+ },
  {
-  "customer": "Chi-Chis", 
-  "email_id": "HansRasmussen@example.com", 
-  "first_name": "Hans", 
-  "last_name": "Rasmussen", 
-  "supplier": null
- }, 
+  "email_id": "HansRasmussen@example.com",
+  "first_name": "Hans",
+  "last_name": "Rasmussen",
+  "links": [{"link_doctype": "Customer", "link_name": "Chi-Chis"}]
+ },
  {
-  "customer": "Choices", 
-  "email_id": "SatomiShigeki@example.com", 
-  "first_name": "Satomi", 
-  "last_name": "Shigeki", 
-  "supplier": null
- }, 
+  "email_id": "SatomiShigeki@example.com",
+  "first_name": "Satomi",
+  "last_name": "Shigeki",
+  "links": [{"link_doctype": "Customer", "link_name": "Choices"}]
+ },
  {
-  "customer": "Consumers and Consumers Express", 
-  "email_id": "SimonVJessen@example.com", 
-  "first_name": "Simon", 
-  "last_name": "Jessen", 
-  "supplier": null
- }, 
+  "email_id": "SimonVJessen@example.com",
+  "first_name": "Simon",
+  "last_name": "Jessen",
+  "links": [{"link_doctype": "Customer", "link_name": "Consumers and Consumers Express"}]
+ },
  {
-  "customer": "Crafts Canada", 
-  "email_id": "NeguaranShahsaah@example.com", 
-  "first_name": "\u0646\u06af\u0627\u0631\u06cc\u0646", 
-  "last_name": "\u0634\u0627\u0647 \u0633\u06cc\u0627\u0647", 
-  "supplier": null
- }, 
+  "email_id": "NeguaranShahsaah@example.com",
+  "first_name": "\u0646\u06af\u0627\u0631\u06cc\u0646",
+  "last_name": "\u0634\u0627\u0647 \u0633\u06cc\u0627\u0647",
+  "links": [{"link_doctype": "Customer", "link_name": "Crafts Canada"}]
+ },
  {
-  "customer": "Endicott Shoes", 
-  "email_id": "Lom-AliBataev@example.com", 
-  "first_name": "Lom-Ali", 
-  "last_name": "Bataev", 
-  "supplier": null
- }, 
+  "email_id": "Lom-AliBataev@example.com",
+  "first_name": "Lom-Ali",
+  "last_name": "Bataev",
+  "links": [{"link_doctype": "Customer", "link_name": "Endicott Shoes"}]
+ },
  {
-  "customer": "Fayva", 
-  "email_id": "VanNgocTien@example.com", 
-  "first_name": "Ti\u00ean", 
-  "last_name": "V\u0103n", 
-  "supplier": null
- }, 
+  "email_id": "VanNgocTien@example.com",
+  "first_name": "Ti\u00ean",
+  "last_name": "V\u0103n",
+  "links": [{"link_doctype": "Customer", "link_name": "Fayva"}]
+ },
  {
-  "customer": "Intelacard", 
-  "email_id": "QuimeyOsorioRuelas@example.com", 
-  "first_name": "Quimey", 
-  "last_name": "Osorio", 
-  "supplier": null
- }, 
+  "email_id": "QuimeyOsorioRuelas@example.com",
+  "first_name": "Quimey",
+  "last_name": "Osorio",
+  "links": [{"link_doctype": "Customer", "link_name": "Intelacard"}]
+ },
  {
-  "customer": "Landskip Yard Care", 
-  "email_id": "EdgardaSalcedoRaya@example.com", 
-  "first_name": "Edgarda", 
-  "last_name": "Salcedo", 
-  "supplier": null
- }, 
+  "email_id": "EdgardaSalcedoRaya@example.com",
+  "first_name": "Edgarda",
+  "last_name": "Salcedo",
+  "links": [{"link_doctype": "Customer", "link_name": "Landskip Yard Care"}]
+ },
  {
-  "customer": "Life Plan Counselling", 
-  "email_id": "HafsteinnBjarnarsonar@example.com", 
-  "first_name": "Hafsteinn", 
-  "last_name": "Bjarnarsonar", 
-  "supplier": null
- }, 
+  "email_id": "HafsteinnBjarnarsonar@example.com",
+  "first_name": "Hafsteinn",
+  "last_name": "Bjarnarsonar",
+  "links": [{"link_doctype": "Customer", "link_name": "Life Plan Counselling"}]
+ },
  {
-  "customer": "Mr Fables", 
-  "email_id": "\u0434\u0430\u043d\u0438\u0438\u043b@example.com", 
-  "first_name": "\u0414\u0430\u043d\u0438\u0438\u043b", 
-  "last_name": "\u041a\u043e\u043d\u043e\u0432\u0430\u043b\u043e\u0432", 
-  "supplier": null
- }, 
+  "email_id": "\u0434\u0430\u043d\u0438\u0438\u043b@example.com",
+  "first_name": "\u0414\u0430\u043d\u0438\u0438\u043b",
+  "last_name": "\u041a\u043e\u043d\u043e\u0432\u0430\u043b\u043e\u0432",
+  "links": [{"link_doctype": "Customer", "link_name": "Mr Fables"}]
+ },
  {
-  "customer": "Nelson Brothers", 
-  "email_id": "SelmaMAndersen@example.com", 
-  "first_name": "Selma", 
-  "last_name": "Andersen", 
-  "supplier": null
- }, 
+  "email_id": "SelmaMAndersen@example.com",
+  "first_name": "Selma",
+  "last_name": "Andersen",
+  "links": [{"link_doctype": "Customer", "link_name": "Nelson Brothers"}]
+ },
  {
-  "customer": "Netobill", 
-  "email_id": "LadislavKolaja@example.com", 
-  "first_name": "Ladislav", 
-  "last_name": "Kolaja", 
-  "supplier": null
- }, 
+  "email_id": "LadislavKolaja@example.com",
+  "first_name": "Ladislav",
+  "last_name": "Kolaja",
+  "links": [{"link_doctype": "Customer", "link_name": "Netobill"}]
+ },
  {
-  "customer": null, 
-  "email_id": "TewoldeAbaalom@example.com", 
-  "first_name": "Tewolde", 
-  "last_name": "Abaalom", 
-  "supplier": "Helios Air"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Helios Air"}],
+  "email_id": "TewoldeAbaalom@example.com",
+  "first_name": "Tewolde",
+  "last_name": "Abaalom"
+ },
  {
-  "customer": null, 
-  "email_id": "LeilaFernandesRodrigues@example.com", 
-  "first_name": "Leila", 
-  "last_name": "Rodrigues", 
-  "supplier": "Ks Merchandise"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Ks Merchandise"}],
+  "email_id": "LeilaFernandesRodrigues@example.com",
+  "first_name": "Leila",
+  "last_name": "Rodrigues"
+ },
  {
-  "customer": null, 
-  "email_id": "DmitryBulgakov@example.com", 
-  "first_name": "Dmitry", 
-  "last_name": "Bulgakov", 
-  "supplier": "HomeBase"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "HomeBase"}],
+  "email_id": "DmitryBulgakov@example.com",
+  "first_name": "Dmitry",
+  "last_name": "Bulgakov"
+ },
  {
-  "customer": null, 
-  "email_id": "HaiducWhitfoot@example.com", 
-  "first_name": "Haiduc", 
-  "last_name": "Whitfoot", 
-  "supplier": "Scott Ties"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Scott Ties"}],
+  "email_id": "HaiducWhitfoot@example.com",
+  "first_name": "Haiduc",
+  "last_name": "Whitfoot"
+ },
  {
-  "customer": null, 
-  "email_id": "SesseljaPetursdottir@example.com", 
-  "first_name": "Sesselja", 
-  "last_name": "P\u00e9tursd\u00f3ttir", 
-  "supplier": "Reliable Investments"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Reliable Investments"}],
+  "email_id": "SesseljaPetursdottir@example.com",
+  "first_name": "Sesselja",
+  "last_name": "P\u00e9tursd\u00f3ttir"
+ },
  {
-  "customer": null, 
-  "email_id": "HajdarPignar@example.com", 
-  "first_name": "Hajdar", 
-  "last_name": "Pignar", 
-  "supplier": "Nan Duskin"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Nan Duskin"}],
+  "email_id": "HajdarPignar@example.com",
+  "first_name": "Hajdar",
+  "last_name": "Pignar"
+ },
  {
-  "customer": null, 
-  "email_id": "GustavaLorenzo@example.com", 
-  "first_name": "Gustava", 
-  "last_name": "Lorenzo", 
-  "supplier": "Rainbow Records"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Rainbow Records"}],
+  "email_id": "GustavaLorenzo@example.com",
+  "first_name": "Gustava",
+  "last_name": "Lorenzo"
+ },
  {
-  "customer": null, 
-  "email_id": "BethanyWood@example.com", 
-  "first_name": "Bethany", 
-  "last_name": "Wood", 
-  "supplier": "New World Realty"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "New World Realty"}],
+  "email_id": "BethanyWood@example.com",
+  "first_name": "Bethany",
+  "last_name": "Wood"
+ },
  {
-  "customer": null, 
-  "email_id": "GlorianaBrownlock@example.com", 
-  "first_name": "Gloriana", 
-  "last_name": "Brownlock", 
-  "supplier": "Asiatic Solutions"
- }, 
+  "links": [{"link_doctype": "Supplier", "link_name": "Asiatic Solutions"}],
+  "email_id": "GlorianaBrownlock@example.com",
+  "first_name": "Gloriana",
+  "last_name": "Brownlock"
+ },
  {
-  "customer": null, 
-  "email_id": "JensonFraser@gustr.com", 
-  "first_name": "Jenson", 
-  "last_name": "Fraser", 
-  "supplier": "Eagle Hardware"
+  "links": [{"link_doctype": "Supplier", "link_name": "Eagle Hardware"}],
+  "email_id": "JensonFraser@gustr.com",
+  "first_name": "Jenson",
+  "last_name": "Fraser"
  }
 ]
\ No newline at end of file
diff --git a/erpnext/demo/setup/setup_data.py b/erpnext/demo/setup/setup_data.py
index 902bbab..4c1d443 100644
--- a/erpnext/demo/setup/setup_data.py
+++ b/erpnext/demo/setup/setup_data.py
@@ -32,7 +32,7 @@
 	import_json('Contact')
 	import_json('Lead')
 	setup_currency_exchange()
-	setup_mode_of_payment()
+	#setup_mode_of_payment()
 	setup_account_to_expense_type()
 	setup_budget()
 	setup_pos_profile()
@@ -46,9 +46,8 @@
 
 	if not frappe.get_all('Company', limit=1):
 		setup_complete({
-			"first_name": "Test",
-			"last_name": "User",
-			"email": "demo@erpnext.com",
+			"full_name": "Test User",
+			"email": "test_demo@erpnext.com",
 			"company_tagline": 'Awesome Products and Services',
 			"password": "demo",
 			"fy_start_date": "2015-01-01",
@@ -163,11 +162,10 @@
 	ss.append('deductions', {
 		'salary_component': 'Income Tax',
 		"abbr":'IT',
-		'condition': 'base > 1000',
-		'amount': random.random() * 1000,
+		'condition': 'base > 10000',
+		'formula': 'base*.1',
 		"idx": 1
 	})
-
 	ss.insert()
 
 	return ss
diff --git a/erpnext/demo/user/hr.py b/erpnext/demo/user/hr.py
index cfe3119..2536602 100644
--- a/erpnext/demo/user/hr.py
+++ b/erpnext/demo/user/hr.py
@@ -6,6 +6,7 @@
 from erpnext.projects.doctype.timesheet.test_timesheet import make_timesheet
 from erpnext.projects.doctype.timesheet.timesheet import make_salary_slip, make_sales_invoice
 from frappe.utils.make_random import get_random
+from erpnext.hr.doctype.expense_claim.test_expense_claim import get_payable_account
 from erpnext.hr.doctype.expense_claim.expense_claim import get_expense_approver, make_bank_entry
 from erpnext.hr.doctype.leave_application.leave_application import (get_leave_balance_on,
 	OverlapError, AttendanceAlreadyMarkedError)
@@ -50,6 +51,7 @@
 		expense_claim.extend('expenses', get_expenses())
 		expense_claim.employee = get_random("Employee")
 		expense_claim.company = frappe.flags.company
+		expense_claim.payable_account = get_payable_account(expense_claim.company)
 		expense_claim.posting_date = frappe.flags.current_date
 		expense_claim.exp_approver = filter((lambda x: x[0] != 'Administrator'), get_expense_approver(None, '', None, 0, 20, None))[0][0]
 		expense_claim.insert()
@@ -118,6 +120,7 @@
 	employees = get_timesheet_based_salary_slip_employee()
 	for e in employees:
 		ts = make_timesheet(e.employee, simulate = True, billable = 1, activity_type=get_random("Activity Type"))
+		frappe.db.commit()
 
 		rand = random.random()
 		if rand >= 0.3:
@@ -137,7 +140,8 @@
 	sales_invoice = make_sales_invoice(name)
 	sales_invoice.customer = get_random("Customer")
 	sales_invoice.append('items', {
-		'item_code': get_random("Item", {"has_variants": 0, "is_stock_item": 0, "is_fixed_asset": 0}),
+		'item_code': get_random("Item", {"has_variants": 0, "is_stock_item": 0,
+			"is_fixed_asset": 0}),
 		'qty': 1,
 		'rate': 1000
 	})
@@ -176,18 +180,18 @@
 				frappe.db.rollback()
 
 def mark_attendance():
-	att_date = frappe.flags.current_date
+	attendance_date = frappe.flags.current_date
 	for employee in frappe.get_all('Employee', fields=['name'], filters = {'status': 'Active'}):
 
-		if not frappe.db.get_value("Attendance", {"employee": employee.name, "att_date": att_date}):
+		if not frappe.db.get_value("Attendance", {"employee": employee.name, "attendance_date": attendance_date}):
 			attendance = frappe.get_doc({
 				"doctype": "Attendance",
 				"employee": employee.name,
-				"att_date": att_date
+				"attendance_date": attendance_date
 			})
 			leave = frappe.db.sql("""select name from `tabLeave Application`
 				where employee = %s and %s between from_date and to_date and status = 'Approved'
-				and docstatus = 1""", (employee.name, att_date))
+				and docstatus = 1""", (employee.name, attendance_date))
 
 			if leave:
 				attendance.status = "Absent"
diff --git a/erpnext/docs/assets/img/accounts/offline-records.png b/erpnext/docs/assets/img/accounts/offline-records.png
index 78bb730..a73f696 100644
--- a/erpnext/docs/assets/img/accounts/offline-records.png
+++ b/erpnext/docs/assets/img/accounts/offline-records.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/pos-customer.png b/erpnext/docs/assets/img/accounts/pos-customer.png
index ffb058a..c3cbb8a 100644
--- a/erpnext/docs/assets/img/accounts/pos-customer.png
+++ b/erpnext/docs/assets/img/accounts/pos-customer.png
Binary files differ
diff --git a/erpnext/docs/assets/img/accounts/pos-item.png b/erpnext/docs/assets/img/accounts/pos-item.png
index 321e8dc..14bd371 100644
--- a/erpnext/docs/assets/img/accounts/pos-item.png
+++ b/erpnext/docs/assets/img/accounts/pos-item.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/employee-loan-application.png b/erpnext/docs/assets/img/human-resources/employee-loan-application.png
new file mode 100644
index 0000000..317de4f
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/employee-loan-application.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/employee-loan.png b/erpnext/docs/assets/img/human-resources/employee-loan.png
new file mode 100644
index 0000000..19f3181
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/employee-loan.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/employee_account.png b/erpnext/docs/assets/img/human-resources/employee_account.png
new file mode 100644
index 0000000..a9a6066
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/employee_account.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/expense-claim-3.1.png b/erpnext/docs/assets/img/human-resources/expense-claim-3.1.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/expense-claim-3.1.png
rename to erpnext/docs/assets/img/human-resources/expense-claim-3.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/expense-claim-3.2.png b/erpnext/docs/assets/img/human-resources/expense-claim-3.2.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/expense-claim-3.2.png
rename to erpnext/docs/assets/img/human-resources/expense-claim-3.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/expense_claim.png b/erpnext/docs/assets/img/human-resources/expense_claim.png
index ddca100..9647d3d 100644
--- a/erpnext/docs/assets/img/human-resources/expense_claim.png
+++ b/erpnext/docs/assets/img/human-resources/expense_claim.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/expense_claim_book.png b/erpnext/docs/assets/img/human-resources/expense_claim_book.png
new file mode 100644
index 0000000..4b81604
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/expense_claim_book.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/loan-repayment-salary-slip.png b/erpnext/docs/assets/img/human-resources/loan-repayment-salary-slip.png
new file mode 100644
index 0000000..4e5f340
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/loan-repayment-salary-slip.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/loan-type.png b/erpnext/docs/assets/img/human-resources/loan-type.png
new file mode 100644
index 0000000..9146b89
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/loan-type.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/payment.png b/erpnext/docs/assets/img/human-resources/payment.png
new file mode 100644
index 0000000..f6b6e5d
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/payment.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/payment_entry.png b/erpnext/docs/assets/img/human-resources/payment_entry.png
new file mode 100644
index 0000000..a499ccf
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/payment_entry.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/repayment-info.png b/erpnext/docs/assets/img/human-resources/repayment-info.png
new file mode 100644
index 0000000..5b8bdf7
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/repayment-info.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/repayment-schedule.png b/erpnext/docs/assets/img/human-resources/repayment-schedule.png
new file mode 100644
index 0000000..f2ddf02
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/repayment-schedule.png
Binary files differ
diff --git a/erpnext/docs/assets/img/human-resources/unclaimed_expense_claims.png b/erpnext/docs/assets/img/human-resources/unclaimed_expense_claims.png
new file mode 100644
index 0000000..1581bb7
--- /dev/null
+++ b/erpnext/docs/assets/img/human-resources/unclaimed_expense_claims.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.1.png b/erpnext/docs/assets/img/human-resources/vehicle-1.1.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-1.1.png
rename to erpnext/docs/assets/img/human-resources/vehicle-1.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.2.png b/erpnext/docs/assets/img/human-resources/vehicle-1.2.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-1.2.png
rename to erpnext/docs/assets/img/human-resources/vehicle-1.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-1.3.png b/erpnext/docs/assets/img/human-resources/vehicle-1.3.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-1.3.png
rename to erpnext/docs/assets/img/human-resources/vehicle-1.3.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-expenses.png b/erpnext/docs/assets/img/human-resources/vehicle-expenses.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-expenses.png
rename to erpnext/docs/assets/img/human-resources/vehicle-expenses.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-log-2.1.png b/erpnext/docs/assets/img/human-resources/vehicle-log-2.1.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-log-2.1.png
rename to erpnext/docs/assets/img/human-resources/vehicle-log-2.1.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/vehicle-log-2.2.png b/erpnext/docs/assets/img/human-resources/vehicle-log-2.2.png
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/vehicle-log-2.2.png
rename to erpnext/docs/assets/img/human-resources/vehicle-log-2.2.png
Binary files differ
diff --git a/erpnext/docs/assets/img/fleet-management/__init__.py b/erpnext/docs/assets/img/setup/feedback/__init__.py
similarity index 100%
rename from erpnext/docs/assets/img/fleet-management/__init__.py
rename to erpnext/docs/assets/img/setup/feedback/__init__.py
diff --git a/erpnext/docs/assets/img/setup/feedback/feedback-trigger-condition.png b/erpnext/docs/assets/img/setup/feedback/feedback-trigger-condition.png
new file mode 100644
index 0000000..5fdae3c
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/feedback-trigger-condition.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/feedback-trigger-subject.png b/erpnext/docs/assets/img/setup/feedback/feedback-trigger-subject.png
new file mode 100644
index 0000000..22c3f4c
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/feedback-trigger-subject.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/manual-feedback-request-option.png b/erpnext/docs/assets/img/setup/feedback/manual-feedback-request-option.png
new file mode 100644
index 0000000..e9f6487
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/manual-feedback-request-option.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/manual-feedback-request.png b/erpnext/docs/assets/img/setup/feedback/manual-feedback-request.png
new file mode 100644
index 0000000..cf9ecc0
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/manual-feedback-request.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-button.png b/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-button.png
new file mode 100644
index 0000000..9a4b19d
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-button.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-custom-message.png b/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-custom-message.png
new file mode 100644
index 0000000..a68f520
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/resend-feedback-request-custom-message.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger-message.png b/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger-message.png
new file mode 100644
index 0000000..6bc802e
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger-message.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger.png b/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger.png
new file mode 100644
index 0000000..dec0336
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/setting-up-feedback-trigger.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/sidebar-ratings.png b/erpnext/docs/assets/img/setup/feedback/sidebar-ratings.png
new file mode 100644
index 0000000..72f4377
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/sidebar-ratings.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/submit-feedback.png b/erpnext/docs/assets/img/setup/feedback/submit-feedback.png
new file mode 100644
index 0000000..a1ccf0d
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/submit-feedback.png
Binary files differ
diff --git a/erpnext/docs/assets/img/setup/feedback/timeline-rating-and-feedback.png b/erpnext/docs/assets/img/setup/feedback/timeline-rating-and-feedback.png
new file mode 100644
index 0000000..0f691d3
--- /dev/null
+++ b/erpnext/docs/assets/img/setup/feedback/timeline-rating-and-feedback.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-email-digest.png b/erpnext/docs/assets/old_images/erpnext/calender-email-digest.png
new file mode 100644
index 0000000..1d95ef4
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-email-digest.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-event-lead.png b/erpnext/docs/assets/old_images/erpnext/calender-event-lead.png
new file mode 100644
index 0000000..dc6eb8b
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-event-lead.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-event-manually.png b/erpnext/docs/assets/old_images/erpnext/calender-event-manually.png
new file mode 100644
index 0000000..84cb343
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-event-manually.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-event-notification.png b/erpnext/docs/assets/old_images/erpnext/calender-event-notification.png
new file mode 100644
index 0000000..fa1e4ff
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-event-notification.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-event-permission.png b/erpnext/docs/assets/old_images/erpnext/calender-event-permission.png
new file mode 100644
index 0000000..783f968
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-event-permission.png
Binary files differ
diff --git a/erpnext/docs/assets/old_images/erpnext/calender-event-recurring.png b/erpnext/docs/assets/old_images/erpnext/calender-event-recurring.png
new file mode 100644
index 0000000..6147cf5
--- /dev/null
+++ b/erpnext/docs/assets/old_images/erpnext/calender-event-recurring.png
Binary files differ
diff --git a/erpnext/docs/install.md b/erpnext/docs/install.md
index 26ad128..c6a87cb 100644
--- a/erpnext/docs/install.md
+++ b/erpnext/docs/install.md
@@ -8,7 +8,7 @@
 
 After you have installed Frappe Bench, go to you bench folder, which is     `frappe.bench` by default and setup **erpnext**.
 
-    bench get-app erpnext {{ source_link }}
+    bench get-app erpnext https://github.com/frappe/erpnext
 
 Then create a new site to install the app.
 
@@ -27,4 +27,4 @@
 Fire up your browser and go to http://localhost:8000 and you should see the login screen. Login as **Administrator** and **admin** (or the password you set at the time of `new-site`) and you are set.
 
 <!-- jinja -->
-<!-- autodoc -->
\ No newline at end of file
+<!-- autodoc -->
diff --git a/erpnext/docs/user/manual/en/CRM/customer.md b/erpnext/docs/user/manual/en/CRM/customer.md
index 55755e6..1e4e0b5 100644
--- a/erpnext/docs/user/manual/en/CRM/customer.md
+++ b/erpnext/docs/user/manual/en/CRM/customer.md
@@ -13,7 +13,7 @@
 
 or upload it via the Data Import Tool.
 
-A Customer can avail the features (operations) in the selling process. The general flow can be summarazed as:
+A Customer can avail the features (operations) in the selling process. The general flow can be summarised as:
 
 <img class="screenshot" alt="Customer" src="{{docs_base_url}}/assets/img/crm/customer-to selling-flowchart.jpeg">
 
diff --git a/erpnext/docs/user/manual/en/human-resources/employee-loan-management.md b/erpnext/docs/user/manual/en/human-resources/employee-loan-management.md
new file mode 100644
index 0000000..b76a226
--- /dev/null
+++ b/erpnext/docs/user/manual/en/human-resources/employee-loan-management.md
@@ -0,0 +1,56 @@
+# Employee Loan Management
+This module enables companies which provides employee loans to define and manage employee loans.
+Employees can request loans, which are then reviewed and approved. For the approved loans, 
+repayment schedule for the entire loan cycle can be generated and automatic deduction from salary can also be set up. 
+
+### Loan Type
+To create a new Loan Type go to:
+
+> Human Resources > Employee Loan Management > Loan Type > New Loan Type
+
+Configure Loan limit and Rate of interest.
+
+<img class="screenshot" alt="Loan Type" src="{{docs_base_url}}/assets/img/human-resources/loan-type.png">
+
+### Employee Loan Application
+
+Employee can apply for loan by going to:
+
+> Human Resources > Employee Loan Management > Employee Loan Application > New Employee Loan Application
+
+<img class="screenshot" alt="Employee Loan Application" src="{{docs_base_url}}/assets/img/human-resources/employee-loan-application.png">
+
+#### In the Employee Loan Application,
+
+  * Enter Employee details and Loan details
+  * Select the repayment method, and based on your selection enter Repayment Period in Months or repayment Amount
+  
+On save, Employee can see Repayment Information and make changes if required before submitting.
+
+<img class="screenshot" alt="Employee Loan Application" src="{{docs_base_url}}/assets/img/human-resources/repayment-info.png">
+
+### Employee Loan
+
+Once the Loan is approved, Manager can create Employee Loan record for the Employee.
+
+> Human Resources > Employee Loan Management > Employee Loan > New Employee Loan
+
+<img class="screenshot" alt="Employee Loan Application" src="{{docs_base_url}}/assets/img/human-resources/employee-loan.png">
+
+#### In the Employee Loan,
+
+ * Enter Employee and Loan Application
+ * Check "Repay from Salary" if the loan repayment will be deducted from the salary
+ * Enter Disbursement Date and Account Info
+ * As soon as you hit save, the repayment schedule is generated.
+ 
+<img class="screenshot" alt="repayment Schedule" src="{{docs_base_url}}/assets/img/human-resources/repayment-schedule.png">
+
+#### Loan repayment deduction from Salary
+
+To auto deduct the Loan repayment from Salary, check "Repay from Salary" in Employee Loan. It will appear as Loan repayment in Salary Slip.
+
+<img class="screenshot" alt="Salary Slip" src="{{docs_base_url}}/assets/img/human-resources/loan-repayment-salary-slip.png">
+
+
+ 
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/human-resources/expense-claim.md b/erpnext/docs/user/manual/en/human-resources/expense-claim.md
index da3b2ee..1d4996d 100644
--- a/erpnext/docs/user/manual/en/human-resources/expense-claim.md
+++ b/erpnext/docs/user/manual/en/human-resources/expense-claim.md
@@ -9,6 +9,10 @@
 Set the Employee ID, date and the list of expenses that are to be claimed and
 “Submit” the record.
 
+### Set Account for Employee
+Set employee's expense account on the employee form, system books an expense amount of an employee under this account.
+<img class="screenshot" alt="Expense Claim" src="{{docs_base_url}}/assets/img/human-resources/employee_account.png">
+
 ### Approving Expenses
 
 Approver for the Expense Claim is selected by an Employee himself. Users to whom `Expense Approver` role is assigned will shown in the Expense Claim Approver field.
@@ -18,11 +22,25 @@
 Expense Claim Approver can update the “Sanctioned Amounts” against Claimed Amount of an Employee. If submitting, Approval Status should be submitted to Approved or Rejected. If Approved, then Expense Claim gets submitted. If rejected, then Expen
 Comments can be added in the Comments section explaining why the claim was approved or rejected.
 
-### Booking the Expense and Reimbursement
+### Booking the Expense
 
-The approved Expense Claim must then be converted into a Journal Entry and a
-payment must be made. Note: This amount should not be clubbed with Salary
-because the amount will then be taxable to the Employee.
+On submission of Expense Claim, system books an expense against the expense account and the employee account
+<img class="screenshot" alt="Expense Claim" src="{{docs_base_url}}/assets/img/human-resources/expense_claim_book.png">
+
+User can view unpaid expense claim using report "Unclaimed Expense Claims"
+<img class="screenshot" alt="Expense Claim" src="{{docs_base_url}}/assets/img/human-resources/unclaimed_expense_claims.png">
+
+### Payment for Expense Claim
+
+To make payment against the expense claim, user has to click on Make > Bank Entry
+#### Expense Claim
+<img class="screenshot" alt="Expense Claim" src="{{docs_base_url}}/assets/img/human-resources/payment.png">
+
+#### Payment Entry
+<img class="screenshot" alt="Expense Claim" src="{{docs_base_url}}/assets/img/human-resources/payment_entry.png">
+
+
+Note: This amount should not be clubbed with Salary because the amount will then be taxable to the Employee.
 
 ### Linking with Task & Project
 
diff --git a/erpnext/docs/user/manual/en/human-resources/fleet-management.md b/erpnext/docs/user/manual/en/human-resources/fleet-management.md
new file mode 100644
index 0000000..e55caa5
--- /dev/null
+++ b/erpnext/docs/user/manual/en/human-resources/fleet-management.md
@@ -0,0 +1,64 @@
+Fleet Management section of Human Resources helps your Organization manage their fleet of vehicles and track their expenses.
+
+To use Fleet Management in ERPNext,
+
+  1. Set Up a Vehicle.
+  2. Enter Vehicle Logs regularly.
+  3. Make Expense Claims for Vehicle Expenses.
+  4. View Reports for Vehicle Expenses.
+
+### Vehicle Set Up
+
+The Vehicle Set Up allows you to define the different types of Vehicles in your Organization.It acts as the Vehicle Master for Fleet Management. 
+
+To create a new Vehicle go to:
+
+Human Resources > Fleet Management > Vehicle
+
+* Enter License Plate, Make, Model, Odometer Value, Fuel Type and Fuel UOM for a quick entry.
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/human-resources/vehicle-1.1.png">
+
+* Enter details like Insurance, Chassis, Vehicle Value, Location and Employee.
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/human-resources/vehicle-1.2.png">
+
+* Enter Vehicle attributes like color, wheels, doors and last carbon check 
+
+	<img class="screenshot" alt="Vehicle" src="{{docs_base_url}}/assets/img/human-resources/vehicle-1.3.png">
+
+### Vehicle Log
+
+Vehicle Log is used to enter Odometer readings, Fuel Expenses and Service Expense details.
+
+To create a new Vehicle Log go to:
+
+Human Resources > Fleet Management > Vehicle Log
+
+* Enter License Plate, Employee, Date, Odometer reading for a quick entry.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/human-resources/vehicle-log-2.1.png">
+
+* Enter Refueling details, Service details if applicable.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/human-resources/vehicle-log-2.2.png">
+
+### Make Expense Claim
+
+* Click on Make Expense Claim button. This button appears only in case of Submitted Vehicle Logs.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/human-resources/expense-claim-3.1.png">
+
+When you click on 'Make Expense Claim',
+
+  1. The date,employee,expense total are copied over to the created Expense Claim.
+  2. The sum of Fuel Expenses and Service Expenses is copied over to Expense Claim Amount.
+  3. Employee can submit the Expense Claim for further processing.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/human-resources/expense-claim-3.2.png">
+
+### Vehicle Expenses Report
+
+* To track and monitor Vehicle Expenses you can use the Vehicle Expenses report.This report gives a one stop view of all your vehicle expenses month wise.
+
+	<img class="screenshot" alt="Vehicle Log" src="{{docs_base_url}}/assets/img/human-resources/vehicle-expenses.png">
diff --git a/erpnext/docs/user/manual/en/human-resources/index.txt b/erpnext/docs/user/manual/en/human-resources/index.txt
index 5615790..673efdb 100644
--- a/erpnext/docs/user/manual/en/human-resources/index.txt
+++ b/erpnext/docs/user/manual/en/human-resources/index.txt
@@ -14,4 +14,6 @@
 holiday-list
 human-resource-setup
 daily-work-summary
+fleet-management
+employee-loan-management
 articles
diff --git a/erpnext/docs/assets/img/fleet-management/__init__.py b/erpnext/docs/user/manual/en/setting-up/feedback/__init__.py
similarity index 100%
copy from erpnext/docs/assets/img/fleet-management/__init__.py
copy to erpnext/docs/user/manual/en/setting-up/feedback/__init__.py
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/index.md b/erpnext/docs/user/manual/en/setting-up/feedback/index.md
new file mode 100644
index 0000000..bb2efaf
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/index.md
@@ -0,0 +1,7 @@
+# Feedback
+
+Customer/User Feedback for a Product or Services can be useful for business as it can be used to make decisions for improvements either in products or services.
+
+### Topics
+
+{index}
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/index.txt b/erpnext/docs/user/manual/en/setting-up/feedback/index.txt
new file mode 100644
index 0000000..08160cc
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/index.txt
@@ -0,0 +1,4 @@
+setting-up-feedback
+submit-feedback
+resend-feedback-request
+manual-feedback-request
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/manual-feedback-request.md b/erpnext/docs/user/manual/en/setting-up/feedback/manual-feedback-request.md
new file mode 100644
index 0000000..4afaee1
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/manual-feedback-request.md
@@ -0,0 +1,17 @@
+# Manual Feedback Request
+
+We can also send the feedback request to Customer/User without configuring the
+Feedback Trigger.
+
+To request a feedback manually go to respective document e.g. Sales Order, Issue etc.
+and click on Ask a Feedback option in Menu.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/manual-feedback-request-option.png">
+
+Then, user can enter the feedback request details like email id, message and send the
+feedback request mail.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/manual-feedback-request.png">
+
+Note. If Feedback Trigger is already configured for the document then system will fetch
+Feedback Request details (email id, message)
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/resend-feedback-request.md b/erpnext/docs/user/manual/en/setting-up/feedback/resend-feedback-request.md
new file mode 100644
index 0000000..0dbb3b7
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/resend-feedback-request.md
@@ -0,0 +1,16 @@
+# Resend Feedback Request
+
+We can also Resend the Feedback Request to the Customer/User.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/timeline-rating-and-feedback.png">
+
+To resend the Feedback Request we will need to navigate the Communication by clicking the `Details` link on Timeline Feedback.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/resend-feedback-request-button.png">
+
+On Resend Button click a dialog with the Feedback Request message will appear user can either send the
+Feedback Request with same message or he/she can make the changes in the Feedback Request message.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/resend-feedback-request-custom-message.png">
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/setting-up-feedback.md b/erpnext/docs/user/manual/en/setting-up/feedback/setting-up-feedback.md
new file mode 100644
index 0000000..373d703
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/setting-up-feedback.md
@@ -0,0 +1,53 @@
+# Feedback Trigger
+
+You can set up the Feedback Trigger for various documents to get the Feedback from the user.
+
+For this, you will need to setup the Feedback Trigger,
+
+> Setup > Email > Feedback Trigger
+
+### Setting Up Feedback Trigger
+
+To Setup an Feedback:
+
+1. Select which Document Type you want to send feedback request mail.
+2. Select the Email Field, This field will be used to get the recipients email id.
+3. Set the Subject for feedback request mail.
+4. Set the conditions, if all the conditions are met only then the feedback request mail will be sent.
+5. Compose the message.
+
+### Setting a Subject
+You can retrieve the data for a particular field by using `doc.[field_name]`. To use it in your subject/message, you have to surround it with `{% raw %}{{ }}{% endraw %}`. These are called [Jinja](http://jinja.pocoo.org/) tags. So, for example, to get the name of a document, you use `{% raw %}{{ doc.name }}{% endraw %}`. The below example sends an feedback request whenever Issue is Closed with the Subject, "ISS-##### Issue is Resolved"
+
+<img class="screenshot" alt="Setting Subject" src="{{docs_base_url}}/assets/img/setup/feedback/feedback-trigger-subject.png">
+
+### Setting Conditions
+
+Feedback Trigger allows you to set conditions according to the field data in your documents. The feedback request email will be sent on document save only if the all conditions are true For example if you want to trigger the feedback request mail to a customer if an Issue is has been saved as "Closed" as it's status, you put `doc.status == "Closed"` in the conditions textbox. You can also set more complex conditions by combining them.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/feedback-trigger-condition.png">
+
+### Setting a Message
+
+You can use both Jinja Tags (`{% raw %}{{ doc.[field_name] }}{% endraw %}`) and HTML tags in the message textbox.
+
+	{% raw %}<h3>Your Support Ticket is Resolved</h3>
+
+	<p>Issue {{ doc.name }} Is resolved. Please check and confirm the same.</p>
+	<p> Your Feedback is important for us. Please give us your Feedback for {{ doc.name }}</p>
+	<p> Please visit the following url for feedback.</p>
+
+	{{ feedback_url }}
+	{% endraw %}
+
+---
+
+### Example
+
+1. Setting up Feedback Trigger
+    <img class="screenshot" alt="Defining Criteria" src="{{docs_base_url}}/assets/img/setup/feedback/setting-up-feedback-trigger.png">
+
+1. Setting the Recipients and Message
+    <img class="screenshot" alt="Set Message" src="{{docs_base_url}}/assets/img/setup/feedback/setting-up-feedback-trigger-message.png">
+
+{next}
diff --git a/erpnext/docs/user/manual/en/setting-up/feedback/submit-feedback.md b/erpnext/docs/user/manual/en/setting-up/feedback/submit-feedback.md
new file mode 100644
index 0000000..9069f37
--- /dev/null
+++ b/erpnext/docs/user/manual/en/setting-up/feedback/submit-feedback.md
@@ -0,0 +1,19 @@
+# Submit Feedback
+
+Once feedback request mail is sent the user/customer. He/She can visit the URL to submit the feedback
+as well as rating for the document.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/submit-feedback.png">
+
+Once Feedback is submitted the feedback details message and ratings will be recorded and will be shown on Document sidebar and timeline. Also once the Feedback is successfully submitted by the user the link shared to the user will be expired and can not be used to submit the Feedback again.
+
+On Document sidebar the latest feedback ratings will displayed.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/sidebar-ratings.png">
+
+Also, The Feedback details such as Feedback message and ratings will be shown in the Document's Timeline along
+with Comment, Email.
+
+<img class="screenshot" alt="Setting Condition" src="{{docs_base_url}}/assets/img/setup/feedback/timeline-rating-and-feedback.png">
+
+{next}
\ No newline at end of file
diff --git a/erpnext/docs/user/manual/en/stock/warehouse.md b/erpnext/docs/user/manual/en/stock/warehouse.md
index 172e469..74ee8cc 100644
--- a/erpnext/docs/user/manual/en/stock/warehouse.md
+++ b/erpnext/docs/user/manual/en/stock/warehouse.md
@@ -4,15 +4,27 @@
 cities, towns, and villages. They mostly have loading docks to load and unload
 goods from trucks.
 
+The terminology of 'Warehouse" in ERPNext is a bit broader though and maybe can be 
+regarded as "storage locations". For example you can create a sub-Warehouse which 
+practically is a shelf inside your actual location. 
+This can become quite a detailed Tree like >Warehouse >Room >Row >Shelf >Box
+
 To go to Warehouse, click on Stock and go to Warehouse under Setup.  You
 could also switch to 'Tree' View or simply type warehouse tree in the awsone bar.
 
 <img class="screenshot" alt="Warehouse" src="{{docs_base_url}}/assets/img/stock/warehouse.png">
 
 In ERPNext, every Warehouse must belong to a specific company, to maintain
-company wise stock balance. The Warehouses are saved with their respective
-company’s abbreviations. This facilitates in identifying which Warehouse
-belongs to which company, at a glance.
+company wise stock balance. In order to do so each Warehouse is linked with an 
+Account in the Chart of Accounts (by default of the the same name as the Warehouse 
+itself) which captures the monetary equivalent of the goods or materials stored 
+in that specific warehouse. If you have a more detailed Warehouse Tree as the one 
+described above most likely it's a good idea to link the sub-locations (>room >row >Shelf, ...)
+to the account of the actual Warehouse (the root Warehouse of that Tree) as most 
+scenarios do not require to account for value of stock items per Shelf or Box.
+
+Warehouses are saved with their respective company’s abbreviations. This facilitates 
+identifying which Warehouse belongs to which company, at a glance.
 
 You can include user restrictions for these Warehouses. In case you do not
 wish a particular user to operate on a particular Warehouse, you can refrain
diff --git a/erpnext/docs/user/manual/en/using-erpnext/calendar.md b/erpnext/docs/user/manual/en/using-erpnext/calendar.md
index 1ad325b..5e0ae29 100644
--- a/erpnext/docs/user/manual/en/using-erpnext/calendar.md
+++ b/erpnext/docs/user/manual/en/using-erpnext/calendar.md
@@ -34,7 +34,7 @@
 
 ###Permission for Event
 
-You can set Event as Private or Public. Private Events will be visible only to you, and if any other user selected in the participants table. Instead of User, you can also assign permission for event based on Role.
+You can set Event as Private or Public. Private Events will be visible only to you, and you can also assign permission for event based on Role in the participants table.
 
 Public Event, like Birthday will be visible to all.
 
diff --git a/erpnext/fleet_management/report/__init__.py b/erpnext/fleet_management/report/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/fleet_management/report/__init__.py
+++ /dev/null
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 59a1e2b..14ea74b 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -107,17 +107,12 @@
 	{"title": _("Shipments"), "route": "/shipments", "reference_doctype": "Delivery Note", "role":"Customer"},
 	{"title": _("Issues"), "route": "/issues", "reference_doctype": "Issue", "role":"Customer"},
 	{"title": _("Addresses"), "route": "/addresses", "reference_doctype": "Address"},
-	{"title": _("Announcements"), "route": "/announcement", "reference_doctype": "Announcement"},
-	{"title": _("Courses"), "route": "/course", "reference_doctype": "Course", "role":"Student"},
-	{"title": _("Assessment Schedule"), "route": "/assessment", "reference_doctype": "Assessment", "role":"Student"},
 	{"title": _("Fees"), "route": "/fees", "reference_doctype": "Fees", "role":"Student"}
 ]
 
 default_roles = [
-	{'role': 'Customer', 'doctype':'Contact', 'email_field': 'email_id',
-		'filters': {'ifnull(customer, "")': ('!=', '')}},
-	{'role': 'Supplier', 'doctype':'Contact', 'email_field': 'email_id',
-		'filters': {'ifnull(supplier, "")': ('!=', '')}},
+	{'role': 'Customer', 'doctype':'Contact', 'email_field': 'email_id'},
+	{'role': 'Supplier', 'doctype':'Contact', 'email_field': 'email_id'},
 	{'role': 'Student', 'doctype':'Student', 'email_field': 'student_email_id'}
 ]
 
@@ -126,19 +121,7 @@
 	"Sales Invoice": "erpnext.controllers.website_list_for_contact.has_website_permission",
 	"Supplier Quotation": "erpnext.controllers.website_list_for_contact.has_website_permission",
 	"Delivery Note": "erpnext.controllers.website_list_for_contact.has_website_permission",
-	"Issue": "erpnext.support.doctype.issue.issue.has_website_permission",
-	"Address": "erpnext.utilities.doctype.address.address.has_website_permission",
-	"Discussion": "erpnext.schools.web_form.discussion.discussion.has_website_permission"
-}
-
-permission_query_conditions = {
-	"Contact": "erpnext.utilities.address_and_contact.get_permission_query_conditions_for_contact",
-	"Address": "erpnext.utilities.address_and_contact.get_permission_query_conditions_for_address"
-}
-
-has_permission = {
-	"Contact": "erpnext.utilities.address_and_contact.has_permission",
-	"Address": "erpnext.utilities.address_and_contact.has_permission"
+	"Issue": "erpnext.support.doctype.issue.issue.has_website_permission"
 }
 
 dump_report_map = "erpnext.startup.report_data_map.data_map"
@@ -155,23 +138,14 @@
 		"on_cancel": "erpnext.stock.doctype.material_request.material_request.update_completed_and_requested_qty"
 	},
 	"User": {
+		"after_insert": "frappe.email.doctype.contact.contact.update_contact",
 		"validate": "erpnext.hr.doctype.employee.employee.validate_employee_role",
 		"on_update": "erpnext.hr.doctype.employee.employee.update_user_permissions",
-		"on_update": "erpnext.utilities.doctype.contact.contact.update_contact"
+		"on_update": "frappe.geo.address_and_contact.set_default_role"
 	},
 	("Sales Taxes and Charges Template", 'Price List'): {
 		"on_update": "erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings.validate_cart_settings"
 	},
-	"Address": {
-		"validate": "erpnext.shopping_cart.cart.set_customer_in_address"
-	},
-
-	# bubble transaction notification on master
-	('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice',
-		'Supplier Quotation', 'Purchase Order', 'Purchase Receipt',
-		'Purchase Invoice', 'Project', 'Issue'): {
-			'on_change': 'erpnext.accounts.party_status.notify_status'
-		},
 
 	"Website Settings": {
 		"validate": "erpnext.portal.doctype.products_settings.products_settings.home_page_is_products"
diff --git a/erpnext/hr/doctype/appraisal/appraisal.json b/erpnext/hr/doctype/appraisal/appraisal.json
index 0906557..450a47b 100644
--- a/erpnext/hr/doctype/appraisal/appraisal.json
+++ b/erpnext/hr/doctype/appraisal/appraisal.json
@@ -21,7 +21,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -49,7 +48,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Series", 
@@ -79,7 +77,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Appraisal Template", 
@@ -111,7 +108,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "For Employee", 
@@ -142,7 +138,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "For Employee Name", 
@@ -172,7 +167,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -202,7 +196,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Status", 
@@ -233,7 +226,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Start Date", 
@@ -263,7 +255,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "End Date", 
@@ -293,7 +284,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Goals", 
@@ -322,7 +312,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Goals", 
@@ -337,7 +326,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
@@ -352,7 +341,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Calculate Total Score", 
@@ -381,7 +369,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Total Score (Out of 5)", 
@@ -411,7 +398,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -438,7 +424,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Remarks", 
@@ -466,7 +451,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -493,7 +477,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -523,7 +506,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -550,7 +532,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -583,7 +564,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:47:32.082712", 
+ "modified": "2017-02-14 04:54:28.784666", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Appraisal", 
@@ -599,7 +580,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -620,7 +600,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -641,7 +620,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -661,5 +639,6 @@
  "sort_order": "DESC", 
  "timeline_field": "employee", 
  "title_field": "employee_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/appraisal/appraisal.py b/erpnext/hr/doctype/appraisal/appraisal.py
index df6d770..e69dfa8 100644
--- a/erpnext/hr/doctype/appraisal/appraisal.py
+++ b/erpnext/hr/doctype/appraisal/appraisal.py
@@ -16,6 +16,9 @@
 		if not self.status:
 			self.status = "Draft"
 
+		if not self.goals:
+			frappe.throw(_("Goals cannot be empty"))
+
 		set_employee_name(self)
 		self.validate_dates()
 		self.validate_existing_appraisal()
diff --git a/erpnext/hr/doctype/attendance/attendance.js b/erpnext/hr/doctype/attendance/attendance.js
index 2aeeb9f..7f2b18f 100644
--- a/erpnext/hr/doctype/attendance/attendance.js
+++ b/erpnext/hr/doctype/attendance/attendance.js
@@ -5,7 +5,7 @@
 cur_frm.add_fetch('employee', 'employee_name', 'employee_name');
 
 cur_frm.cscript.onload = function(doc, cdt, cdn) {
-	if(doc.__islocal) cur_frm.set_value("att_date", get_today());
+	if(doc.__islocal) cur_frm.set_value("attendance_date", get_today());
 }
 
 cur_frm.fields_dict.employee.get_query = function(doc,cdt,cdn) {
diff --git a/erpnext/hr/doctype/attendance/attendance.json b/erpnext/hr/doctype/attendance/attendance.json
index 9a1b66e..9bbb3e5 100644
--- a/erpnext/hr/doctype/attendance/attendance.json
+++ b/erpnext/hr/doctype/attendance/attendance.json
@@ -106,7 +106,7 @@
    "collapsible": 0, 
    "columns": 0, 
    "fieldname": "employee_name", 
-   "fieldtype": "Data", 
+   "fieldtype": "Read Only", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -148,7 +148,7 @@
    "no_copy": 1, 
    "oldfieldname": "status", 
    "oldfieldtype": "Select", 
-   "options": "\nPresent\nAbsent\nHalf Day", 
+   "options": "\nPresent\nAbsent\nOn Leave\nHalf Day", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -165,9 +165,10 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:doc.status==\"On Leave\"", 
    "fieldname": "leave_type", 
    "fieldtype": "Link", 
-   "hidden": 1, 
+   "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
@@ -180,11 +181,11 @@
    "oldfieldtype": "Link", 
    "options": "Leave Type", 
    "permlevel": 0, 
-   "print_hide": 1, 
+   "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
    "remember_last_selected_value": 0, 
-   "report_hide": 1, 
+   "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
@@ -223,7 +224,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "att_date", 
+   "fieldname": "attendance_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -234,7 +235,7 @@
    "label": "Attendance Date", 
    "length": 0, 
    "no_copy": 0, 
-   "oldfieldname": "att_date", 
+   "oldfieldname": "attendance_date", 
    "oldfieldtype": "Date", 
    "permlevel": 0, 
    "print_hide": 0, 
@@ -317,7 +318,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:50:01.058617", 
+ "modified": "2017-01-12 16:09:27.301839", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Attendance", 
@@ -390,9 +391,10 @@
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
- "search_fields": "employee, employee_name, att_date, status", 
+ "search_fields": "employee, employee_name, attendance_date, status", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "employee_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/attendance/attendance.py b/erpnext/hr/doctype/attendance/attendance.py
index feecae0..465c772 100644
--- a/erpnext/hr/doctype/attendance/attendance.py
+++ b/erpnext/hr/doctype/attendance/attendance.py
@@ -11,26 +11,31 @@
 
 class Attendance(Document):
 	def validate_duplicate_record(self):
-		res = frappe.db.sql("""select name from `tabAttendance` where employee = %s and att_date = %s
+		res = frappe.db.sql("""select name from `tabAttendance` where employee = %s and attendance_date = %s
 			and name != %s and docstatus = 1""",
-			(self.employee, self.att_date, self.name))
+			(self.employee, self.attendance_date, self.name))
 		if res:
 			frappe.throw(_("Attendance for employee {0} is already marked").format(self.employee))
 
 		set_employee_name(self)
 
 	def check_leave_record(self):
-		if self.status == 'Present':
-			leave = frappe.db.sql("""select name from `tabLeave Application`
-				where employee = %s and %s between from_date and to_date and status = 'Approved'
-				and docstatus = 1""", (self.employee, self.att_date))
+		leave_record = frappe.db.sql("""select leave_type, half_day from `tabLeave Application`
+			where employee = %s and %s between from_date and to_date and status = 'Approved'
+			and docstatus = 1""", (self.employee, self.attendance_date), as_dict=True)
+		if leave_record:
+			if leave_record[0].half_day:
+				self.status = 'Half Day'
+				frappe.msgprint(_("Employee {0} on Half day on {1}").format(self.employee, self.attendance_date))
+			else:
+				self.status = 'On Leave'
+				self.leave_type = leave_record[0].leave_type
+				frappe.msgprint(_("Employee {0} on Leave on {1}").format(self.employee, self.attendance_date))
+		if self.status == "On Leave" and not leave_record:
+			frappe.throw(_("No leave record found for employee {0} for {1}").format(self.employee, self.attendance_date))
 
-			if leave:
-				frappe.throw(_("Employee {0} was on leave on {1}. Cannot mark attendance.").format(self.employee,
-					self.att_date))
-
-	def validate_att_date(self):
-		if getdate(self.att_date) > getdate(nowdate()):
+	def validate_attendance_date(self):
+		if getdate(self.attendance_date) > getdate(nowdate()):
 			frappe.throw(_("Attendance can not be marked for future dates"))
 
 	def validate_employee(self):
@@ -41,13 +46,7 @@
 
 	def validate(self):
 		from erpnext.controllers.status_updater import validate_status
-		validate_status(self.status, ["Present", "Absent", "Half Day"])
-		self.validate_att_date()
+		validate_status(self.status, ["Present", "Absent", "On Leave", "Half Day"])
+		self.validate_attendance_date()
 		self.validate_duplicate_record()
 		self.check_leave_record()
-
-	def on_update(self):
-		# this is done because sometimes user entered wrong employee name
-		# while uploading employee attendance
-		employee_name = frappe.db.get_value("Employee", self.employee, "employee_name")
-		frappe.db.set(self, 'employee_name', employee_name)
diff --git a/erpnext/hr/doctype/attendance/attendance_list.js b/erpnext/hr/doctype/attendance/attendance_list.js
index 05353e2..f36fb15 100644
--- a/erpnext/hr/doctype/attendance/attendance_list.js
+++ b/erpnext/hr/doctype/attendance/attendance_list.js
@@ -1,5 +1,5 @@
 frappe.listview_settings['Attendance'] = {
-	add_fields: ["status", "att_date"],
+	add_fields: ["status", "attendance_date"],
 	get_indicator: function(doc) {
 		return [__(doc.status), doc.status=="Present" ? "green" : "darkgrey", "status,=," + doc.status];
 	}
diff --git a/erpnext/hr/doctype/attendance/test_records.json b/erpnext/hr/doctype/attendance/test_records.json
index 12983dc..1c8f3b5 100644
--- a/erpnext/hr/doctype/attendance/test_records.json
+++ b/erpnext/hr/doctype/attendance/test_records.json
@@ -4,7 +4,7 @@
 		"name": "_Test Attendance 1",
 		"employee": "_T-Employee-0001",
 		"status": "Present",
-		"att_date": "2014-02-01",
+		"attendance_date": "2014-02-01",
 		"company": "_Test Company"
 	}
 ]
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index 881853d..afa21e0 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -26,6 +26,8 @@
 				self.name = make_autoname(self.naming_series + '.####')
 			elif naming_method == 'Employee Number':
 				self.name = self.employee_number
+			elif naming_method == 'Full Name':
+				self.name = self.employee_name
 
 		self.employee = self.name
 
@@ -161,11 +163,11 @@
 
 def get_timeline_data(doctype, name):
 	'''Return timeline for attendance'''
-	return dict(frappe.db.sql('''select unix_timestamp(att_date), count(*)
+	return dict(frappe.db.sql('''select unix_timestamp(attendance_date), count(*)
 		from `tabAttendance` where employee=%s
-			and att_date > date_sub(curdate(), interval 1 year)
+			and attendance_date > date_sub(curdate(), interval 1 year)
 			and status in ('Present', 'Half Day')
-			group by att_date''', name))
+			group by attendance_date''', name))
 
 @frappe.whitelist()
 def get_retirement_date(date_of_birth=None):
@@ -271,7 +273,7 @@
 		last_name = employee_name[1]
 
 	first_name = employee_name[0]
-	
+
 	user = frappe.new_doc("User")
 	user.update({
 		"name": emp.employee_name,
@@ -286,4 +288,4 @@
 		"bio": emp.bio
 	})
 	user.insert()
-	return user.name
\ No newline at end of file
+	return user.name
diff --git a/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.py b/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
index 353008e..7438737 100644
--- a/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
+++ b/erpnext/hr/doctype/employee_attendance_tool/employee_attendance_tool.py
@@ -20,7 +20,7 @@
 		"status": "Active", "department": department, "branch": branch, "company": company}, order_by="employee_name")
 	marked_employee = {}
 	for emp in frappe.get_list("Attendance", fields=["employee", "status"],
-							   filters={"att_date": date}):
+							   filters={"attendance_date": date}):
 		marked_employee[emp['employee']] = emp['status']
 
 	for employee in employee_list:
@@ -36,14 +36,16 @@
 
 
 @frappe.whitelist()
-def mark_employee_attendance(employee_list, status, date, company=None):
+def mark_employee_attendance(employee_list, status, date, leave_type=None, company=None):
 	employee_list = json.loads(employee_list)
 	for employee in employee_list:
 		attendance = frappe.new_doc("Attendance")
 		attendance.employee = employee['employee']
 		attendance.employee_name = employee['employee_name']
-		attendance.att_date = date
+		attendance.attendance_date = date
 		attendance.status = status
+		if status == "On Leave" and leave_type:
+			attendance.leave_type = leave_type
 		if company:
 			attendance.company = company
 		else:
diff --git a/erpnext/hr/report/monthly_salary_register/__init__.py b/erpnext/hr/doctype/employee_loan/__init__.py
similarity index 100%
copy from erpnext/hr/report/monthly_salary_register/__init__.py
copy to erpnext/hr/doctype/employee_loan/__init__.py
diff --git a/erpnext/hr/doctype/employee_loan/employee_loan.js b/erpnext/hr/doctype/employee_loan/employee_loan.js
new file mode 100644
index 0000000..a03dbda
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan/employee_loan.js
@@ -0,0 +1,88 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Employee Loan', {
+	onload: function(frm) {
+		frm.set_query("employee_loan_application", function() {
+			return {
+				"filters": {
+					"employee": frm.doc.employee,
+					"docstatus": 1,
+					"status": "Approved"
+				}
+			};
+		});
+
+		$.each(["payment_account", "employee_loan_account"], function(i, field) {
+			frm.set_query(field, function() {
+				return {
+					"filters": {
+						"company": frm.doc.company,
+						"root_type": "Asset",
+						"is_group": 0
+					}
+				};
+			});
+		})
+	},
+
+	mode_of_payment: function(frm){
+		frappe.call({
+			method: "erpnext.accounts.doctype.sales_invoice.sales_invoice.get_bank_cash_account",
+			args: {
+				"mode_of_payment": frm.doc.mode_of_payment,
+				"company": frm.doc.company
+			},
+			callback: function(r, rt) {
+				if(r.message) {
+					frm.set_value("payment_account", r.message.account);
+				}
+			}
+		});
+	},
+
+	refresh: function(frm) {
+		frm.trigger("toggle_fields");
+
+		if(frm.doc.docstatus==1) {
+			frm.add_custom_button(__('Ledger'), function() {
+				frappe.route_options = {
+					"voucher_no": frm.doc.name,
+					"from_date": frm.doc.posting_date,
+					"to_date": frm.doc.posting_date,
+					"company": frm.doc.company,
+					group_by_voucher: 0
+				};
+				frappe.set_route("query-report", "General Ledger");
+			}, "fa fa-table");
+		}
+	},
+
+	employee_loan_application: function(frm) {
+		return frm.call({
+			method: "erpnext.hr.doctype.employee_loan.employee_loan.get_employee_loan_application",
+			args: {
+				"employee_loan_application": frm.doc.employee_loan_application
+			},
+			callback: function(r){
+				if(!r.exc && r.message) {
+					frm.set_value("loan_type", r.message.loan_type);
+					frm.set_value("loan_amount", r.message.loan_amount);
+					frm.set_value("repayment_method", r.message.repayment_method);
+					frm.set_value("monthly_repayment_amount", r.message.repayment_amount);
+					frm.set_value("repayment_periods", r.message.repayment_periods);
+					frm.set_value("rate_of_interest", r.message.rate_of_interest);
+				}
+			}
+		})
+	},
+
+	repayment_method: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+
+	toggle_fields: function(frm) {
+		frm.toggle_enable("monthly_repayment_amount", frm.doc.repayment_method=="Repay Fixed Amount per Period")
+		frm.toggle_enable("repayment_periods", frm.doc.repayment_method=="Repay Over Number of Periods")
+	}
+});
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.json b/erpnext/hr/doctype/employee_loan/employee_loan.json
similarity index 76%
copy from erpnext/fleet_management/doctype/vehicle/vehicle.json
copy to erpnext/hr/doctype/employee_loan/employee_loan.json
index edad8a2..560515f 100644
--- a/erpnext/fleet_management/doctype/vehicle/vehicle.json
+++ b/erpnext/hr/doctype/employee_loan/employee_loan.json
@@ -1,32 +1,34 @@
 {
  "allow_copy": 0, 
- "allow_import": 0, 
+ "allow_import": 1, 
  "allow_rename": 0, 
- "autoname": "field:license_plate", 
+ "autoname": "ELN.####", 
  "beta": 0, 
- "creation": "2016-09-03 03:33:27.680331", 
+ "creation": "2016-12-02 10:11:49.673604", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
  "document_type": "Document", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "license_plate", 
-   "fieldtype": "Data", 
+   "fieldname": "employee", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "License Plate", 
+   "label": "Employee", 
    "length": 0, 
-   "no_copy": 1, 
+   "no_copy": 0, 
+   "options": "Employee", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -37,24 +39,83 @@
    "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
-   "unique": 1
+   "unique": 0
   }, 
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "make", 
-   "fieldtype": "Data", 
+   "fieldname": "employee_name", 
+   "fieldtype": "Read Only", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Make", 
+   "label": "Employee Name", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "employee.employee_name", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 0, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "employee_loan_application", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Employee Loan Application", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Employee Loan Application", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "loan_type", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Loan Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Loan Type", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -99,71 +160,16 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "model", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Model", 
-   "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": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "vehicle_details", 
-   "fieldtype": "Section Break", 
+   "default": "", 
+   "fieldname": "posting_date", 
+   "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Details", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "last_odometer", 
-   "fieldtype": "Int", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
-   "label": "Odometer Value (Last)", 
+   "label": "Posting Date", 
    "length": 0, 
    "no_copy": 1, 
    "permlevel": 0, 
@@ -175,34 +181,6 @@
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
-   "set_only_once": 1, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "acquisition_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Acquisition Date", 
-   "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
   }, 
@@ -211,194 +189,26 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "location", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Location", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_8", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "chassis_no", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Chassis No", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "vehicle_value", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Vehicle Value", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 1, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "employee", 
+   "fieldname": "company", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Employee", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Employee", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "insurance_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Insurance Details", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "insurance_company", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Insurance Company", 
+   "label": "Company", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Company", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
-   "remember_last_selected_value": 0, 
+   "remember_last_selected_value": 1, 
    "report_hide": 0, 
-   "reqd": 0, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -408,187 +218,18 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "policy_no", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Policy No", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_15", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "start_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Start Date", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "end_date", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "End Date", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "additional_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Additional Details", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "fuel_type", 
+   "fieldname": "status", 
    "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Fuel Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Petrol\nDiesel\nNatural Gas\nElectric", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Litre", 
-   "fieldname": "uom", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Fuel UOM", 
+   "label": "Status", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "UOM", 
+   "options": "Loan Unpaid\nLoan Paid\nEMI in progress\nLoan Repaid", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -596,7 +237,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
@@ -606,15 +247,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "carbon_check_date", 
-   "fieldtype": "Date", 
+   "fieldname": "repay_from_salary", 
+   "fieldtype": "Check", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Last Carbon Check", 
+   "label": "Repay from Salary", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -634,7 +275,121 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "column_break_21", 
+   "fieldname": "section_break_8", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Details", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "loan_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Amount", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "", 
+   "fieldname": "rate_of_interest", 
+   "fieldtype": "Percent", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Rate of Interest (%) / Year", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "loan_type.rate_of_interest", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "disbursement_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Disbursement Date", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_11", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -661,15 +416,47 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "color", 
-   "fieldtype": "Data", 
+   "default": "Repay Over Number of Periods", 
+   "fieldname": "repayment_method", 
+   "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Color", 
+   "label": "Repayment Method", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "\nRepay Fixed Amount per Period\nRepay Over Number of Periods", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "", 
+   "depends_on": "", 
+   "fieldname": "repayment_periods", 
+   "fieldtype": "Int", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Repayment Period in Months", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -689,15 +476,17 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "wheels", 
-   "fieldtype": "Int", 
+   "default": "", 
+   "depends_on": "", 
+   "fieldname": "monthly_repayment_amount", 
+   "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Wheels", 
+   "label": "Repayment Amount", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -717,15 +506,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "doors", 
-   "fieldtype": "Int", 
+   "fieldname": "account_info", 
+   "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Doors", 
+   "label": "Account Info", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -745,6 +534,290 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "mode_of_payment", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Mode of Payment", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Mode of Payment", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "payment_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Payment Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_9", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "employee_loan_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Employee Loan Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Account", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_15", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Repayment Schedule", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "repayment_schedule", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Repayment Schedule", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Repayment Schedule", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_17", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Totals", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "0", 
+   "fieldname": "total_payment", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Total Payment", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_19", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "0", 
+   "fieldname": "total_interest_payable", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Total Interest Payable", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -756,7 +829,7 @@
    "label": "Amended From", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "Vehicle", 
+   "options": "Employee Loan", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -775,21 +848,21 @@
  "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
- "is_submittable": 0, 
+ "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 06:00:22.056662", 
+ "modified": "2017-01-17 07:13:10.704520", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle", 
+ "module": "HR", 
+ "name": "Employee Loan", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [
   {
    "amend": 0, 
    "apply_user_permissions": 0, 
-   "cancel": 0, 
+   "cancel": 1, 
    "create": 1, 
    "delete": 1, 
    "email": 1, 
@@ -801,19 +874,19 @@
    "print": 1, 
    "read": 1, 
    "report": 1, 
-   "role": "Fleet Manager", 
+   "role": "HR Manager", 
    "set_user_permissions": 0, 
    "share": 1, 
-   "submit": 0, 
+   "submit": 1, 
    "write": 1
   }
  ], 
- "quick_entry": 1, 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
- "search_fields": "license_plate,location,model", 
- "sort_field": "modified", 
+ "search_fields": "posting_date", 
+ "sort_field": "creation", 
  "sort_order": "DESC", 
- "title_field": "", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_loan/employee_loan.py b/erpnext/hr/doctype/employee_loan/employee_loan.py
new file mode 100644
index 0000000..568596e
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan/employee_loan.py
@@ -0,0 +1,127 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe, math
+import erpnext
+from frappe import _
+from frappe.utils import flt, rounded, add_months, nowdate
+from erpnext.controllers.accounts_controller import AccountsController
+from erpnext.accounts.general_ledger import make_gl_entries
+
+class EmployeeLoan(AccountsController):
+	def validate(self):
+		check_repayment_method(self.repayment_method, self.loan_amount, self.monthly_repayment_amount, self.repayment_periods)
+		if not self.company:
+			self.company = erpnext.get_default_company()
+		if not self.posting_date:
+			self.posting_date = nowdate()
+		if self.loan_type and not self.rate_of_interest:
+			self.rate_of_interest = frappe.db.get_value("Loan Type", self.loan_type, "rate_of_interest")
+		if self.repayment_method == "Repay Over Number of Periods":
+			self.monthly_repayment_amount = get_monthly_repayment_amount(self.repayment_method, self.loan_amount, self.rate_of_interest, self.repayment_periods)
+
+		self.make_repayment_schedule()
+		self.set_repayment_period()
+		self.calculate_totals()
+
+	def on_submit(self):
+		self.make_gl_entries()
+
+	def on_cancel(self):
+		self.make_gl_entries()
+
+	def make_gl_entries(self):
+		gl_entries = []
+		# Gl entries for employee loan account
+		gl_entries.append(
+			self.get_gl_dict({
+				"account": self.employee_loan_account,
+				"party_type": "Employee",
+				"party": self.employee,
+				"debit": self.loan_amount,
+				"debit_in_account_currency": self.loan_amount
+			})
+		)
+		# Gl entries for payment account
+		gl_entries.append(
+			self.get_gl_dict({
+				"account": self.payment_account,
+				"credit": self.loan_amount,
+				"credit_in_account_currency": self.loan_amount
+			})
+		)
+		make_gl_entries(gl_entries, cancel=(self.docstatus == 2))
+
+	def make_repayment_schedule(self):
+		self.repayment_schedule = []
+		payment_date = self.disbursement_date
+		balance_amount = self.loan_amount
+
+		while(balance_amount > 0):
+			interest_amount = rounded(balance_amount * flt(self.rate_of_interest) / (12*100))
+			principal_amount = self.monthly_repayment_amount - interest_amount
+			balance_amount = rounded(balance_amount + interest_amount - self.monthly_repayment_amount)
+
+			if balance_amount < 0:
+				principal_amount += balance_amount
+				balance_amount = 0.0
+
+			total_payment = principal_amount + interest_amount
+
+			self.append("repayment_schedule", {
+				"payment_date": payment_date,
+				"principal_amount": principal_amount,
+				"interest_amount": interest_amount,
+				"total_payment": total_payment,
+				"balance_loan_amount": balance_amount
+			})
+
+			next_payment_date = add_months(payment_date, 1)
+			payment_date = next_payment_date
+
+	def set_repayment_period(self):
+		if self.repayment_method == "Repay Fixed Amount per Period":
+			repayment_periods = len(self.repayment_schedule)
+
+			self.repayment_periods = repayment_periods
+
+	def calculate_totals(self):
+		self.total_payment = 0
+		self.total_interest_payable = 0
+		for data in self.repayment_schedule:
+			self.total_payment += data.total_payment
+			self.total_interest_payable +=data.interest_amount
+
+	def update_status(self):
+		if self.disbursement_date:
+			self.status = "Loan Paid"
+		if len(self.repayment_schedule)>0:
+			self.status = "repayment in progress"
+	
+def check_repayment_method(repayment_method, loan_amount, monthly_repayment_amount, repayment_periods):
+	if repayment_method == "Repay Over Number of Periods" and not repayment_periods:
+		frappe.throw(_("Please enter Repayment Periods"))
+		
+	if repayment_method == "Repay Fixed Amount per Period":
+		if not monthly_repayment_amount:
+			frappe.throw(_("Please enter repayment Amount"))
+		if monthly_repayment_amount > loan_amount:
+			frappe.throw(_("Monthly Repayment Amount cannot be greater than Loan Amount"))
+
+def get_monthly_repayment_amount(repayment_method, loan_amount, rate_of_interest, repayment_periods):
+	if rate_of_interest:
+		monthly_interest_rate = flt(rate_of_interest) / (12 *100)
+		monthly_repayment_amount = math.ceil((loan_amount * monthly_interest_rate *
+			(1 + monthly_interest_rate)**repayment_periods) \
+			/ ((1 + monthly_interest_rate)**repayment_periods - 1))
+	else:
+		monthly_repayment_amount = math.ceil(flt(loan_amount) / repayment_periods)
+	return monthly_repayment_amount
+
+@frappe.whitelist()
+def get_employee_loan_application(employee_loan_application):
+	employee_loan = frappe.get_doc("Employee Loan Application", employee_loan_application)
+	if employee_loan:
+		return employee_loan
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_loan/test_employee_loan.py b/erpnext/hr/doctype/employee_loan/test_employee_loan.py
new file mode 100644
index 0000000..c1c6ba2
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan/test_employee_loan.py
@@ -0,0 +1,68 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import erpnext
+import unittest
+from frappe.utils import nowdate
+from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee
+
+class TestEmployeeLoan(unittest.TestCase):
+	def setUp(self):
+		create_loan_type("Personal Loan", 500000, 8.4)
+		self.employee = make_employee("robert_loan@loan.com")
+		create_employee_loan(self.employee, "Personal Loan", 280000, "Repay Over Number of Periods", 20)
+	
+	def test_employee_loan(self):
+		employee_loan = frappe.get_doc("Employee Loan", {"employee":self.employee})
+		self.assertEquals(employee_loan.monthly_repayment_amount, 15052)
+		self.assertEquals(employee_loan.total_interest_payable, 21034)
+		self.assertEquals(employee_loan.total_payment, 301034)
+
+		schedule = employee_loan.repayment_schedule
+
+		self.assertEquals(len(schedule), 20)
+
+		for idx, principal_amount, interest_amount, balance_loan_amount in [[3, 13369, 1683, 227079], [19, 14941, 105, 0], [17, 14740, 312, 29785]]:
+			self.assertEquals(schedule[idx].principal_amount, principal_amount)
+			self.assertEquals(schedule[idx].interest_amount, interest_amount)
+			self.assertEquals(schedule[idx].balance_loan_amount, balance_loan_amount)
+
+		employee_loan.repayment_method = "Repay Fixed Amount per Period"
+		employee_loan.monthly_repayment_amount = 14000
+		employee_loan.save()
+
+		self.assertEquals(len(employee_loan.repayment_schedule), 22)
+		self.assertEquals(employee_loan.total_interest_payable, 22712)
+		self.assertEquals(employee_loan.total_payment, 302712)
+
+
+def create_loan_type(loan_name, maximum_loan_amount, rate_of_interest):
+	if not frappe.db.get_value("Loan Type", loan_name):
+		frappe.get_doc({
+			"doctype": "Loan Type",
+			"loan_name": loan_name,
+			"maximum_loan_amount": maximum_loan_amount,
+			"rate_of_interest": rate_of_interest
+		}).insert()
+
+def	create_employee_loan(employee, loan_type, loan_amount, repayment_method, repayment_periods):
+	if not frappe.db.get_value("Employee Loan", {"employee":employee}):
+		employee_loan = frappe.new_doc("Employee Loan")
+		employee_loan.update({
+				"employee": employee,
+				"loan_type": loan_type,
+				"loan_amount": loan_amount,
+				"repayment_method": repayment_method,
+				"repayment_periods": repayment_periods,
+				"disbursement_date": nowdate(),
+				"mode_of_payment": frappe.db.get_value('Mode of Payment', {'type': 'Cash'}, 'name'),
+				"payment_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name"),
+				"employee_loan_account": frappe.db.get_value('Account', {'account_type': 'Cash', 'company': erpnext.get_default_company(),'is_group':0}, "name")
+			})
+		employee_loan.insert()
+		return employee_loan
+	else:
+		return frappe.get_doc("Employee Loan", {"employee":employee})
\ No newline at end of file
diff --git a/erpnext/hr/report/monthly_salary_register/__init__.py b/erpnext/hr/doctype/employee_loan_application/__init__.py
similarity index 100%
copy from erpnext/hr/report/monthly_salary_register/__init__.py
copy to erpnext/hr/doctype/employee_loan_application/__init__.py
diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js
new file mode 100644
index 0000000..6958bea
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.js
@@ -0,0 +1,16 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Employee Loan Application', {
+	refresh: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+	repayment_method: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+
+	toggle_fields: function(frm) {
+		frm.toggle_enable("repayment_amount", frm.doc.repayment_method=="Repay Fixed Amount per Period")
+		frm.toggle_enable("repayment_periods", frm.doc.repayment_method=="Repay Over Number of Periods")
+	}
+});
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json
similarity index 82%
copy from erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
copy to erpnext/hr/doctype/employee_loan_application/employee_loan_application.json
index 26a4a01..e30dc5a 100644
--- a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
+++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.json
@@ -2,31 +2,33 @@
  "allow_copy": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
- "autoname": "naming_series:", 
+ "autoname": "ELA/.#####", 
  "beta": 0, 
- "creation": "2016-09-03 14:14:51.788550", 
+ "creation": "2016-12-02 12:35:56.046811", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
+ "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "vehicle_section", 
-   "fieldtype": "Section Break", 
+   "default": "Today", 
+   "fieldname": "posting_date", 
+   "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Posting Date", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "fa fa-user", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -44,72 +46,14 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "naming_series", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Series", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "VLOG.", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "license_plate", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "License Plate", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Vehicle", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "employee", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Employee", 
    "length": 0, 
    "no_copy": 0, 
@@ -131,7 +75,36 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "column_break_4", 
+   "fieldname": "employee_name", 
+   "fieldtype": "Read Only", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Employee Name", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "employee.employee_name", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -154,6 +127,177 @@
    "unique": 0
   }, 
   {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "status", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Status", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Open\nApproved\nRejected", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Company", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Company", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_4", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Info", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "loan_type", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Loan Type", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "loan_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Amount", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "required_by_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Required by Date", 
+   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -185,15 +329,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "model", 
-   "fieldtype": "Read Only", 
+   "fieldname": "description", 
+   "fieldtype": "Small Text", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Model", 
+   "label": "Reason", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -213,35 +357,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "make", 
-   "fieldtype": "Read Only", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Make", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "odometer_reading", 
+   "fieldname": "repayment_info", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -249,7 +365,7 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Odometer Reading", 
+   "label": "Repayment Info", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -269,17 +385,18 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "date", 
-   "fieldtype": "Date", 
+   "fieldname": "repayment_method", 
+   "fieldtype": "Select", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Date", 
+   "label": "Repayment Method", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "\nRepay Fixed Amount per Period\nRepay Over Number of Periods", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -297,50 +414,23 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "odometer", 
-   "fieldtype": "Int", 
+   "fieldname": "rate_of_interest", 
+   "fieldtype": "Percent", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Odometer", 
+   "label": "Rate of Interest", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "loan_type.rate_of_interest", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "refuelling_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Refuelling Details", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -353,35 +443,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "fuel_qty", 
-   "fieldtype": "Float", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Fuel Qty", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "price", 
+   "fieldname": "total_payable_interest", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -389,14 +451,14 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Fuel Price", 
+   "label": "Total Payable Interest", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -409,7 +471,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "column_break_15", 
+   "fieldname": "column_break_11", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -436,72 +498,16 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "supplier", 
-   "fieldtype": "Link", 
+   "depends_on": "", 
+   "fieldname": "repayment_amount", 
+   "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "invoice", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Invoice Ref", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
-   "fieldname": "service_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Service_Details", 
+   "label": "Repayment Amount", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -521,18 +527,18 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "service_detail", 
-   "fieldtype": "Table", 
+   "depends_on": "", 
+   "fieldname": "repayment_periods", 
+   "fieldtype": "Int", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Service Detail", 
+   "label": "Repayment Period in Months", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Vehicle Service", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -550,50 +556,22 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "section_break_20", 
-   "fieldtype": "Section Break", 
+   "fieldname": "total_payable_amount", 
+   "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Total Payable Amount", 
    "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_on_submit": 1, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.docstatus==1", 
-   "fieldname": "expense_claim", 
-   "fieldtype": "Button", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Make Expense Claim", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
@@ -617,7 +595,7 @@
    "label": "Amended From", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "Vehicle Log", 
+   "options": "Employee Loan Application", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -640,10 +618,10 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:24:55.310831", 
+ "modified": "2017-01-09 12:02:36.562577", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle Log", 
+ "module": "HR", 
+ "name": "Employee Loan Application", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [
@@ -662,18 +640,42 @@
    "print": 1, 
    "read": 1, 
    "report": 1, 
-   "role": "Fleet Manager", 
+   "role": "HR Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 1, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Employee", 
    "set_user_permissions": 0, 
    "share": 1, 
    "submit": 1, 
    "write": 1
   }
  ], 
- "quick_entry": 1, 
+ "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "search_fields": "employee, employee_name, loan_type, loan_amount", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
- "title_field": "", 
+ "timeline_field": "employee", 
+ "title_field": "employee_name", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py
new file mode 100644
index 0000000..15dbd4e
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan_application/employee_loan_application.py
@@ -0,0 +1,34 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe, math
+from frappe import _
+from frappe.utils import flt
+from frappe.model.document import Document
+
+from erpnext.hr.doctype.employee_loan.employee_loan import get_monthly_repayment_amount, check_repayment_method
+
+class EmployeeLoanApplication(Document):
+	def validate(self):
+		check_repayment_method(self.repayment_method, self.loan_amount, self.repayment_amount, self.repayment_periods)
+		self.validate_loan_amount()
+		self.get_repayment_details()
+
+	def validate_loan_amount(self):
+		maximum_loan_limit = frappe.db.get_value('Loan Type', self.loan_type, 'maximum_loan_amount')
+		if self.loan_amount > maximum_loan_limit:
+			frappe.throw(_("Loan Amount cannot exceed Maximum Loan Amount of {0}").format(maximum_loan_limit))
+
+	def get_repayment_details(self):
+		if self.repayment_method == "Repay Over Number of Periods":
+			self.repayment_amount = get_monthly_repayment_amount(self.repayment_method, self.loan_amount, self.rate_of_interest, self.repayment_periods)
+
+		if self.repayment_method == "Repay Fixed Amount per Period":
+			monthly_interest_rate = flt(self.rate_of_interest) / (12 *100)
+			self.repayment_periods = math.ceil((math.log(self.repayment_amount) - math.log(self.repayment_amount - \
+									(self.loan_amount*monthly_interest_rate)))/(math.log(1+monthly_interest_rate)))
+
+		self.total_payable_amount = self.repayment_amount * self.repayment_periods
+		self.total_payable_interest = self.total_payable_amount - self.loan_amount
\ No newline at end of file
diff --git a/erpnext/hr/doctype/employee_loan_application/test_employee_loan_application.py b/erpnext/hr/doctype/employee_loan_application/test_employee_loan_application.py
new file mode 100644
index 0000000..1d157d6
--- /dev/null
+++ b/erpnext/hr/doctype/employee_loan_application/test_employee_loan_application.py
@@ -0,0 +1,51 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+from erpnext.hr.doctype.salary_structure.test_salary_structure import make_employee
+
+class TestEmployeeLoanApplication(unittest.TestCase):
+	def setUp(self):
+		self.create_loan_type()
+		self.employee = make_employee("kate_loan@loan.com")
+		self.create_loan_application()
+
+	def create_loan_type(self):
+		if not frappe.db.get_value("Loan Type", "Home Loan"):
+			frappe.get_doc({
+				"doctype": "Loan Type",
+				"loan_name": "Home Loan",
+				"maximum_loan_amount": 500000,
+				"rate_of_interest": 9.2
+			}).insert()
+
+	def create_loan_application(self):
+		if not frappe.db.get_value("Employee Loan Application", {"employee":self.employee}, "name"):
+			loan_application = frappe.new_doc("Employee Loan Application")
+			loan_application.update({
+				"employee": self.employee,
+				"loan_type": "Home Loan",
+				"rate_of_interest": 9.2,
+				"loan_amount": 250000,
+				"repayment_method": "Repay Over Number of Periods",
+				"repayment_periods": 24
+			})
+			loan_application.insert()
+	
+
+	def test_loan_totals(self):
+		loan_application = frappe.get_doc("Employee Loan Application", {"employee":self.employee})
+		self.assertEquals(loan_application.repayment_amount, 11445)
+		self.assertEquals(loan_application.total_payable_interest, 24680)
+		self.assertEquals(loan_application.total_payable_amount, 274680)
+
+		loan_application.repayment_method = "Repay Fixed Amount per Period"
+		loan_application.repayment_amount = 15000
+		loan_application.save()
+
+		self.assertEquals(loan_application.repayment_periods, 18)
+		self.assertEquals(loan_application.total_payable_interest, 20000)
+		self.assertEquals(loan_application.total_payable_amount, 270000)
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.js b/erpnext/hr/doctype/expense_claim/expense_claim.js
index 8b3c451..7d19051 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.js
@@ -158,6 +158,21 @@
 	}
 }
 
+frappe.ui.form.on("Expense Claim", {
+	refresh: function(frm) {
+		if(frm.doc.docstatus == 1) {
+			frm.add_custom_button(__('Accounting Ledger'), function() {
+				frappe.route_options = {
+					voucher_no: frm.doc.name,
+					company: frm.doc.company,
+					group_by_voucher: false
+				};
+				frappe.set_route("query-report", "General Ledger");
+			}, __("View"));
+		}
+	}
+})
+
 frappe.ui.form.on("Expense Claim Detail", {
 	claim_amount: function(frm, cdt, cdn) {
 		var child = locals[cdt][cdn];
@@ -176,6 +191,47 @@
 	}
 })
 
+frappe.ui.form.on("Expense Claim",{
+	setup: function(frm) {
+		frm.trigger("set_query_for_cost_center")
+		frm.trigger("set_query_for_payable_account")
+		frm.add_fetch("company", "cost_center", "cost_center");
+		frm.add_fetch("company", "default_payable_account", "payable_account");
+	},
+
+	refresh: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+
+	set_query_for_cost_center: function(frm) {
+		frm.fields_dict["cost_center"].get_query = function() {
+			return {
+				filters: {
+					"company": frm.doc.company
+				}
+			}
+		}
+	},
+
+	set_query_for_payable_account: function(frm) {
+		frm.fields_dict["payable_account"].get_query = function() {
+			return {
+				filters: {
+					"root_type": "Liability",
+					"account_type": "Payable"
+				}
+			}
+		}
+	},
+
+	is_paid: function(frm) {
+		frm.trigger("toggle_fields")
+	},
+
+	toggle_fields: function(frm) {
+		frm.toggle_reqd("mode_of_payment", frm.doc.is_paid)
+	}
+});
 
 frappe.ui.form.on("Expense Claim", "employee_name", function(frm) {
 	erpnext.expense_claim.set_title(frm);
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.json b/erpnext/hr/doctype/expense_claim/expense_claim.json
index 67132bf..f517b91 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.json
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.json
@@ -46,6 +46,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "is_paid", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Paid", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "default": "Draft", 
    "depends_on": "eval:!doc.__islocal", 
    "fieldname": "approval_status", 
@@ -55,7 +83,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "Approval Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -86,7 +114,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "Approver", 
    "length": 0, 
    "no_copy": 0, 
@@ -175,7 +203,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Total Sanctioned Amount", 
    "length": 0, 
@@ -322,7 +350,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
+   "in_standard_filter": 0, 
    "label": "From Employee", 
    "length": 0, 
    "no_copy": 0, 
@@ -375,36 +403,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "company", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Company", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "company", 
-   "oldfieldtype": "Link", 
-   "options": "Company", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 1, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "vehicle_log", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -434,90 +432,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "cb1", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "total_amount_reimbursed", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Total Amount Reimbursed", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "Company:company:default_currency", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "remark", 
-   "fieldtype": "Small Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Remark", 
-   "length": 0, 
-   "no_copy": 1, 
-   "oldfieldname": "remark", 
-   "oldfieldtype": "Small Text", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "project", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -572,6 +486,90 @@
    "unique": 0
   }, 
   {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "cb1", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "length": 0, 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "total_amount_reimbursed", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Total Amount Reimbursed", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Company:company:default_currency", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "remark", 
+   "fieldtype": "Small Text", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Remark", 
+   "length": 0, 
+   "no_copy": 1, 
+   "oldfieldname": "remark", 
+   "oldfieldtype": "Small Text", 
+   "permlevel": 0, 
+   "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_on_submit": 1, 
    "bold": 0, 
    "collapsible": 0, 
@@ -613,7 +611,7 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Employees Email Address", 
+   "label": "Employees Email Id", 
    "length": 0, 
    "no_copy": 0, 
    "oldfieldname": "email_id", 
@@ -634,6 +632,238 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "accounting_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Accounting Details", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "company", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Company", 
+   "length": 0, 
+   "no_copy": 0, 
+   "oldfieldname": "company", 
+   "oldfieldtype": "Link", 
+   "options": "Company", 
+   "permlevel": 0, 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 1, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "is_paid", 
+   "fieldname": "mode_of_payment", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Mode of Payment", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Mode of Payment", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_24", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "", 
+   "fieldname": "payable_account", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Payable Account", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Account", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "cost_center", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Employees Email Address", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Cost Center", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 1, 
+   "columns": 0, 
+   "fieldname": "more_details", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "More Details", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "Draft", 
+   "fieldname": "status", 
+   "fieldtype": "Select", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 1, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Status", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Draft\nPaid\nUnpaid\nSubmitted\nCancelled", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 1, 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -663,7 +893,7 @@
  ], 
  "hide_heading": 0, 
  "hide_toolbar": 0, 
- "icon": "fa fa-money", 
+ "icon": "icon-money", 
  "idx": 1, 
  "image_view": 0, 
  "in_create": 0, 
@@ -673,10 +903,11 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-07 05:52:48.548201", 
+ "modified": "2017-01-19 18:15:35.968292", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Expense Claim", 
+ "name_case": "Title Case", 
  "owner": "harshada@webnotestech.com", 
  "permissions": [
   {
@@ -689,7 +920,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -710,7 +940,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -732,7 +961,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -754,7 +982,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -775,5 +1002,6 @@
  "sort_order": "DESC", 
  "timeline_field": "employee", 
  "title_field": "title", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim.py b/erpnext/hr/doctype/expense_claim/expense_claim.py
index efdee97..957753a 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/expense_claim.py
@@ -4,13 +4,17 @@
 from __future__ import unicode_literals
 import frappe
 from frappe import _
-from frappe.utils import get_fullname, flt
+from frappe.utils import get_fullname, flt, cstr
 from frappe.model.document import Document
 from erpnext.hr.utils import set_employee_name
+from erpnext.accounts.party import get_party_account
+from erpnext.accounts.general_ledger import make_gl_entries
+from erpnext.accounts.doctype.sales_invoice.sales_invoice import get_bank_cash_account
+from erpnext.controllers.accounts_controller import AccountsController
 
 class InvalidExpenseApproverError(frappe.ValidationError): pass
 
-class ExpenseClaim(Document):
+class ExpenseClaim(AccountsController):
 	def get_feed(self):
 		return _("{0}: From {0} for {1}").format(self.approval_status,
 			self.employee_name, self.total_claimed_amount)
@@ -21,16 +25,53 @@
 		self.calculate_total_amount()
 		set_employee_name(self)
 		self.set_expense_account()
+		self.set_payable_account()
+		self.set_cost_center()
+		self.set_status()
 		if self.task and not self.project:
 			self.project = frappe.db.get_value("Task", self.task, "project")
 
+	def set_status(self):
+		self.status = {
+			"0": "Draft",
+			"1": "Submitted",
+			"2": "Cancelled"
+		}[cstr(self.docstatus or 0)]
+
+		if self.total_sanctioned_amount == self.total_amount_reimbursed and self.docstatus == 1:
+			self.status = "Paid"
+		elif self.docstatus == 1:
+			self.status = "Unpaid"
+
+	def set_payable_account(self):
+		if not self.payable_account and not self.is_paid:
+			self.payable_account = frappe.db.get_value("Company", self.company, "default_payable_account")
+
+	def set_cost_center(self):
+		if not self.cost_center:
+			self.cost_center = frappe.db.get_value('Company', self.company, 'cost_center')
+
 	def on_submit(self):
 		if self.approval_status=="Draft":
 			frappe.throw(_("""Approval Status must be 'Approved' or 'Rejected'"""))
+
 		self.update_task_and_project()
+		self.make_gl_entries()
+
+		if self.is_paid:
+			update_reimbursed_amount(self)
+
+		self.set_status()
 
 	def on_cancel(self):
 		self.update_task_and_project()
+		if self.payable_account:
+			self.make_gl_entries(cancel=True)
+
+		if self.is_paid:
+			update_reimbursed_amount(self)
+
+		self.set_status()
 
 	def update_task_and_project(self):
 		if self.task:
@@ -38,6 +79,79 @@
 		elif self.project:
 			frappe.get_doc("Project", self.project).update_project()
 
+	def make_gl_entries(self, cancel = False):
+		if flt(self.total_sanctioned_amount) > 0:
+			gl_entries = self.get_gl_entries()
+			make_gl_entries(gl_entries, cancel)
+
+	def get_gl_entries(self):
+		gl_entry = []
+		self.validate_account_details()
+		
+		# payable entry
+		gl_entry.append(
+			self.get_gl_dict({
+				"account": self.payable_account,
+				"credit": self.total_sanctioned_amount,
+				"credit_in_account_currency": self.total_sanctioned_amount,
+				"against": ",".join([d.default_account for d in self.expenses]),
+				"party_type": "Employee",
+				"party": self.employee,
+				"against_voucher_type": self.doctype,
+				"against_voucher": self.name
+			})
+		)
+
+		# expense entries
+		for data in self.expenses:
+			gl_entry.append(
+				self.get_gl_dict({
+					"account": data.default_account,
+					"debit": data.sanctioned_amount,
+					"debit_in_account_currency": data.sanctioned_amount,
+					"against": self.employee,
+					"cost_center": self.cost_center
+				})
+			)
+
+		if self.is_paid:
+			# payment entry
+			payment_account = get_bank_cash_account(self.mode_of_payment, self.company).get("account")
+			gl_entry.append(
+				self.get_gl_dict({
+					"account": payment_account,
+					"credit": self.total_sanctioned_amount,
+					"credit_in_account_currency": self.total_sanctioned_amount,
+					"against": self.employee
+				})
+			)
+
+			gl_entry.append(
+				self.get_gl_dict({
+					"account": self.payable_account,
+					"party_type": "Employee",
+					"party": self.employee,
+					"against": payment_account,
+					"debit": self.total_sanctioned_amount,
+					"debit_in_account_currency": self.total_sanctioned_amount,
+					"against_voucher": self.name,
+					"against_voucher_type": self.doctype,
+				})
+			)
+
+		return gl_entry
+
+	def validate_account_details(self):
+		if not self.cost_center:
+			frappe.throw(_("Cost center is required to book an expense claim"))
+
+		if not self.payable_account:
+			frappe.throw(_("Please set default payable account in the employee {0}").format(self.employee))
+
+		if self.is_paid:
+			if not self.mode_of_payment:
+				frappe.throw(_("Mode of payment is required to make a payment").format(self.employee))
+
 	def calculate_total_amount(self):
 		self.total_claimed_amount = 0
 		self.total_sanctioned_amount = 0
@@ -64,7 +178,18 @@
 		for expense in self.expenses:
 			if not expense.default_account:
 				expense.default_account = get_expense_claim_account(expense.expense_type, self.company)["account"]
-		
+
+def update_reimbursed_amount(doc):
+	amt = frappe.db.sql("""select ifnull(sum(debit_in_account_currency), 0) as amt 
+		from `tabGL Entry` where against_voucher_type = 'Expense Claim' and against_voucher = %s
+		and party = %s """, (doc.name, doc.employee) ,as_dict=1)[0].amt
+
+	doc.total_amount_reimbursed = amt
+	frappe.db.set_value("Expense Claim", doc.name , "total_amount_reimbursed", amt)
+
+	doc.set_status()
+	frappe.db.set_value("Expense Claim", doc.name , "status", doc.status)
+
 @frappe.whitelist()
 def get_expense_approver(doctype, txt, searchfield, start, page_len, filters):
 	return frappe.db.sql("""
@@ -80,23 +205,26 @@
 
 	expense_claim = frappe.get_doc("Expense Claim", docname)
 	default_bank_cash_account = get_default_bank_cash_account(expense_claim.company, "Bank")
+	if not default_bank_cash_account:
+		default_bank_cash_account = get_default_bank_cash_account(expense_claim.company, "Cash")
 
 	je = frappe.new_doc("Journal Entry")
 	je.voucher_type = 'Bank Entry'
 	je.company = expense_claim.company
 	je.remark = 'Payment against Expense Claim: ' + docname;
 
-	for expense in expense_claim.expenses:
-		je.append("accounts", {
-			"account": expense.default_account,
-			"debit_in_account_currency": expense.sanctioned_amount,
-			"reference_type": "Expense Claim",
-			"reference_name": expense_claim.name
-		})
+	je.append("accounts", {
+		"account": expense_claim.payable_account,
+		"debit_in_account_currency": flt(expense_claim.total_sanctioned_amount - expense_claim.total_amount_reimbursed),
+		"reference_type": "Expense Claim",
+		"party_type": "Employee",
+		"party": expense_claim.employee,
+		"reference_name": expense_claim.name
+	})
 
 	je.append("accounts", {
 		"account": default_bank_cash_account.account,
-		"credit_in_account_currency": expense_claim.total_sanctioned_amount,
+		"credit_in_account_currency": flt(expense_claim.total_sanctioned_amount - expense_claim.total_amount_reimbursed),
 		"reference_type": "Expense Claim",
 		"reference_name": expense_claim.name,
 		"balance": default_bank_cash_account.balance,
diff --git a/erpnext/hr/doctype/expense_claim/expense_claim_list.js b/erpnext/hr/doctype/expense_claim/expense_claim_list.js
index 54073ed..7cff8e2 100644
--- a/erpnext/hr/doctype/expense_claim/expense_claim_list.js
+++ b/erpnext/hr/doctype/expense_claim/expense_claim_list.js
@@ -2,7 +2,10 @@
 	add_fields: ["approval_status", "total_claimed_amount", "docstatus"],
 	filters:[["approval_status","!=", "Rejected"]],
 	get_indicator: function(doc) {
-		return [__(doc.approval_status), frappe.utils.guess_colour(doc.approval_status),
-			"approval_status,=," + doc.approval_status];
+		if(doc.status == "Paid") {
+			return [__("Paid"), "green", "status,=,'Paid'"];
+		} else {
+			return [__("Unpaid"), "orange"];
+		}
 	}
 };
diff --git a/erpnext/hr/doctype/expense_claim/test_expense_claim.py b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
index 59d686e..20df7be 100644
--- a/erpnext/hr/doctype/expense_claim/test_expense_claim.py
+++ b/erpnext/hr/doctype/expense_claim/test_expense_claim.py
@@ -4,6 +4,8 @@
 
 import frappe
 import unittest
+from frappe.utils import random_string, nowdate
+from erpnext.hr.doctype.expense_claim.expense_claim import make_bank_entry
 
 test_records = frappe.get_test_records('Expense Claim')
 
@@ -11,8 +13,6 @@
 	def test_total_expense_claim_for_project(self):
 		frappe.db.sql("""delete from `tabTask` where project = "_Test Project 1" """)
 		frappe.db.sql("""delete from `tabProject` where name = "_Test Project 1" """)
-		frappe.db.sql("""delete from `tabExpense Claim`""")
-		frappe.db.sql("""delete from `tabExpense Claim Detail`""")
 
 		frappe.get_doc({
 			"project_name": "_Test Project 1",
@@ -22,15 +22,17 @@
 		}).save()
 
 		task_name = frappe.db.get_value("Task", {"project": "_Test Project 1"})
+		payable_account = get_payable_account("Wind Power LLC")
 
 		expense_claim = frappe.get_doc({
 			 "doctype": "Expense Claim",
 			 "employee": "_T-Employee-0001",
+			 "payable_account": payable_account,
 			 "approval_status": "Approved",
 			 "project": "_Test Project 1",
 			 "task": task_name,
 			 "expenses":
-			 	[{ "expense_type": "Food", "default_account": "Entertainment Expenses - _TC", "claim_amount": 300, "sanctioned_amount": 200 }]
+			 	[{ "expense_type": "Travel", "default_account": "Travel Expenses - WP", "claim_amount": 300, "sanctioned_amount": 200 }]
 		})
 		expense_claim.submit()
 
@@ -44,7 +46,7 @@
 			 "project": "_Test Project 1",
 			 "task": task_name,
 			 "expenses":
-			 	[{ "expense_type": "Food", "default_account": "Entertainment Expenses - _TC", "claim_amount": 600, "sanctioned_amount": 500 }]
+			 	[{ "expense_type": "Travel", "default_account": "Travel Expenses - WP", "claim_amount": 600, "sanctioned_amount": 500 }]
 		})
 		expense_claim2.submit()
 
@@ -52,6 +54,64 @@
 		self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 700)
 
 		expense_claim2.cancel()
+		frappe.delete_doc("Expenses Claim", expense_claim2.name)
 
 		self.assertEqual(frappe.db.get_value("Task", task_name, "total_expense_claim"), 200)
 		self.assertEqual(frappe.db.get_value("Project", "_Test Project 1", "total_expense_claim"), 200)
+		
+	def test_expense_claim_status(self):
+		payable_account = get_payable_account("Wind Power LLC")
+		expense_claim = frappe.get_doc({
+			 "doctype": "Expense Claim",
+			 "employee": "_T-Employee-0001",
+			 "payable_account": payable_account,
+			 "approval_status": "Approved",
+			 "expenses":
+			 	[{ "expense_type": "Travel", "default_account": "Travel Expenses - WP", "claim_amount": 300, "sanctioned_amount": 200 }]
+		})
+		expense_claim.submit()
+
+		je_dict = make_bank_entry(expense_claim.name)
+		je = frappe.get_doc(je_dict)
+		je.posting_date = nowdate()
+		je.cheque_no = random_string(5)
+		je.cheque_date = nowdate()
+		je.submit()
+
+		expense_claim = frappe.get_doc("Expense Claim", expense_claim.name)
+		self.assertEqual(expense_claim.status, "Paid")
+		
+		je.cancel()
+		expense_claim = frappe.get_doc("Expense Claim", expense_claim.name)
+		self.assertEqual(expense_claim.status, "Unpaid")
+
+	def test_expense_claim_gl_entry(self):
+		payable_account = get_payable_account("Wind Power LLC")
+		expense_claim = frappe.get_doc({
+			 "doctype": "Expense Claim",
+			 "employee": "_T-Employee-0001",
+			 "payable_account": payable_account,
+			 "approval_status": "Approved",
+			 "expenses":
+			 	[{ "expense_type": "Travel", "default_account": "Travel Expenses - WP", "claim_amount": 300, "sanctioned_amount": 200 }]
+		})
+		expense_claim.submit()
+		
+		gl_entries = frappe.db.sql("""select account, debit, credit
+			from `tabGL Entry` where voucher_type='Expense Claim' and voucher_no=%s
+			order by account asc""", expense_claim.name, as_dict=1)
+
+		self.assertTrue(gl_entries)
+
+		expected_values = dict((d[0], d) for d in [
+			[payable_account, 0.0, 200.0],
+			["Travel Expenses - WP", 200.0, 0.0]
+		])
+
+		for gle in gl_entries:
+			self.assertEquals(expected_values[gle.account][0], gle.account)
+			self.assertEquals(expected_values[gle.account][1], gle.debit)
+			self.assertEquals(expected_values[gle.account][2], gle.credit)
+
+def get_payable_account(company):
+	return frappe.db.get_value('Company', company, 'default_payable_account')
diff --git a/erpnext/hr/doctype/hr_settings/hr_settings.json b/erpnext/hr/doctype/hr_settings/hr_settings.json
index e9d2098..5281045 100644
--- a/erpnext/hr/doctype/hr_settings/hr_settings.json
+++ b/erpnext/hr/doctype/hr_settings/hr_settings.json
@@ -22,6 +22,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Employee Settings", 
    "length": 0, 
    "no_copy": 0, 
@@ -50,6 +51,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Retirement Age", 
    "length": 0, 
    "no_copy": 0, 
@@ -79,10 +81,11 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Employee Records to be created by", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Naming Series\nEmployee Number", 
+   "options": "Naming Series\nEmployee Number\nFull Name", 
    "permlevel": 0, 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
@@ -106,6 +109,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -133,6 +137,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Stop Birthday Reminders", 
    "length": 0, 
    "no_copy": 0, 
@@ -159,6 +164,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Maintain Billing Hours and Working Hours Same on Timesheet", 
    "length": 0, 
    "no_copy": 0, 
@@ -186,6 +192,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Payroll Settings", 
    "length": 0, 
    "no_copy": 0, 
@@ -213,6 +220,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Include holidays in Total no. of Working Days", 
    "length": 0, 
    "no_copy": 0, 
@@ -241,6 +249,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Email Salary Slip to Employee", 
    "length": 0, 
    "no_copy": 0, 
@@ -268,6 +277,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Max working hours against Timesheet", 
    "length": 0, 
    "no_copy": 0, 
@@ -295,8 +305,8 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-21 18:52:03.633251", 
- "modified_by": "Administrator", 
+ "modified": "2017-01-16 14:01:31.183485", 
+ "modified_by": "anastasiadis.st00@gmail.com", 
  "module": "HR", 
  "name": "HR Settings", 
  "owner": "Administrator", 
@@ -327,5 +337,6 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "sort_order": "ASC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.py b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
index 3473fd8..58a7f30 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -93,7 +93,7 @@
 		
 		if flt(leaves_taken) > flt(self.total_leaves_allocated):
 			if frappe.db.get_value("Leave Type", self.leave_type, "allow_negative"):
-				frappe.msgprint(_("Note: Total allocated leaves {0} shouldn't be less than already approved leaves {1} for the period").format(self.total_leaves_allocated, leaves_taken), LessAllocationError)
+				frappe.msgprint(_("Note: Total allocated leaves {0} shouldn't be less than already approved leaves {1} for the period").format(self.total_leaves_allocated, leaves_taken))
 			else:
 				frappe.throw(_("Total allocated leaves {0} cannot be less than already approved leaves {1} for the period").format(self.total_leaves_allocated, leaves_taken), LessAllocationError)
 
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index fbf86e1..84c14c9 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -25,7 +25,7 @@
 
 	def validate(self):
 		if not getattr(self, "__islocal", None) and frappe.db.exists(self.doctype, self.name):
-			self.previous_doc = frappe.db.get_value(self.doctype, self.name, "*", as_dict=True)
+			self.previous_doc = frappe.get_value(self.doctype, self.name, "leave_approver", as_dict=True)
 		else:
 			self.previous_doc = None
 
@@ -46,14 +46,10 @@
 				self.status == "Open" and self.previous_doc.leave_approver != self.leave_approver):
 			# notify leave approver about creation
 			self.notify_leave_approver()
-		elif self.previous_doc and \
-				self.previous_doc.status == "Open" and self.status == "Rejected":
-			# notify employee about rejection
-			self.notify_employee(self.status)
 
 	def on_submit(self):
-		if self.status != "Approved":
-			frappe.throw(_("Only Leave Applications with status 'Approved' can be submitted"))
+		if self.status == "Open":
+			frappe.throw(_("Only Leave Applications with status 'Approved' and 'Rejected' can be submitted"))
 
 		self.validate_back_dated_application()
 
@@ -216,7 +212,7 @@
 				LeaveApproverIdentityError)
 
 	def validate_attendance(self):
-		attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s and (att_date between %s and %s)
+		attendance = frappe.db.sql("""select name from `tabAttendance` where employee = %s and (attendance_date between %s and %s)
 					and status = "Present" and docstatus = 1""",
 			(self.employee, self.from_date, self.to_date))
 		if attendance:
@@ -234,13 +230,18 @@
 			else:
 				name = self.name
 
-			return (_("Leave Application") + ": %s - %s") % (name, _(status))
+			message = "Leave Application: {name}".format(name=name)+"<br>"
+			message += "Leave Type: {leave_type}".format(leave_type=self.leave_type)+"<br>"
+			message += "From Date: {from_date}".format(from_date=self.from_date)+"<br>"
+			message += "To Date: {to_date}".format(to_date=self.to_date)+"<br>"
+			message += "Status: {status}".format(status=_(status))
+			return message
 
 		self.notify({
 			# for post in messages
 			"message": _get_message(url=True),
 			"message_to": employee.user_id,
-			"subject": _get_message(),
+			"subject": (_("Leave Application") + ": %s - %s") % (self.name, _(status))
 		})
 
 	def notify_leave_approver(self):
@@ -252,8 +253,12 @@
 			if url:
 				name = get_link_to_form(self.doctype, self.name)
 				employee_name = get_link_to_form("Employee", self.employee, label=employee_name)
-
-			return (_("New Leave Application") + ": %s - " + _("Employee") + ": %s") % (name, employee_name)
+			message = (_("Leave Application") + ": %s") % (name)+"<br>"
+			message += (_("Employee") + ": %s") % (employee_name)+"<br>"
+			message += (_("Leave Type") + ": %s") % (self.leave_type)+"<br>"
+			message += (_("From Date") + ": %s") % (self.from_date)+"<br>"
+			message += (_("To Date") + ": %s") % (self.to_date)
+			return message
 
 		self.notify({
 			# for post in messages
@@ -261,7 +266,7 @@
 			"message_to": self.leave_approver,
 
 			# for email
-			"subject": _get_message()
+			"subject": (_("New Leave Application") + ": %s - " + _("Employee") + ": %s") % (self.name, cstr(employee.employee_name))
 		})
 
 	def notify(self, args):
@@ -270,6 +275,7 @@
 		post(**{"txt": args.message, "contact": args.message_to, "subject": args.subject,
 			"notify": cint(self.follow_via_email)})
 
+
 @frappe.whitelist()
 def get_approvers(doctype, txt, searchfield, start, page_len, filters):
 	if not filters.get("employee"):
diff --git a/erpnext/fleet_management/doctype/__init__.py b/erpnext/hr/doctype/loan_type/__init__.py
similarity index 100%
rename from erpnext/fleet_management/doctype/__init__.py
rename to erpnext/hr/doctype/loan_type/__init__.py
diff --git a/erpnext/hr/doctype/loan_type/loan_type.js b/erpnext/hr/doctype/loan_type/loan_type.js
new file mode 100644
index 0000000..72f5775
--- /dev/null
+++ b/erpnext/hr/doctype/loan_type/loan_type.js
@@ -0,0 +1,7 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Loan Type', {
+	refresh: function(frm) {
+	}
+});
diff --git a/erpnext/hr/doctype/loan_type/loan_type.json b/erpnext/hr/doctype/loan_type/loan_type.json
new file mode 100644
index 0000000..f9441ea
--- /dev/null
+++ b/erpnext/hr/doctype/loan_type/loan_type.json
@@ -0,0 +1,230 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "autoname": "field:loan_name", 
+ "beta": 0, 
+ "creation": "2016-12-02 10:41:40.732843", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "loan_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Name", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "maximum_loan_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Maximum Loan Amount", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "rate_of_interest", 
+   "fieldtype": "Percent", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Rate of Interest (%) Yearly", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "", 
+   "fieldname": "disabled", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Disabled", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "description", 
+   "fieldtype": "Text", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Description", 
+   "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
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2016-12-29 15:54:17.716285", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "Loan Type", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "HR Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 0, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/loan_type/loan_type.py b/erpnext/hr/doctype/loan_type/loan_type.py
new file mode 100644
index 0000000..2714e20
--- /dev/null
+++ b/erpnext/hr/doctype/loan_type/loan_type.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class LoanType(Document):
+	pass
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/hr/doctype/loan_type/test_loan_type.py
similarity index 65%
copy from erpnext/schools/doctype/assessment/test_assessment.py
copy to erpnext/hr/doctype/loan_type/test_loan_type.py
index ce06007..078e11e 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/hr/doctype/loan_type/test_loan_type.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Loan Type')
 
-class TestAssessment(unittest.TestCase):
+class TestLoanType(unittest.TestCase):
 	pass
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.js b/erpnext/hr/doctype/process_payroll/process_payroll.js
index cfb646d..128e533 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.js
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.js
@@ -10,6 +10,19 @@
 		frm.toggle_reqd(['payroll_frequency'], !frm.doc.salary_slip_based_on_timesheet);
 	},
 
+	setup: function(frm) {
+		frm.set_query("payment_account", function() {
+			var account_types = ["Bank", "Cash"];
+			return {
+				filters: {
+					"account_type": ["in", account_types],
+					"is_group": 0,
+					"company": frm.doc.company
+				}
+			}
+		})
+	},
+
 	refresh: function(frm) {
 		frm.disable_save();
 	},
@@ -50,16 +63,6 @@
 				}
 			})
 		}
-	},
-	account: function(frm) {
-		var account_types = ["Bank", "Cash"];
-		return {
-			filters: {
-				"account_type": ["in", account_types],
-				"is_group": 0,
-				"company": frm.doc.company
-			}
-		}
 	}
 })
 
diff --git a/erpnext/hr/doctype/process_payroll/process_payroll.py b/erpnext/hr/doctype/process_payroll/process_payroll.py
index 16b5207..7bfde1c 100644
--- a/erpnext/hr/doctype/process_payroll/process_payroll.py
+++ b/erpnext/hr/doctype/process_payroll/process_payroll.py
@@ -296,17 +296,16 @@
 			frappe.db.set_value("Salary Slip", ss_obj.name, "journal_entry", jv_name)
 
 	def set_start_end_dates(self):
-		self.update(get_start_end_dates(self.payroll_frequency, self.start_date or self.posting_date))
+		self.update(get_start_end_dates(self.payroll_frequency, 
+			self.start_date or self.posting_date, self.company))
 
 
 @frappe.whitelist()
-def get_start_end_dates(payroll_frequency, start_date=None):
+def get_start_end_dates(payroll_frequency, start_date=None, company=None):
 	'''Returns dict of start and end dates for given payroll frequency based on start_date'''
-	if not payroll_frequency:
-		frappe.throw(_("Please set Payroll Frequency first"))
 
-	if payroll_frequency == "Monthly" or payroll_frequency == "Bimonthly":
-		fiscal_year = get_fiscal_year(start_date)[0]
+	if payroll_frequency == "Monthly" or payroll_frequency == "Bimonthly" or payroll_frequency == "":
+		fiscal_year = get_fiscal_year(start_date, company=company)[0]
 		month = "%02d" % getdate(start_date).month
 		m = get_month_details(fiscal_year, month)
 		if payroll_frequency == "Bimonthly":
diff --git a/erpnext/hr/report/monthly_salary_register/__init__.py b/erpnext/hr/doctype/repayment_schedule/__init__.py
similarity index 100%
copy from erpnext/hr/report/monthly_salary_register/__init__.py
copy to erpnext/hr/doctype/repayment_schedule/__init__.py
diff --git a/erpnext/hr/doctype/repayment_schedule/repayment_schedule.json b/erpnext/hr/doctype/repayment_schedule/repayment_schedule.json
new file mode 100644
index 0000000..3a0dfd3
--- /dev/null
+++ b/erpnext/hr/doctype/repayment_schedule/repayment_schedule.json
@@ -0,0 +1,179 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "beta": 0, 
+ "creation": "2016-12-20 15:32:25.078334", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "payment_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Payment Date", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "principal_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Principal Amount", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "interest_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Interest Amount", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "total_payment", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Total Payment", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "balance_loan_amount", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Balance Loan Amount", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 1, 
+ "max_attachments": 0, 
+ "modified": "2017-01-09 12:00:10.818772", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "Repayment Schedule", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_changes": 1, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/hr/doctype/repayment_schedule/repayment_schedule.py b/erpnext/hr/doctype/repayment_schedule/repayment_schedule.py
new file mode 100644
index 0000000..8abee5e
--- /dev/null
+++ b/erpnext/hr/doctype/repayment_schedule/repayment_schedule.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class RepaymentSchedule(Document):
+	pass
diff --git a/erpnext/hr/doctype/salary_component/salary_component.js b/erpnext/hr/doctype/salary_component/salary_component.js
index 3ed566e..3a2492c 100644
--- a/erpnext/hr/doctype/salary_component/salary_component.js
+++ b/erpnext/hr/doctype/salary_component/salary_component.js
@@ -2,7 +2,16 @@
 // For license information, please see license.txt
 
 frappe.ui.form.on('Salary Component', {
-	refresh: function(frm) {
-
+	setup: function(frm) {
+		frm.set_query("default_account", "accounts", function(doc, cdt, cdn) {
+			var d = locals[cdt][cdn];
+			return {
+				filters: {
+					"root_type": "Expense",
+					"is_group": 0,
+					"company": d.company
+				}
+			}
+		})
 	}
 });
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.js b/erpnext/hr/doctype/salary_slip/salary_slip.js
index 8b0dd16..0262259 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.js
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.js
@@ -110,6 +110,7 @@
 	calculate_earning_total(doc, dt, dn, true);
 	calculate_ded_total(doc, dt, dn, true);
 	calculate_net_pay(doc, dt, dn);
+	refresh_many(['amount','gross_pay', 'rounded_total', 'net_pay', 'loan_repayment']);
 };
 
 // Calculate earning total
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.json b/erpnext/hr/doctype/salary_slip/salary_slip.json
index e558d73..7d5dbe9 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.json
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.json
@@ -1266,7 +1266,35 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "Gross Pay + Arrear Amount +Encashment Amount - Total Deduction", 
+   "fieldname": "loan_repayment", 
+   "fieldtype": "Currency", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Loan Repayment", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "description": "Gross Pay + Arrear Amount + Encashment Amount - Total Deduction - Loan Repayment", 
    "fieldname": "net_pay", 
    "fieldtype": "Currency", 
    "hidden": 0, 
@@ -1362,7 +1390,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-14 08:26:31.400930", 
+ "modified": "2017-01-09 12:37:03.802501", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Slip", 
@@ -1413,7 +1441,7 @@
   }, 
   {
    "amend": 0, 
-   "apply_user_permissions": 0, 
+   "apply_user_permissions": 1, 
    "cancel": 0, 
    "create": 0, 
    "delete": 0, 
@@ -1430,6 +1458,7 @@
    "set_user_permissions": 0, 
    "share": 0, 
    "submit": 0, 
+   "user_permission_doctypes": "[\"Employee\"]", 
    "write": 0
   }
  ], 
@@ -1440,5 +1469,6 @@
  "sort_order": "DESC", 
  "timeline_field": "employee", 
  "title_field": "employee_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_slip/salary_slip.py b/erpnext/hr/doctype/salary_slip/salary_slip.py
index eeec6e8..9d57a5d 100644
--- a/erpnext/hr/doctype/salary_slip/salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/salary_slip.py
@@ -89,8 +89,8 @@
 		    frappe.throw(_("Name error: {0}".format(err)))
 		except SyntaxError as err:
 		    frappe.throw(_("Syntax error in formula or condition: {0}".format(err)))
-		except:
-		    frappe.throw(_("Error in formula or condition"))
+		except Exception, e:
+		    frappe.throw(_("Error in formula or condition: {0}".format(e)))
 		    raise
 
 	def get_data_for_eval(self):
@@ -99,7 +99,7 @@
 
 		for d in self._salary_structure_doc.employees:
 			if d.employee == self.employee:
-				data.base, data.variable = d.base, d.variable
+				data.update(frappe.get_doc("Salary Structure Employee", {"employee": self.employee}).as_dict())
 
 		data.update(frappe.get_doc("Employee", self.employee).as_dict())
 		data.update(self.as_dict())
@@ -108,7 +108,6 @@
 		salary_components = frappe.get_all("Salary Component", fields=["salary_component_abbr"])
 		for salary_component in salary_components:
 			data[salary_component.salary_component_abbr] = 0
-
 		return data
 
 
@@ -284,6 +283,7 @@
 				where t2.name = t1.leave_type
 				and t2.is_lwp = 1
 				and t1.docstatus = 1
+				and t1.status = 'Approved'
 				and t1.employee = %(employee)s
 				and CASE WHEN t2.include_holiday != 1 THEN %(dt)s not in ('{0}') and %(dt)s between from_date and to_date
 				WHEN t2.include_holiday THEN %(dt)s between from_date and to_date
@@ -329,11 +329,21 @@
 
 		self.sum_components('earnings', 'gross_pay')
 		self.sum_components('deductions', 'total_deduction')
+		
+		self.set_loan_repayment()
 
-		self.net_pay = flt(self.gross_pay) - flt(self.total_deduction)
+		self.net_pay = flt(self.gross_pay) - (flt(self.total_deduction) + flt(self.loan_repayment))
 		self.rounded_total = rounded(self.net_pay,
 			self.precision("net_pay") if disable_rounded_total else 0)
 
+	def set_loan_repayment(self):
+		employee_loan = frappe.db.sql("""select sum(total_payment) as loan_repayment from `tabRepayment Schedule`
+						where payment_date between %s and %s and parent in (select name from `tabEmployee Loan`
+						where employee = %s and repay_from_salary = 1 and docstatus = 1)""",
+						(self.start_date, self.end_date, self.employee), as_dict=True)
+		if employee_loan:
+			self.loan_repayment = employee_loan[0].loan_repayment
+
 	def on_submit(self):
 		if self.net_pay < 0:
 			frappe.throw(_("Net Pay cannot be less than 0"))
diff --git a/erpnext/hr/doctype/salary_slip/test_salary_slip.py b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
index 3eec686..9999f1e 100644
--- a/erpnext/hr/doctype/salary_slip/test_salary_slip.py
+++ b/erpnext/hr/doctype/salary_slip/test_salary_slip.py
@@ -7,7 +7,7 @@
 import erpnext
 import calendar
 from erpnext.accounts.utils import get_fiscal_year
-from frappe.utils import getdate, nowdate, add_days
+from frappe.utils import getdate, nowdate, add_days, flt
 from erpnext.hr.doctype.salary_structure.salary_structure import make_salary_slip
 from erpnext.hr.doctype.process_payroll.test_process_payroll import get_salary_component_account
 from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
@@ -24,7 +24,6 @@
 
 		frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Slip Test Holiday List")
 
-
 	def tearDown(self):
 		frappe.db.set_value("HR Settings", None, "include_holidays_in_total_working_days", 0)
 		frappe.set_user("Administrator")
@@ -40,12 +39,12 @@
 
 		self.assertEquals(ss.total_working_days, no_of_days[0])
 		self.assertEquals(ss.payment_days, no_of_days[0])
-		self.assertEquals(ss.earnings[0].amount, 5000)
+		self.assertEquals(ss.earnings[0].amount, 25000)
 		self.assertEquals(ss.earnings[1].amount, 3000)
 		self.assertEquals(ss.deductions[0].amount, 5000)
-		self.assertEquals(ss.deductions[1].amount, 2500)
-		self.assertEquals(ss.gross_pay, 10500)
-		self.assertEquals(ss.net_pay, 3000)
+		self.assertEquals(ss.deductions[1].amount, 5000)
+		self.assertEquals(ss.gross_pay, 40500)
+		self.assertEquals(ss.net_pay, 29918)
 
 	def test_salary_slip_with_holidays_excluded(self):
 		no_of_days = self.get_no_of_days()
@@ -58,13 +57,13 @@
 
 		self.assertEquals(ss.total_working_days, no_of_days[0] - no_of_days[1])
 		self.assertEquals(ss.payment_days, no_of_days[0] - no_of_days[1])
-		self.assertEquals(ss.earnings[0].amount, 5000)
-		self.assertEquals(ss.earnings[0].default_amount, 5000)
+		self.assertEquals(ss.earnings[0].amount, 25000)
+		self.assertEquals(ss.earnings[0].default_amount, 25000)
 		self.assertEquals(ss.earnings[1].amount, 3000)
 		self.assertEquals(ss.deductions[0].amount, 5000)
-		self.assertEquals(ss.deductions[1].amount, 2500)
-		self.assertEquals(ss.gross_pay, 10500)
-		self.assertEquals(ss.net_pay, 3000)
+		self.assertEquals(ss.deductions[1].amount, 5000)
+		self.assertEquals(ss.gross_pay, 40500)
+		self.assertEquals(ss.net_pay, 29918)
 
 	def test_payment_days(self):
 		no_of_days = self.get_no_of_days()
@@ -130,11 +129,25 @@
 		ss = frappe.get_doc("Salary Slip",
 			self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
 		ss.submit()
+
 		email_queue = frappe.db.sql("""select name from `tabEmail Queue`""")
 		self.assertTrue(email_queue)
 
+	def test_loan_repayment_salary_slip(self):
+		from erpnext.hr.doctype.employee_loan.test_employee_loan import create_loan_type, create_employee_loan
+		employee = self.make_employee("test_employee@salary.com")
+		create_loan_type("Car Loan", 500000, 6.4)
+		employee_loan = create_employee_loan(employee, "Car Loan", 11000, "Repay Over Number of Periods", 20)
+		employee_loan.repay_from_salary = 1
+		employee_loan.submit()
+		ss = frappe.get_doc("Salary Slip",
+			self.make_employee_salary_slip("test_employee@salary.com", "Monthly"))
+		ss.submit()
+		self.assertEquals(ss.loan_repayment, 582)
+		self.assertEquals(ss.net_pay, (flt(ss.gross_pay) - (flt(ss.total_deduction) + flt(ss.loan_repayment))))
+
 	def test_payroll_frequency(self):
-		fiscal_year = get_fiscal_year(nowdate())[0]
+		fiscal_year = get_fiscal_year(nowdate(), company="_Test Company")[0]
 		month = "%02d" % getdate(nowdate()).month
 		m = get_month_details(fiscal_year, month)
 
@@ -167,7 +180,7 @@
 			}).insert()
 
 		if not frappe.db.get_value("Employee", {"user_id": user}):
-			frappe.get_doc({
+			employee = frappe.get_doc({
 				"doctype": "Employee",
 				"naming_series": "EMP-",
 				"employee_name": user,
@@ -183,9 +196,12 @@
 				"status": "Active",
 				"employment_type": "Intern"
 			}).insert()
+			return employee.name
+		else:
+			return frappe.get_value("Employee", {"employee_name":user}, "name")
 
 	def make_holiday_list(self):
-		fiscal_year = get_fiscal_year(nowdate())
+		fiscal_year = get_fiscal_year(nowdate(), company="_Test Company")
 		if not frappe.db.get_value("Holiday List", "Salary Slip Test Holiday List"):
 			holiday_list = frappe.get_doc({
 				"doctype": "Holiday List",
@@ -278,7 +294,7 @@
 
 def get_employee_details(employee):
 	return [{"employee": employee,
-			"base": 25000,
+			"base": 50000,
 			"variable": 5000
 			}
 		]
@@ -289,14 +305,14 @@
 					"salary_component": 'Basic Salary',
 					"abbr":'BS',
 					"condition": 'base > 10000',
-					"formula": 'base*.2',
+					"formula": 'base*.5',
 					"idx": 1
 				},
 				{
 					"salary_component": 'Basic Salary',
 					"abbr":'BS',
 					"condition": 'base < 10000',
-					"formula": 'base*.1',
+					"formula": 'base*.2',
 					"idx": 2
 				},
 				{
@@ -320,13 +336,13 @@
 					"salary_component": 'Professional Tax',
 					"abbr":'PT',
 					"condition": 'base > 10000',
-					"formula": 'base*.2',
+					"formula": 'base*.1',
 					"idx": 1
 				},
 				{
 					"salary_component": 'TDS',
 					"abbr":'T',
-					"formula": 'base*.5',
+					"formula": 'base*.1',
 					"idx": 2
 				},
 				{
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.json b/erpnext/hr/doctype/salary_structure/salary_structure.json
index 8db8e93..b34cff1 100644
--- a/erpnext/hr/doctype/salary_structure/salary_structure.json
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.json
@@ -1,7 +1,7 @@
 {
  "allow_copy": 0, 
  "allow_import": 1, 
- "allow_rename": 0, 
+ "allow_rename": 1, 
  "autoname": "Prompt", 
  "beta": 0, 
  "creation": "2013-03-07 18:50:29", 
@@ -21,7 +21,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -48,7 +47,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -76,7 +74,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Letter Head", 
@@ -107,7 +104,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Payroll Frequency", 
@@ -136,7 +132,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -164,7 +159,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Is Active", 
@@ -195,7 +189,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Default", 
@@ -224,7 +217,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "From Date", 
@@ -253,7 +245,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "To Date", 
@@ -282,7 +273,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -310,7 +300,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Employees", 
@@ -339,7 +328,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -368,7 +356,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Salary Slip Based on Timesheet", 
@@ -396,7 +383,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -425,7 +411,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Salary Component", 
@@ -455,7 +440,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Hour Rate", 
@@ -485,7 +469,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -515,7 +498,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Earning", 
@@ -546,7 +528,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Earnings", 
@@ -576,7 +557,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Deduction", 
@@ -606,7 +586,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Deductions", 
@@ -637,7 +616,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -664,7 +642,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -691,7 +668,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Earning", 
@@ -721,7 +697,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Deduction", 
@@ -751,7 +726,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Net Pay", 
@@ -779,7 +753,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Account", 
@@ -807,7 +780,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Mode of Payment", 
@@ -836,7 +808,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -863,7 +834,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Payment Account", 
@@ -894,7 +864,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-14 02:02:10.848614", 
+ "modified": "2017-02-02 01:23:49.179497", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Structure", 
@@ -910,7 +880,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -928,10 +897,9 @@
    "create": 1, 
    "delete": 1, 
    "email": 1, 
-   "export": 0, 
+   "export": 1, 
    "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
+   "import": 1, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -950,5 +918,6 @@
  "sort_order": "DESC", 
  "timeline_field": "", 
  "title_field": "", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/salary_structure/salary_structure.py b/erpnext/hr/doctype/salary_structure/salary_structure.py
index 13622c3..d60cd35 100644
--- a/erpnext/hr/doctype/salary_structure/salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/salary_structure.py
@@ -4,8 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 
-from frappe.utils import cstr, flt, getdate, cint
-from frappe.model.naming import make_autoname
+from frappe.utils import flt, cint
 from frappe import _
 from frappe.model.mapper import get_mapped_doc
 from frappe.model.document import Document
@@ -15,7 +14,6 @@
 	
 	def validate(self):
 		self.validate_amount()
-		self.validate_joining_date()
 		for e in self.get('employees'):
 			set_employee_name(e)
 
@@ -29,19 +27,19 @@
 	def validate_amount(self):
 		if flt(self.net_pay) < 0 and self.salary_slip_based_on_timesheet:
 			frappe.throw(_("Net pay cannot be negative"))
-
-	def validate_joining_date(self):
-		for e in self.get('employees'):
-			joining_date = getdate(frappe.db.get_value("Employee", e.employee, "date_of_joining"))
-			if getdate(self.from_date) < joining_date:
-				frappe.throw(_("From Date in Salary Structure cannot be lesser than Employee Joining Date."))
 				
 
 @frappe.whitelist()
 def make_salary_slip(source_name, target_doc = None, employee = None, as_print = False, print_format = None):
 	def postprocess(source, target):
 		if employee:
+			employee_details = frappe.db.get_value("Employee", employee, 
+							["employee_name", "branch", "designation", "department"], as_dict=1)
 			target.employee = employee
+			target.employee_name = employee_details.employee_name
+			target.branch = employee_details.branch
+			target.designation = employee_details.designation
+			target.department = employee_details.department
 		target.run_method('process_salary_structure')
 
 	doc = get_mapped_doc("Salary Structure", source_name, {
diff --git a/erpnext/hr/doctype/salary_structure/test_salary_structure.py b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
index fe88d9a..36e50d3 100644
--- a/erpnext/hr/doctype/salary_structure/test_salary_structure.py
+++ b/erpnext/hr/doctype/salary_structure/test_salary_structure.py
@@ -19,8 +19,8 @@
 		frappe.db.set_value("Company", erpnext.get_default_company(), "default_holiday_list", "Salary Structure Test Holiday List")
 		make_earning_salary_component(["Basic Salary", "Allowance", "HRA"])
 		make_deduction_salary_component(["Professional Tax", "TDS"])
-		self.make_employee("test_employee@salary.com")
-		self.make_employee("test_employee_2@salary.com")
+		make_employee("test_employee@salary.com")
+		make_employee("test_employee_2@salary.com")
 		
 	def make_holiday_list(self):
 		if not frappe.db.get_value("Holiday List", "Salary Structure Test Holiday List"):
@@ -33,37 +33,6 @@
 			}).insert()	
 			holiday_list.get_weekly_off_dates()
 			holiday_list.save()
-	
-	def make_employee(self, user):
-		if not frappe.db.get_value("User", user):
-			frappe.get_doc({
-				"doctype": "User",
-				"email": user,
-				"first_name": user,
-				"new_password": "password",
-				"user_roles": [{"doctype": "UserRole", "role": "Employee"}]
-			}).insert()
-			
-
-		if not frappe.db.get_value("Employee", {"user_id": user}):
-			emp = frappe.get_doc({
-				"doctype": "Employee",
-				"naming_series": "EMP-",
-				"employee_name": user,
-				"company": erpnext.get_default_company(),
-				"user_id": user,
-				"date_of_birth": "1990-05-08",
-				"date_of_joining": "2013-01-01",
-				"relieving_date": "",
-				"department": frappe.get_all("Department", fields="name")[0].name,
-				"gender": "Female",
-				"company_email": user,
-				"status": "Active",
-				"employment_type": "Intern"
-			}).insert()
-			return emp.name
-		else:
-			return frappe.get_value("Employee", {"employee_name":user}, "name")
 		
 	def test_amount_totals(self):
 		sal_slip = frappe.get_value("Salary Slip", {"employee_name":"test_employee@salary.com"})
@@ -76,6 +45,36 @@
 			self.assertEquals(sal_slip.get("total_deduction"), 7500)
 			self.assertEquals(sal_slip.get("net_pay"), 7500)
 			
+def make_employee(user):
+	if not frappe.db.get_value("User", user):
+		frappe.get_doc({
+			"doctype": "User",
+			"email": user,
+			"first_name": user,
+			"new_password": "password",
+			"user_roles": [{"doctype": "UserRole", "role": "Employee"}]
+		}).insert()
+		
+
+	if not frappe.db.get_value("Employee", {"user_id": user}):
+		emp = frappe.get_doc({
+			"doctype": "Employee",
+			"naming_series": "EMP-",
+			"employee_name": user,
+			"company": erpnext.get_default_company(),
+			"user_id": user,
+			"date_of_birth": "1990-05-08",
+			"date_of_joining": "2013-01-01",
+			"relieving_date": "",
+			"department": frappe.get_all("Department", fields="name")[0].name,
+			"gender": "Female",
+			"company_email": user,
+			"status": "Active",
+			"employment_type": "Intern"
+		}).insert()
+		return emp.name
+	else:
+		return frappe.get_value("Employee", {"employee_name":user}, "name")			
 		
 def make_salary_slip_from_salary_structure(employee):
 	sal_struct = make_salary_structure('Salary Structure Sample')
diff --git a/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json b/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
index aae33e3..f5ac764 100644
--- a/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
+++ b/erpnext/hr/doctype/salary_structure_employee/salary_structure_employee.json
@@ -15,13 +15,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Employee", 
    "length": 0, 
    "no_copy": 0, 
@@ -31,6 +32,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -41,21 +43,24 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "employee_name", 
-   "fieldtype": "Data", 
+   "fieldtype": "Read Only", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Employee Name", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "employee.employee_name", 
    "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, 
@@ -66,13 +71,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "base", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Base", 
    "length": 0, 
    "no_copy": 0, 
@@ -81,6 +87,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -91,13 +98,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "variable", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Variable", 
    "length": 0, 
    "no_copy": 0, 
@@ -106,6 +114,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, 
@@ -123,7 +132,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-08-11 12:18:14.526977", 
+ "modified": "2017-02-02 02:06:33.809285", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Salary Structure Employee", 
@@ -135,5 +144,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/hr/doctype/upload_attendance/upload_attendance.py b/erpnext/hr/doctype/upload_attendance/upload_attendance.py
index 49eb8cf..fc1a8ae 100644
--- a/erpnext/hr/doctype/upload_attendance/upload_attendance.py
+++ b/erpnext/hr/doctype/upload_attendance/upload_attendance.py
@@ -36,7 +36,7 @@
 	w.writerow(["Please do not change the template headings"])
 	w.writerow(["Status should be one of these values: " + status])
 	w.writerow(["If you are overwriting existing attendance records, 'ID' column mandatory"])
-	w.writerow(["ID", "Employee", "Employee Name", "Date", "Status",
+	w.writerow(["ID", "Employee", "Employee Name", "Date", "Status", "Leave Type",
 		 "Company", "Naming Series"])
 	return w
 
@@ -53,7 +53,8 @@
 			row = [
 				existing_attendance and existing_attendance.name or "",
 				employee.name, employee.employee_name, date,
-				existing_attendance and existing_attendance.status or "", employee.company,
+				existing_attendance and existing_attendance.status or "",
+				existing_attendance and existing_attendance.leave_type or "", employee.company,
 				existing_attendance and existing_attendance.naming_series or get_naming_series(),
 			]
 			w.writerow(row)
@@ -71,13 +72,13 @@
 	return employees
 
 def get_existing_attendance_records(args):
-	attendance = frappe.db.sql("""select name, att_date, employee, status, naming_series
-		from `tabAttendance` where att_date between %s and %s and docstatus < 2""",
+	attendance = frappe.db.sql("""select name, attendance_date, employee, status, leave_type, naming_series
+		from `tabAttendance` where attendance_date between %s and %s and docstatus < 2""",
 		(args["from_date"], args["to_date"]), as_dict=1)
 
 	existing_attendance = {}
 	for att in attendance:
-		existing_attendance[tuple([att.att_date, att.employee])] = att
+		existing_attendance[tuple([att.attendance_date, att.employee])] = att
 
 	return existing_attendance
 
@@ -103,7 +104,7 @@
 		return {"messages": msg, "error": msg}
 	columns = [scrub(f) for f in rows[4]]
 	columns[0] = "name"
-	columns[3] = "att_date"
+	columns[3] = "attendance_date"
 	ret = []
 	error = False
 
diff --git a/erpnext/fleet_management/doctype/vehicle/__init__.py b/erpnext/hr/doctype/vehicle/__init__.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle/__init__.py
rename to erpnext/hr/doctype/vehicle/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle/test_vehicle.py b/erpnext/hr/doctype/vehicle/test_vehicle.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle/test_vehicle.py
rename to erpnext/hr/doctype/vehicle/test_vehicle.py
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.js b/erpnext/hr/doctype/vehicle/vehicle.js
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle/vehicle.js
rename to erpnext/hr/doctype/vehicle/vehicle.js
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.json b/erpnext/hr/doctype/vehicle/vehicle.json
similarity index 99%
rename from erpnext/fleet_management/doctype/vehicle/vehicle.json
rename to erpnext/hr/doctype/vehicle/vehicle.json
index edad8a2..39735e6 100644
--- a/erpnext/fleet_management/doctype/vehicle/vehicle.json
+++ b/erpnext/hr/doctype/vehicle/vehicle.json
@@ -779,9 +779,9 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 06:00:22.056662", 
+ "modified": "2017-01-09 11:10:11.678834", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
+ "module": "HR", 
  "name": "Vehicle", 
  "name_case": "", 
  "owner": "Administrator", 
@@ -815,5 +815,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle.py b/erpnext/hr/doctype/vehicle/vehicle.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle/vehicle.py
rename to erpnext/hr/doctype/vehicle/vehicle.py
diff --git a/erpnext/fleet_management/doctype/vehicle/vehicle_dashboard.py b/erpnext/hr/doctype/vehicle/vehicle_dashboard.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle/vehicle_dashboard.py
rename to erpnext/hr/doctype/vehicle/vehicle_dashboard.py
diff --git a/erpnext/fleet_management/doctype/vehicle_log/__init__.py b/erpnext/hr/doctype/vehicle_log/__init__.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_log/__init__.py
rename to erpnext/hr/doctype/vehicle_log/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_log/test_vehicle_log.py b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_log/test_vehicle_log.py
rename to erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.js b/erpnext/hr/doctype/vehicle_log/vehicle_log.js
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_log/vehicle_log.js
rename to erpnext/hr/doctype/vehicle_log/vehicle_log.js
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
similarity index 99%
rename from erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
rename to erpnext/hr/doctype/vehicle_log/vehicle_log.json
index 26a4a01..a2cfa27 100644
--- a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.json
+++ b/erpnext/hr/doctype/vehicle_log/vehicle_log.json
@@ -640,9 +640,9 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:24:55.310831", 
+ "modified": "2017-01-09 11:10:21.208266", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
+ "module": "HR", 
  "name": "Vehicle Log", 
  "name_case": "", 
  "owner": "Administrator", 
@@ -675,5 +675,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_log/vehicle_log.py b/erpnext/hr/doctype/vehicle_log/vehicle_log.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_log/vehicle_log.py
rename to erpnext/hr/doctype/vehicle_log/vehicle_log.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/__init__.py b/erpnext/hr/doctype/vehicle_service/__init__.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_service/__init__.py
rename to erpnext/hr/doctype/vehicle_service/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
similarity index 89%
rename from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
rename to erpnext/hr/doctype/vehicle_service/vehicle_service.json
index 6b80efc..635a0b6 100644
--- a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/hr/doctype/vehicle_service/vehicle_service.json
@@ -22,6 +22,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Service Item", 
    "length": 0, 
    "no_copy": 0, 
@@ -31,6 +32,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, 
@@ -49,6 +51,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Type", 
    "length": 0, 
    "no_copy": 0, 
@@ -58,6 +61,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, 
@@ -76,6 +80,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Frequency", 
    "length": 0, 
    "no_copy": 0, 
@@ -85,6 +90,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, 
@@ -103,6 +109,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Expense", 
    "length": 0, 
    "no_copy": 0, 
@@ -111,6 +118,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, 
@@ -128,9 +136,9 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-20 07:29:50.852748", 
+ "modified": "2017-01-09 11:10:29.476907", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
+ "module": "HR", 
  "name": "Vehicle Service", 
  "name_case": "", 
  "owner": "Administrator", 
@@ -140,5 +148,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.py b/erpnext/hr/doctype/vehicle_service/vehicle_service.py
similarity index 100%
rename from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.py
rename to erpnext/hr/doctype/vehicle_service/vehicle_service.py
diff --git a/erpnext/fleet_management/__init__.py b/erpnext/hr/page/team_updates/__init__.py
similarity index 100%
rename from erpnext/fleet_management/__init__.py
rename to erpnext/hr/page/team_updates/__init__.py
diff --git a/erpnext/hr/page/team_updates/team_update_row.html b/erpnext/hr/page/team_updates/team_update_row.html
new file mode 100644
index 0000000..e3adcb8
--- /dev/null
+++ b/erpnext/hr/page/team_updates/team_update_row.html
@@ -0,0 +1,15 @@
+<div class="row activity-row" data-creation="{%= creation.split(" ")[0] + " 00:00:00" %}">
+	<div class="col-xs-3 text-right activity-date"><span class="{%= date_class %}">
+		{%= date_sep || "" %}</span></div>
+	<div class="col-xs-9 activity-message"
+		title="{%= by %} / {%= dateutil.str_to_user(creation) %}">
+		<div class="row">
+			<div class="col-xs-2 col-sm-1">
+				{{ avatar }}
+			</div>
+			<div class="col-xs-10 col-sm-11 small content">
+				{{ content }}
+			</div>
+		</div>
+	</div>
+</div>
diff --git a/erpnext/hr/page/team_updates/team_updates.css b/erpnext/hr/page/team_updates/team_updates.css
new file mode 100644
index 0000000..d37e782
--- /dev/null
+++ b/erpnext/hr/page/team_updates/team_updates.css
@@ -0,0 +1,57 @@
+.date-indicator {
+    background:none;
+    font-size:12px;
+    vertical-align:middle;
+    font-weight:bold;
+    color:#6c7680;
+}
+.date-indicator::after {
+    margin:0 -4px 0 12px;
+    content:'';
+    display:inline-block;
+    height:8px;
+    width:8px;
+    border-radius:8px;
+	background: #d1d8dd;
+}
+
+.date-indicator.blue {
+	color: #5e64ff;
+}
+
+.date-indicator.blue::after {
+	background: #5e64ff;
+}
+
+.activity-row {
+}
+
+.activity-message {
+	border-left: 1px solid #d1d8dd;
+}
+
+.activity-message .row {
+	padding: 15px;
+	margin-right: 0px;
+	border-bottom: 1px solid #d1d8dd;
+}
+
+.activity-row:last-child .activity-message .row {
+	border-bottom: none;
+}
+
+.activity-row .content {
+	padding-left: 0px;
+	padding-right: 30px;
+}
+
+.activity-date {
+	padding: 15px;
+	padding-right: 0px;
+	z-index: 1;
+}
+
+.for-more {
+	border-top: 1px solid #d1d8dd;
+	padding: 10px;
+}
diff --git a/erpnext/hr/page/team_updates/team_updates.js b/erpnext/hr/page/team_updates/team_updates.js
new file mode 100644
index 0000000..e701b5f
--- /dev/null
+++ b/erpnext/hr/page/team_updates/team_updates.js
@@ -0,0 +1,79 @@
+frappe.pages['team-updates'].on_page_load = function(wrapper) {
+	var page = frappe.ui.make_app_page({
+		parent: wrapper,
+		title: __('Team Updates'),
+		single_column: true
+	});
+
+	frappe.team_updates.make(page);
+	frappe.team_updates.run();
+
+	if(frappe.model.can_read('Daily Work Summary Settings')) {
+		page.add_menu_item(__('Daily Work Summary Settings'), function() {
+			frappe.set_route('Form', 'Daily Work Summary Settings');
+		});
+	}
+}
+
+frappe.team_updates = {
+	start: 0,
+	make: function(page) {
+		var me = frappe.team_updates;
+		me.page = page;
+		me.body = $('<div></div>').appendTo(me.page.main);
+		me.more = $('<div class="for-more"><button class="btn btn-sm btn-default btn-more">'
+			+ __("More") + '</button></div>').appendTo(me.page.main)
+			.find('.btn-more').on('click', function() {
+				me.start += 40;
+				me.run();
+			});
+	},
+	run: function() {
+		var me = frappe.team_updates;
+		frappe.call({
+			method: 'erpnext.hr.page.team_updates.team_updates.get_data',
+			args: {
+				start: me.start
+			},
+			callback: function(r) {
+				if(r.message) {
+					r.message.forEach(function(d) {
+						me.add_row(d);
+					});
+				} else {
+					frappe.show_alert({message:__('No more updates'), indicator:'darkgrey'});
+					me.more.parent().addClass('hidden');
+				}
+			}
+		});
+	},
+	add_row: function(data) {
+		var me = frappe.team_updates;
+
+		data.by = frappe.user.full_name(data.sender);
+		data.avatar = frappe.avatar(data.sender);
+		data.when = comment_when(data.creation);
+
+		var date = dateutil.str_to_obj(data.creation);
+		var last = me.last_feed_date;
+
+		if((last && dateutil.obj_to_str(last) != dateutil.obj_to_str(date)) || (!last)) {
+			var diff = dateutil.get_day_diff(dateutil.get_today(), dateutil.obj_to_str(date));
+			if(diff < 1) {
+				pdate = 'Today';
+			} else if(diff < 2) {
+				pdate = 'Yesterday';
+			} else {
+				pdate = dateutil.global_date_format(date);
+			}
+			data.date_sep = pdate;
+			data.date_class = pdate=='Today' ? "date-indicator blue" : "date-indicator";
+		} else {
+			data.date_sep = null;
+			data.date_class = "";
+		}
+		me.last_feed_date = date;
+
+		$(frappe.render_template('team_update_row', data)).appendTo(me.body)
+	}
+}
\ No newline at end of file
diff --git a/erpnext/hr/page/team_updates/team_updates.json b/erpnext/hr/page/team_updates/team_updates.json
new file mode 100644
index 0000000..167c67f
--- /dev/null
+++ b/erpnext/hr/page/team_updates/team_updates.json
@@ -0,0 +1,25 @@
+{
+ "content": null, 
+ "creation": "2017-01-31 11:02:31.614045", 
+ "docstatus": 0, 
+ "doctype": "Page", 
+ "idx": 0, 
+ "modified": "2017-01-31 11:25:01.983200", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "team-updates", 
+ "owner": "Administrator", 
+ "page_name": "team-updates", 
+ "roles": [
+  {
+   "role": "Employee"
+  }, 
+  {
+   "role": "System Manager"
+  }
+ ], 
+ "script": null, 
+ "standard": "Yes", 
+ "style": null, 
+ "title": "Team Updates"
+}
\ No newline at end of file
diff --git a/erpnext/hr/page/team_updates/team_updates.py b/erpnext/hr/page/team_updates/team_updates.py
new file mode 100644
index 0000000..5b90f6f
--- /dev/null
+++ b/erpnext/hr/page/team_updates/team_updates.py
@@ -0,0 +1,21 @@
+from __future__ import unicode_literals
+
+import frappe
+from email_reply_parser import EmailReplyParser
+from markdown2 import markdown
+
+@frappe.whitelist()
+def get_data(start=0):
+	#frappe.only_for('Employee', 'System Manager')
+	data = frappe.get_all('Communication',
+		fields=('content', 'text_content', 'sender', 'creation'),
+		filters=dict(reference_doctype='Daily Work Summary'),
+		order_by='creation desc', limit=40, start=start)
+
+	for d in data:
+		d.sender_name = frappe.db.get_value("Employee", {"user_id": d.sender},
+			"employee_name") or d.sender
+		if d.text_content:
+			d.content = markdown(EmailReplyParser.parse_reply(d.text_content))
+
+	return data
\ No newline at end of file
diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
index 7f1c442..8105e1a 100644
--- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
+++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
@@ -30,28 +30,31 @@
 	return columns
 	
 def get_data(filters, leave_types):
-
+	user = frappe.session.user
 	allocation_records_based_on_to_date = get_leave_allocation_records(filters.to_date)
 
 	active_employees = frappe.get_all("Employee", 
 		filters = { "status": "Active", "company": filters.company}, 
-		fields = ["name", "employee_name", "department"])
+		fields = ["name", "employee_name", "department", "user_id"])
 	
 	data = []
 	for employee in active_employees:
-		row = [employee.name, employee.employee_name, employee.department]
+		leave_approvers = [l.leave_approver for l in frappe.db.sql("""select leave_approver from `tabEmployee Leave Approver` where parent = %s""",
+							(employee.name),as_dict=True)]
+		if (len(leave_approvers) and user in leave_approvers) or (user in ["Administrator", employee.user_id]) or ("HR Manager" in frappe.get_roles(user)):
+			row = [employee.name, employee.employee_name, employee.department]
 
-		for leave_type in leave_types:	
-			# leaves taken
-			leaves_taken = get_approved_leaves_for_period(employee.name, leave_type, 
-				filters.from_date, filters.to_date)
+			for leave_type in leave_types:
+				# leaves taken
+				leaves_taken = get_approved_leaves_for_period(employee.name, leave_type,
+					filters.from_date, filters.to_date)
 	
-			# closing balance
-			closing = get_leave_balance_on(employee.name, leave_type, filters.to_date, 
-				allocation_records_based_on_to_date.get(employee.name, frappe._dict()))
+				# closing balance
+				closing = get_leave_balance_on(employee.name, leave_type, filters.to_date,
+					allocation_records_based_on_to_date.get(employee.name, frappe._dict()))
 
-			row += [leaves_taken, closing]
+				row += [leaves_taken, closing]
 			
-		data.append(row)
+			data.append(row)
 		
 	return data
\ No newline at end of file
diff --git a/erpnext/hr/report/employees_working_on_a_holiday/employees_working_on_a_holiday.py b/erpnext/hr/report/employees_working_on_a_holiday/employees_working_on_a_holiday.py
index a0b78a6..60bb02c 100644
--- a/erpnext/hr/report/employees_working_on_a_holiday/employees_working_on_a_holiday.py
+++ b/erpnext/hr/report/employees_working_on_a_holiday/employees_working_on_a_holiday.py
@@ -41,13 +41,13 @@
 		holiday_names[holiday.holiday_date] = holiday.description
 
 	if(holidays_list):
-		cond = " att_date in %(holidays_list)s"
+		cond = " attendance_date in %(holidays_list)s"
 
 		if filters.holiday_list:
 			cond += """ and (employee in (select employee from tabEmployee where holiday_list = %(holidays)s))"""
 
 		employee_list = frappe.db.sql("""select
-				employee, employee_name, att_date, status
+				employee, employee_name, attendance_date, status
 			from tabAttendance
 			where %s"""% cond.format(', '.join(["%s"] * len(holidays_list))),
 				{'holidays_list':holidays_list,
diff --git a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
index 525f9ab..05d3df5 100644
--- a/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
+++ b/erpnext/hr/report/monthly_attendance_sheet/monthly_attendance_sheet.py
@@ -24,21 +24,23 @@
 		row = [emp, emp_det.employee_name, emp_det.branch, emp_det.department, emp_det.designation,
 			emp_det.company]
 
-		total_p = total_a = 0.0
+		total_p = total_a = total_l = 0.0
 		for day in range(filters["total_days_in_month"]):
 			status = att_map.get(emp).get(day + 1, "None")
-			status_map = {"Present": "P", "Absent": "A", "Half Day": "H", "None": ""}
+			status_map = {"Present": "P", "Absent": "A", "Half Day": "H", "On Leave": "L", "None": ""}
 			row.append(status_map[status])
 
 			if status == "Present":
 				total_p += 1
 			elif status == "Absent":
 				total_a += 1
+			elif status == "On Leave":
+				total_l += 1	
 			elif status == "Half Day":
 				total_p += 0.5
 				total_a += 0.5
 
-		row += [total_p, total_a]
+		row += [total_p, total_l, total_a]
 		data.append(row)
 
 	return columns, data
@@ -53,12 +55,12 @@
 	for day in range(filters["total_days_in_month"]):
 		columns.append(cstr(day+1) +"::20")
 
-	columns += [_("Total Present") + ":Float:80", _("Total Absent") + ":Float:80"]
+	columns += [_("Total Present") + ":Float:80", _("Total Leaves") + ":Float:80",  _("Total Absent") + ":Float:80"]
 	return columns
 
 def get_attendance_list(conditions, filters):
-	attendance_list = frappe.db.sql("""select employee, day(att_date) as day_of_month,
-		status from tabAttendance where docstatus = 1 %s order by employee, att_date""" %
+	attendance_list = frappe.db.sql("""select employee, day(attendance_date) as day_of_month,
+		status from tabAttendance where docstatus = 1 %s order by employee, attendance_date""" %
 		conditions, filters, as_dict=1)
 
 	att_map = {}
@@ -77,7 +79,7 @@
 
 	filters["total_days_in_month"] = monthrange(cint(filters.year), filters.month)[1]
 
-	conditions = " and month(att_date) = %(month)s and year(att_date) = %(year)s"
+	conditions = " and month(attendance_date) = %(month)s and year(attendance_date) = %(year)s"
 
 	if filters.get("company"): conditions += " and company = %(company)s"
 	if filters.get("employee"): conditions += " and employee = %(employee)s"
@@ -95,7 +97,7 @@
 
 @frappe.whitelist()
 def get_attendance_years():
-	year_list = frappe.db.sql_list("""select distinct YEAR(att_date) from tabAttendance ORDER BY YEAR(att_date) DESC""")
+	year_list = frappe.db.sql_list("""select distinct YEAR(attendance_date) from tabAttendance ORDER BY YEAR(attendance_date) DESC""")
 	if not year_list:
 		year_list = [getdate().year]
 
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js
deleted file mode 100644
index a879b39..0000000
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.js
+++ /dev/null
@@ -1,34 +0,0 @@
-// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-// License: GNU General Public License v3. See license.txt
-
-frappe.query_reports["Monthly Salary Register"] = {
-	"filters": [
-		{
-			"fieldname":"from_date",
-			"label": __("From"),
-			"fieldtype": "Date",
-			"default": frappe.datetime.add_months(frappe.datetime.get_today(), -1),
-			"reqd": 1
-		},
-		{
-			"fieldname":"to_date",
-			"label": __("To"),
-			"fieldtype": "Date",
-			"default": frappe.datetime.get_today(),
-			"reqd": 1
-		},
-		{
-			"fieldname":"employee",
-			"label": __("Employee"),
-			"fieldtype": "Link",
-			"options": "Employee"
-		},
-		{
-			"fieldname":"company",
-			"label": __("Company"),
-			"fieldtype": "Link",
-			"options": "Company",
-			"default": frappe.defaults.get_user_default("Company")
-		}
-	]
-}
\ No newline at end of file
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.json b/erpnext/hr/report/monthly_salary_register/monthly_salary_register.json
deleted file mode 100644
index d32e71e..0000000
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.json
+++ /dev/null
@@ -1,17 +0,0 @@
-{
- "add_total_row": 1, 
- "apply_user_permissions": 1, 
- "creation": "2013-05-07 18:09:42", 
- "docstatus": 0, 
- "doctype": "Report", 
- "idx": 1, 
- "is_standard": "Yes", 
- "modified": "2014-06-03 07:18:17.187018", 
- "modified_by": "Administrator", 
- "module": "HR", 
- "name": "Monthly Salary Register", 
- "owner": "Administrator", 
- "ref_doctype": "Salary Slip", 
- "report_name": "Monthly Salary Register", 
- "report_type": "Script Report"
-}
\ No newline at end of file
diff --git a/erpnext/hr/report/monthly_salary_register/__init__.py b/erpnext/hr/report/salary_register/__init__.py
similarity index 100%
rename from erpnext/hr/report/monthly_salary_register/__init__.py
rename to erpnext/hr/report/salary_register/__init__.py
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.html b/erpnext/hr/report/salary_register/salary_register.html
similarity index 89%
rename from erpnext/hr/report/monthly_salary_register/monthly_salary_register.html
rename to erpnext/hr/report/salary_register/salary_register.html
index c77e4e5..2a9cd3e 100644
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.html
+++ b/erpnext/hr/report/salary_register/salary_register.html
@@ -2,8 +2,7 @@
 	{%= frappe.boot.letter_heads[filters.letter_head || frappe.defaults.get_default("letter_head")] %}
 </div>
 <h2 class="text-center">{%= __(report.report_name) %}</h2>
-<h5 class="text-center">Fiscal Year: {%= filters.fiscal_year %}</h5>
-<h5 class="text-center">Month: {%= filters.month %}</h5>
+<h5 class="text-center">From {%= filters.date_range[0] %} to {%= filters.date_range[1] %}</h5>
 <hr>
 <table class="table table-bordered">
 	<thead>
@@ -36,4 +35,3 @@
 	</tbody>
 </table>
 <p class="text-right text-muted">Printed On {%= dateutil.str_to_user(dateutil.get_datetime_as_string()) %}</p>
-
diff --git a/erpnext/hr/report/salary_register/salary_register.js b/erpnext/hr/report/salary_register/salary_register.js
new file mode 100644
index 0000000..8b0faf5
--- /dev/null
+++ b/erpnext/hr/report/salary_register/salary_register.js
@@ -0,0 +1,27 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.query_reports["Salary Register"] = {
+	"filters": [
+		{
+			"fieldname":"date_range",
+			"label": __("Date Range"),
+			"fieldtype": "DateRange",
+			"default": [frappe.datetime.add_months(get_today(),-1), frappe.datetime.get_today()],
+			"reqd": 1
+		},
+		{
+			"fieldname":"employee",
+			"label": __("Employee"),
+			"fieldtype": "Link",
+			"options": "Employee"
+		},
+		{
+			"fieldname":"company",
+			"label": __("Company"),
+			"fieldtype": "Link",
+			"options": "Company",
+			"default": frappe.defaults.get_user_default("Company")
+		}
+	]
+}
diff --git a/erpnext/hr/report/salary_register/salary_register.json b/erpnext/hr/report/salary_register/salary_register.json
new file mode 100644
index 0000000..1166915
--- /dev/null
+++ b/erpnext/hr/report/salary_register/salary_register.json
@@ -0,0 +1,18 @@
+{
+ "add_total_row": 1, 
+ "apply_user_permissions": 1, 
+ "creation": "2017-01-10 17:36:58.153863", 
+ "disabled": 0, 
+ "docstatus": 0, 
+ "doctype": "Report", 
+ "idx": 0, 
+ "is_standard": "Yes", 
+ "modified": "2017-01-10 17:38:00.832224", 
+ "modified_by": "Administrator", 
+ "module": "HR", 
+ "name": "Salary Register", 
+ "owner": "Administrator", 
+ "ref_doctype": "Salary Slip", 
+ "report_name": "Salary Register", 
+ "report_type": "Script Report"
+}
\ No newline at end of file
diff --git a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py b/erpnext/hr/report/salary_register/salary_register.py
similarity index 92%
rename from erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
rename to erpnext/hr/report/salary_register/salary_register.py
index e8d0a0b..1e36b92 100644
--- a/erpnext/hr/report/monthly_salary_register/monthly_salary_register.py
+++ b/erpnext/hr/report/salary_register/salary_register.py
@@ -3,12 +3,11 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import flt, cstr
-from frappe import msgprint, _
+from frappe.utils import flt
+from frappe import _
 
 def execute(filters=None):
 	if not filters: filters = {}
-
 	salary_slips = get_salary_slips(filters)
 	columns, earning_types, ded_types = get_columns(salary_slips)
 	ss_earning_map = get_ss_earning_map(salary_slips)
@@ -58,6 +57,7 @@
 	return columns, salary_components[_("Earning")], salary_components[_("Deduction")]
 
 def get_salary_slips(filters):
+	filters.update({"from_date": filters.get("date_range")[0], "to_date":filters.get("date_range")[1]})
 	conditions, filters = get_conditions(filters)
 	salary_slips = frappe.db.sql("""select * from `tabSalary Slip` where docstatus = 1 %s
 		order by employee""" % conditions, filters, as_dict=1)
@@ -65,13 +65,12 @@
 	if not salary_slips:
 		frappe.throw(_("No salary slip found between {0} and {1}").format(
 			filters.get("from_date"), filters.get("to_date")))
-
 	return salary_slips
 
 def get_conditions(filters):
 	conditions = ""
-	if filters.get("from_date"): conditions += " and start_date >= %(from_date)s"
-	if filters.get("to_date"): conditions += " and end_date <= %(to_date)s"
+	if filters.get("date_range"): conditions += " and start_date >= %(from_date)s"
+	if filters.get("date_range"): conditions += " and end_date <= %(to_date)s"
 	if filters.get("company"): conditions += " and company = %(company)s"
 	if filters.get("employee"): conditions += " and employee = %(employee)s"
 
diff --git a/erpnext/fleet_management/report/vehicle_expenses/__init__.py b/erpnext/hr/report/vehicle_expenses/__init__.py
similarity index 100%
rename from erpnext/fleet_management/report/vehicle_expenses/__init__.py
rename to erpnext/hr/report/vehicle_expenses/__init__.py
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.js b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.js
similarity index 100%
rename from erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.js
rename to erpnext/hr/report/vehicle_expenses/vehicle_expenses.js
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.json
similarity index 83%
rename from erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json
rename to erpnext/hr/report/vehicle_expenses/vehicle_expenses.json
index 380c873..f151c67 100644
--- a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.json
+++ b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.json
@@ -7,9 +7,9 @@
  "doctype": "Report", 
  "idx": 0, 
  "is_standard": "Yes", 
- "modified": "2016-09-18 08:54:12.080753", 
+ "modified": "2017-01-09 11:18:31.959124", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
+ "module": "HR", 
  "name": "Vehicle Expenses", 
  "owner": "Administrator", 
  "ref_doctype": "Vehicle", 
diff --git a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py
similarity index 98%
rename from erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py
rename to erpnext/hr/report/vehicle_expenses/vehicle_expenses.py
index 717a94f..a03b7f3 100644
--- a/erpnext/fleet_management/report/vehicle_expenses/vehicle_expenses.py
+++ b/erpnext/hr/report/vehicle_expenses/vehicle_expenses.py
@@ -15,7 +15,7 @@
 	columns=get_columns()
 	data=get_log_data(filters)
 	chart=get_chart_data(data,period_list)
-	return columns,data,None,chart
+	return columns, data, None, chart
 	
 def get_columns():
 	columns = [_("License") + ":Link/Vehicle:100", _("Make") + ":data:50",
diff --git a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
index bcf1ae6..9639e7f 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
+++ b/erpnext/maintenance/doctype/maintenance_schedule/maintenance_schedule.js
@@ -3,18 +3,28 @@
 
 frappe.provide("erpnext.maintenance");
 
-frappe.ui.form.on_change("Maintenance Schedule", "customer", function(frm) {
-	erpnext.utils.get_party_details(frm) });
-frappe.ui.form.on_change("Maintenance Schedule", "customer_address", function(){
-	erpnext.utils.get_address_display(cur_frm, 'customer_address', 'address_display');
-});
-frappe.ui.form.on_change("Maintenance Schedule", "contact_person", function(){
-  erpnext.utils.get_contact_details(cur_frm);	
-});
+frappe.ui.form.on('Maintenance Schedule', {
+	setup: function(frm) {
+		frm.set_query('contact_person', erpnext.queries.contact_query);
+		frm.set_query('customer_address', erpnext.queries.address_query);
+	},
+	customer: function(frm) {
+		erpnext.utils.get_party_details(frm)
+	},
+	customer_address: function(frm) {
+		erpnext.utils.get_address_display(frm, 'customer_address', 'address_display');
+	},
+	contact_person: function(frm) {
+		erpnext.utils.get_contact_details(frm);
+	}
+
+})
 
 // TODO commonify this code
 erpnext.maintenance.MaintenanceSchedule = frappe.ui.form.Controller.extend({
 	refresh: function() {
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
+
 		var me = this;
 
 		if (this.frm.doc.docstatus === 0) {
@@ -94,18 +104,6 @@
 
 }
 
-cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters:{ 'customer': doc.customer }
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters:{ 'customer': doc.customer }
-	}
-}
-
 cur_frm.cscript.generate_schedule = function(doc, cdt, cdn) {
 	if (!doc.__islocal) {
 		return $c('runserverobj', args={'method':'generate_schedule', 'docs':doc},
diff --git a/erpnext/maintenance/doctype/maintenance_schedule_item/maintenance_schedule_item.json b/erpnext/maintenance/doctype/maintenance_schedule_item/maintenance_schedule_item.json
index e9192f7..1e68fab 100644
--- a/erpnext/maintenance/doctype/maintenance_schedule_item/maintenance_schedule_item.json
+++ b/erpnext/maintenance/doctype/maintenance_schedule_item/maintenance_schedule_item.json
@@ -10,11 +10,13 @@
  "doctype": "DocType", 
  "document_type": "Document", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "item_code", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -32,6 +34,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 1, 
@@ -42,6 +45,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "item_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -58,6 +62,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, 
@@ -68,8 +73,9 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "description", 
-   "fieldtype": "Data", 
+   "fieldtype": "Text Editor", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -85,6 +91,7 @@
    "print_hide_if_no_value": 0, 
    "print_width": "300px", 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -96,6 +103,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "schedule_details", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -110,6 +118,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, 
@@ -120,6 +129,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "start_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -136,6 +146,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 1, 
@@ -146,6 +157,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "end_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
@@ -162,6 +174,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 1, 
@@ -172,6 +185,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "periodicity", 
    "fieldtype": "Select", 
    "hidden": 0, 
@@ -189,6 +203,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, 
@@ -199,6 +214,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "no_of_visits", 
    "fieldtype": "Int", 
    "hidden": 0, 
@@ -215,6 +231,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -225,6 +242,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "sales_person", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -242,6 +260,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -252,6 +271,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "reference", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -266,6 +286,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, 
@@ -276,6 +297,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "serial_no", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -292,6 +314,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, 
@@ -302,6 +325,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "sales_order", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -320,6 +344,7 @@
    "print_hide_if_no_value": 0, 
    "print_width": "150px", 
    "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 1, 
@@ -338,7 +363,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-11 03:28:02.260189", 
+ "modified": "2017-01-11 12:02:38.449129", 
  "modified_by": "Administrator", 
  "module": "Maintenance", 
  "name": "Maintenance Schedule Item", 
diff --git a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
index 38c20da..62cdf86 100644
--- a/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
+++ b/erpnext/maintenance/doctype/maintenance_visit/maintenance_visit.js
@@ -2,20 +2,31 @@
 // License: GNU General Public License v3. See license.txt
 
 frappe.provide("erpnext.maintenance");
+me.frm.set_query('contact_person', erpnext.queries.contact_query);
 
 
-frappe.ui.form.on_change("Maintenance Visit", "customer", function(frm) {
-	erpnext.utils.get_party_details(frm) });
-frappe.ui.form.on_change("Maintenance Visit", "customer_address", function(frm){
-	erpnext.utils.get_address_display(frm, 'customer_address', 'address_display')
-});
-frappe.ui.form.on_change("Maintenance Visit", "contact_person", function(frm){
-	erpnext.utils.get_contact_details(frm)
-});
+frappe.ui.form.on('Maintenance Visit', {
+	setup: function(frm) {
+		frm.set_query('contact_person', erpnext.queries.contact_query);
+		frm.set_query('customer_address', erpnext.queries.address_query);
+	},
+	customer: function(frm) {
+		erpnext.utils.get_party_details(frm)
+	},
+	customer_address: function(frm) {
+		erpnext.utils.get_address_display(frm, 'customer_address', 'address_display');
+	},
+	contact_person: function(frm) {
+		erpnext.utils.get_contact_details(frm);
+	}
+
+})
 
 // TODO commonify this code
 erpnext.maintenance.MaintenanceVisit = frappe.ui.form.Controller.extend({
 	refresh: function() {
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
+
 		if (this.frm.doc.docstatus===0) {
 			cur_frm.add_custom_button(__('Maintenance Schedule'),
 				function() {
@@ -69,18 +80,6 @@
 	cur_frm.add_fetch('item_code', 'description', 'description');
 }
 
-cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
-	return{
-    	filters:{'customer': doc.customer}
-  	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-  	return{
-    	filters:{'customer': doc.customer}
-  	}
-}
-
 cur_frm.fields_dict.customer.get_query = function(doc,cdt,cdn) {
 	return {query: "erpnext.controllers.queries.customer_query" }
 }
diff --git a/erpnext/manufacturing/doctype/bom/bom.json b/erpnext/manufacturing/doctype/bom/bom.json
index c2c9b64..51018d3 100644
--- a/erpnext/manufacturing/doctype/bom/bom.json
+++ b/erpnext/manufacturing/doctype/bom/bom.json
@@ -21,7 +21,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Item", 
@@ -51,7 +50,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Item Name", 
@@ -81,7 +79,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Quantity", 
@@ -110,7 +107,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -137,7 +133,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Is Active", 
@@ -167,7 +162,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Is Default", 
@@ -197,7 +191,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "With Operations", 
@@ -224,7 +217,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Rate Of Materials Based On", 
@@ -253,7 +245,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Price List", 
@@ -281,7 +272,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -309,7 +299,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Currency", 
@@ -338,7 +327,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -365,7 +353,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Conversion Rate", 
@@ -395,7 +382,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Operations", 
@@ -423,7 +409,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Operations", 
@@ -453,7 +438,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Materials", 
@@ -481,7 +465,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Items", 
@@ -511,7 +494,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Scrap", 
@@ -539,7 +521,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Scrap Items", 
@@ -568,7 +549,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Costing", 
@@ -596,7 +576,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Operating Cost", 
@@ -624,7 +603,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Raw Material Cost", 
@@ -652,7 +630,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Scrap Material Cost", 
@@ -681,7 +658,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -707,7 +683,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Operating Cost (Company Currency)", 
@@ -736,7 +711,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Raw Material Cost(Company Currency)", 
@@ -765,7 +739,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Scrap Material Cost(Company Currency)", 
@@ -794,7 +767,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -821,7 +793,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Total Cost", 
@@ -849,7 +820,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -876,7 +846,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Cost(Company Currency)", 
@@ -905,7 +874,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -932,7 +900,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Project", 
@@ -962,7 +929,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -991,7 +957,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -1019,7 +984,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1045,7 +1009,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Item UOM", 
@@ -1073,7 +1036,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1100,7 +1062,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Item Description", 
@@ -1127,7 +1088,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -1154,7 +1114,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Image", 
@@ -1182,7 +1141,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Image View", 
@@ -1212,7 +1170,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Materials Required (Exploded)", 
@@ -1239,7 +1196,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Exploded_items", 
@@ -1271,8 +1227,8 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-21 17:06:49.349654", 
- "modified_by": "rohit@erpnext.com", 
+ "modified": "2017-02-01 14:27:17.949390", 
+ "modified_by": "Administrator", 
  "module": "Manufacturing", 
  "name": "BOM", 
  "owner": "Administrator", 
@@ -1287,7 +1243,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1308,7 +1263,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1329,7 +1283,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1347,5 +1300,6 @@
  "search_fields": "item", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/bom/bom.py b/erpnext/manufacturing/doctype/bom/bom.py
index f4fed6e..8102057 100644
--- a/erpnext/manufacturing/doctype/bom/bom.py
+++ b/erpnext/manufacturing/doctype/bom/bom.py
@@ -500,10 +500,15 @@
 @frappe.whitelist()
 def get_children():
 	if frappe.form_dict.parent:
-		return frappe.db.sql("""select item_code,
-			bom_no as value, qty,
-			if(ifnull(bom_no, "")!="", 1, 0) as expandable
-			from `tabBOM Item`
-			where parent=%s
-			order by idx
+		return frappe.db.sql("""select
+			bom_item.item_code,
+			bom_item.bom_no as value,
+			bom_item.qty,
+			if(ifnull(bom_item.bom_no, "")!="", 1, 0) as expandable,
+			item.image,
+			item.description
+			from `tabBOM Item` bom_item, tabItem item
+			where bom_item.parent=%s
+			and bom_item.item_code = item.name
+			order by bom_item.idx
 			""", frappe.form_dict.parent, as_dict=True)
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/bom/bom_item_preview.html b/erpnext/manufacturing/doctype/bom/bom_item_preview.html
new file mode 100644
index 0000000..9db19a0
--- /dev/null
+++ b/erpnext/manufacturing/doctype/bom/bom_item_preview.html
@@ -0,0 +1,21 @@
+<div style="padding: 15px;">
+	{% if data.image %}
+	<img class="responsive" src={{ data.image }}>
+	<hr style="margin: 15px -15px;">
+	{% endif %}
+	<h4>
+		{{ __("Description") }}
+	</h4>
+	<div style="padding-top: 10px;">
+		{{ data.description }}
+	</div>
+	<hr style="margin: 15px -15px;">
+	<p>
+		{% if data.value %}
+		<a style="margin-right: 7px; margin-bottom: 7px" class="btn btn-default btn-xs" href="#Form/BOM/{{ data.value }}">
+			{{ __("Open BOM {0}", [data.value.bold()]) }}</a>
+		{% endif %}
+		<a class="btn btn-default btn-xs" href="#Form/Item/{{ data.item_code }}">
+			{{ __("Open Item {0}", [data.item_code.bold()]) }}</a>
+	</p>
+</div>
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/bom/bom_tree.js b/erpnext/manufacturing/doctype/bom/bom_tree.js
index f6a205f..09fe037 100644
--- a/erpnext/manufacturing/doctype/bom/bom_tree.js
+++ b/erpnext/manufacturing/doctype/bom/bom_tree.js
@@ -20,14 +20,14 @@
 		}
 	},
 	toolbar: [
-		{toggle_btn: true},
+		{ toggle_btn: true },
 		{
 			label:__("Edit"),
 			condition: function(node) {
 				return node.expandable;
 			},
 			click: function(node) {
-				
+
 				frappe.set_route("Form", "BOM", node.data.value);
 			}
 		}
@@ -40,5 +40,6 @@
 			},
 			condition: 'frappe.boot.user.can_create.indexOf("BOM") !== -1'
 		}
-	]
+	],
+	view_template: 'bom_item_preview'
 }
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.json b/erpnext/manufacturing/doctype/production_order/production_order.json
index dd8bb5b..04a3a93 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.json
+++ b/erpnext/manufacturing/doctype/production_order/production_order.json
@@ -374,7 +374,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "description": "Warehouse for reserving items", 
+   "description": "", 
    "fieldname": "source_warehouse", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -383,7 +383,7 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Source Warehouse", 
+   "label": "Source Warehouse (for reserving Items)", 
    "length": 0, 
    "no_copy": 0, 
    "options": "Warehouse", 
@@ -1244,7 +1244,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:13:02.064821", 
+ "modified": "2017-01-12 05:32:52.523006", 
  "modified_by": "Administrator", 
  "module": "Manufacturing", 
  "name": "Production Order", 
@@ -1298,5 +1298,6 @@
  "read_only_onload": 0, 
  "sort_order": "ASC", 
  "title_field": "production_item", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index aa69342..f690878 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -304,9 +304,9 @@
 
 	def get_operations_data(self, data):
 		return {
-			'from_time': data.planned_start_time,
+			'from_time': get_datetime(data.planned_start_time),
 			'hours': data.time_in_mins / 60.0,
-			'to_time': data.planned_end_time,
+			'to_time': get_datetime(data.planned_end_time),
 			'project': self.project,
 			'operation': data.operation,
 			'operation_id': data.name,
diff --git a/erpnext/manufacturing/doctype/production_order/production_order_calendar.js b/erpnext/manufacturing/doctype/production_order/production_order_calendar.js
index 2832494..47cac28 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order_calendar.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order_calendar.js
@@ -7,7 +7,10 @@
 		"end": "planned_end_date",
 		"id": "name",
 		"title": "name",
-		"allDay": "allDay"
+		"allDay": "allDay",
+		"progress": function(data) {
+			return flt(data.produced_qty) / data.qty * 100;
+		}
 	},
 	gantt: true,
 	get_css_class: function(data) {
diff --git a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
index aaa0e95..4692118 100644
--- a/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
+++ b/erpnext/manufacturing/doctype/production_planning_tool/production_planning_tool.py
@@ -249,7 +249,7 @@
 				"wip_warehouse"			: "",
 				"fg_warehouse"			: d.warehouse,
 				"status"				: "Draft",
-				"project"			: frappe.db.get_value("Sales Order", d.sales_order, "project")
+				"project"				: frappe.db.get_value("Sales Order", d.sales_order, "project")
 			}
 
 			""" Club similar BOM and item for processing in case of Sales Orders """
@@ -344,28 +344,56 @@
 		self.make_items_dict(item_list)
 
 	def get_subitems(self,bom_wise_item_details, bom, parent_qty, include_sublevel, only_raw, supply_subs,non_stock_item=0):
-		for d in frappe.db.sql("""SELECT bom_item.item_code, default_material_request_type,
-			ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
-			item.is_sub_contracted_item as is_sub_contracted, item.default_bom as default_bom,
-			bom_item.description as description,  bom_item.stock_uom as stock_uom,  item.min_order_qty
-			as min_order_qty FROM `tabBOM Item` bom_item, `tabBOM` bom, tabItem item
-			where bom.name = bom_item.parent and bom.name = %(bom)s and bom_item.docstatus < 2
-			and bom_item.item_code = item.name
-			""" + ("and item.is_stock_item = 1","")[non_stock_item] + """
-			group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1):
-			if (d.default_material_request_type == "Purchase" and not (d.is_sub_contracted \
-				and only_raw and include_sublevel)) or (d.default_material_request_type == \
-				"Manufacture" and not only_raw):
+		items = frappe.db.sql("""
+			SELECT
+				bom_item.item_code,
+				default_material_request_type,
+				ifnull(%(parent_qty)s * sum(bom_item.qty/ifnull(bom.quantity, 1)), 0) as qty,
+				item.is_sub_contracted_item as is_sub_contracted,
+				item.default_bom as default_bom,
+				bom_item.description as description,
+				bom_item.stock_uom as stock_uom,
+				item.min_order_qty as min_order_qty
+			FROM
+				`tabBOM Item` bom_item,
+				`tabBOM` bom,
+				tabItem item
+			where
+				bom.name = bom_item.parent
+				and bom.name = %(bom)s
+				and bom_item.docstatus < 2
+				and bom_item.item_code = item.name
+			""" + ("and item.is_stock_item = 1", "")[non_stock_item] + """
+			group by bom_item.item_code""", {"bom": bom, "parent_qty": parent_qty}, as_dict=1)
+
+		for d in items:
+			if ((d.default_material_request_type == "Purchase"
+				and not (d.is_sub_contracted and only_raw and include_sublevel))
+				or (d.default_material_request_type == "Manufacture" and not only_raw)):
+
 				if d.item_code in bom_wise_item_details:
-					bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty\
-						+ d.qty
+					bom_wise_item_details[d.item_code].qty = bom_wise_item_details[d.item_code].qty + d.qty
 				else:
 					bom_wise_item_details[d.item_code] = d
+
 			if include_sublevel:
-				if (d.default_material_request_type == "Purchase" and d.is_sub_contracted \
-					and supply_subs) or (d.default_material_request_type == "Manufacture"):
-					self.get_subitems(bom_wise_item_details,d.default_bom, \
-						d.qty, include_sublevel, only_raw, supply_subs)
+				if ((d.default_material_request_type == "Purchase" and d.is_sub_contracted and supply_subs)
+					or (d.default_material_request_type == "Manufacture")):
+
+					my_qty = 0
+					projected_qty = self.get_item_projected_qty(d.item_code)
+
+					if self.create_material_requests_for_all_required_qty:
+						my_qty = d.qty
+					elif (bom_wise_item_details[d.item_code].qty - d.qty) < projected_qty:
+						my_qty = bom_wise_item_details[d.item_code].qty - projected_qty
+					else:
+						my_qty = d.qty
+
+					if my_qty > 0:
+						self.get_subitems(bom_wise_item_details,
+							d.default_bom, my_qty, include_sublevel, only_raw, supply_subs)
+
 		return bom_wise_item_details
 
 	def make_items_dict(self, item_list):
@@ -380,13 +408,18 @@
 			item_list.append([item, self.item_dict[item][0][1], self.item_dict[item][0][2], total_qty])
 			item_qty = frappe.db.sql("""select warehouse, indented_qty, ordered_qty, actual_qty
 				from `tabBin` where item_code = %s""", item, as_dict=1)
+
 			i_qty, o_qty, a_qty = 0, 0, 0
 			for w in item_qty:
-				i_qty, o_qty, a_qty = i_qty + flt(w.indented_qty), o_qty + flt(w.ordered_qty), a_qty + flt(w.actual_qty)
+				i_qty, o_qty, a_qty = i_qty + flt(w.indented_qty), o_qty + \
+					flt(w.ordered_qty), a_qty + flt(w.actual_qty)
+
 				item_list.append(['', '', '', '', w.warehouse, flt(w.indented_qty),
 					flt(w.ordered_qty), flt(w.actual_qty)])
 			if item_qty:
 				item_list.append(['', '', '', '', 'Total', i_qty, o_qty, a_qty])
+			else:
+				item_list.append(['', '', '', '', 'Total', 0, 0, 0])
 
 		return item_list
 
@@ -449,6 +482,18 @@
 
 		return items_to_be_requested
 
+	def get_item_projected_qty(self,item):
+		item_projected_qty = frappe.db.sql("""
+			select ifnull(sum(projected_qty),0) as qty
+			from `tabBin`
+			where item_code = %(item_code)s and warehouse=%(warehouse)s
+		""", {
+			"item_code": item,
+			"warehouse": self.purchase_request_for_warehouse
+		}, as_dict=1)
+
+		return item_projected_qty[0].qty
+
 	def get_projected_qty(self):
 		items = self.item_dict.keys()
 		item_projected_qty = frappe.db.sql("""select item_code, sum(projected_qty)
diff --git a/erpnext/modules.txt b/erpnext/modules.txt
index 4daf0eb..609a3fe 100644
--- a/erpnext/modules.txt
+++ b/erpnext/modules.txt
@@ -1,7 +1,6 @@
 Accounts
 CRM
 Buying
-Fleet Management
 Projects
 Selling
 Setup
diff --git a/erpnext/patches.txt b/erpnext/patches.txt
index ef1e2c1..e041a2b 100644
--- a/erpnext/patches.txt
+++ b/erpnext/patches.txt
@@ -360,3 +360,14 @@
 erpnext.patches.v7_1.repost_stock_for_deleted_bins_for_merging_items
 execute:frappe.delete_doc('Desktop Icon', {'module_name': 'Profit and Loss Statment'})
 erpnext.patches.v7_2.update_website_for_variant
+erpnext.patches.v7_2.update_assessment_modules
+erpnext.patches.v7_2.update_doctype_status
+erpnext.patches.v7_2.update_salary_slips
+erpnext.patches.v7_2.delete_fleet_management_module_def
+erpnext.patches.v7_2.contact_address_links
+erpnext.patches.v7_2.mark_students_active
+erpnext.patches.v7_2.set_null_value_to_fields
+erpnext.patches.v7_2.update_guardian_name_in_student_master
+erpnext.patches.v7_2.update_abbr_in_salary_slips
+erpnext.patches.v7_2.rename_evaluation_criteria
+erpnext.patches.v7_2.update_party_type
\ No newline at end of file
diff --git a/erpnext/patches/v7_0/set_portal_settings.py b/erpnext/patches/v7_0/set_portal_settings.py
index f7ee205..54a17dc 100644
--- a/erpnext/patches/v7_0/set_portal_settings.py
+++ b/erpnext/patches/v7_0/set_portal_settings.py
@@ -8,7 +8,7 @@
 
 def execute():
 	frappe.reload_doctype('Role')
-	for dt in ("assessment", "announcement", "course", "fees"):
+	for dt in ("assessment", "course", "fees"):
 		frappe.reload_doc("schools", "doctype", dt)
 
 	frappe.reload_doc('website', 'doctype', 'portal_menu_item')
diff --git a/erpnext/patches/v7_0/update_party_status.py b/erpnext/patches/v7_0/update_party_status.py
index 208b476..f3733db 100644
--- a/erpnext/patches/v7_0/update_party_status.py
+++ b/erpnext/patches/v7_0/update_party_status.py
@@ -1,8 +1,7 @@
 import frappe
-from erpnext.accounts.party_status import status_depends_on, default_status
-from frappe.desk.notifications import get_filters_for
 
 def execute():
+	return
 	for party_type in ('Customer', 'Supplier'):
 		frappe.reload_doctype(party_type)
 
diff --git a/erpnext/patches/v7_2/__init__.py b/erpnext/patches/v7_2/__init__.py
index e69de29..baffc48 100644
--- a/erpnext/patches/v7_2/__init__.py
+++ b/erpnext/patches/v7_2/__init__.py
@@ -0,0 +1 @@
+from __future__ import unicode_literals
diff --git a/erpnext/patches/v7_2/contact_address_links.py b/erpnext/patches/v7_2/contact_address_links.py
new file mode 100644
index 0000000..db724b0
--- /dev/null
+++ b/erpnext/patches/v7_2/contact_address_links.py
@@ -0,0 +1,31 @@
+import frappe
+from frappe.core.doctype.dynamic_link.dynamic_link import deduplicate_dynamic_links
+from frappe.utils import update_progress_bar
+
+def execute():
+	frappe.reload_doc('core', 'doctype', 'dynamic_link')
+	frappe.reload_doc('email', 'doctype', 'contact')
+	frappe.reload_doc('geo', 'doctype', 'address')
+	map_fields = (
+		('Customer', 'customer'),
+		('Supplier', 'supplier'),
+		('Load', 'lead'),
+		('Sales Partner', 'sales_partner')
+	)
+	for doctype in ('Contact', 'Address'):
+		if frappe.db.has_column(doctype, 'customer'):
+			items = frappe.get_all(doctype)
+			for i, doc in enumerate(items):
+				doc = frappe.get_doc(doctype, doc.name)
+				dirty = False
+				for field in map_fields:
+					if doc.get(field[1]):
+						doc.append('links', dict(link_doctype=field[0], link_name=doc.get(field[1])))
+						dirty = True
+
+					if dirty:
+						deduplicate_dynamic_links(doc)
+						doc.update_children()
+
+					update_progress_bar('Updating {0}'.format(doctype), i, len(items))
+			print
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/delete_fleet_management_module_def.py b/erpnext/patches/v7_2/delete_fleet_management_module_def.py
new file mode 100644
index 0000000..542ac11
--- /dev/null
+++ b/erpnext/patches/v7_2/delete_fleet_management_module_def.py
@@ -0,0 +1,10 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	if frappe.db.exists('Module Def', 'Fleet Management'):
+		frappe.db.sql("""delete from `tabModule Def`
+			where module_name = 'Fleet Management'""")
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/mark_students_active.py b/erpnext/patches/v7_2/mark_students_active.py
new file mode 100644
index 0000000..12057ed
--- /dev/null
+++ b/erpnext/patches/v7_2/mark_students_active.py
@@ -0,0 +1,7 @@
+import frappe
+
+def execute():
+    frappe.reload_doc('schools', 'doctype', 'student_batch_student')
+    frappe.reload_doc('schools', 'doctype', 'student_group_student')
+    frappe.db.sql("update `tabStudent Batch Student` set active=1")
+    frappe.db.sql("update `tabStudent Group Student` set active=1")
diff --git a/erpnext/patches/v7_2/rename_evaluation_criteria.py b/erpnext/patches/v7_2/rename_evaluation_criteria.py
new file mode 100644
index 0000000..a45604f
--- /dev/null
+++ b/erpnext/patches/v7_2/rename_evaluation_criteria.py
@@ -0,0 +1,29 @@
+import frappe
+from frappe.model.utils.rename_field import rename_field
+
+def execute():
+	frappe.rename_doc("DocType", "Evaluation Criteria", "Assessment Criteria", force=True)
+	frappe.reload_doc("schools", "doctype", "assessment_criteria")
+	if 'evaluation_criteria' in frappe.db.get_table_columns('Assessment Criteria'):
+		rename_field("Assessment Criteria", "evaluation_criteria", "assessment_criteria")
+
+	frappe.rename_doc("DocType", "Assessment Evaluation Criteria", "Assessment Plan Criteria", force=True)
+	frappe.reload_doc("schools", "doctype", "assessment_plan_criteria")
+	if 'evaluation_criteria' in frappe.db.get_table_columns('Assessment Plan'):
+		rename_field("Assessment Plan Criteria", "evaluation_criteria", "assessment_criteria")
+
+	frappe.reload_doc("schools", "doctype", "assessment_plan")
+	rename_field("Assessment Plan", "evaluation_criterias", "assessment_criteria")
+
+	frappe.reload_doc("schools", "doctype", "assessment_result_detail")
+	if 'evaluation_criteria' in frappe.db.get_table_columns('Assessment Result Detail'):
+		rename_field("Assessment Result Detail", "evaluation_criteria", "assessment_criteria")
+
+	frappe.rename_doc("DocType", "Course Evaluation Criteria", "Course Assessment Criteria", force=True)
+	frappe.reload_doc("schools", "doctype", "course_assessment_criteria")
+	if 'evaluation_criteria' in frappe.db.get_table_columns('Course Assessment Criteria'):
+		rename_field("Course Assessment Criteria", "evaluation_criteria", "assessment_criteria")
+
+	frappe.reload_doc("schools", "doctype", "course")
+	if 'evaluation_criteria' in frappe.db.get_table_columns('Course'):
+		rename_field("Course", "evaluation_criterias", "assessment_criteria")
diff --git a/erpnext/patches/v7_2/set_null_value_to_fields.py b/erpnext/patches/v7_2/set_null_value_to_fields.py
new file mode 100644
index 0000000..6388be4
--- /dev/null
+++ b/erpnext/patches/v7_2/set_null_value_to_fields.py
@@ -0,0 +1,11 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	fields = {"Cost Center": "project", "Project": "cost_center"}
+	for budget_against, field in fields.items():
+		frappe.db.sql(""" update `tabBudget` set {field} = null
+			where budget_against = %s """.format(field = field), budget_against)
diff --git a/erpnext/patches/v7_2/update_abbr_in_salary_slips.py b/erpnext/patches/v7_2/update_abbr_in_salary_slips.py
new file mode 100644
index 0000000..aa6965f
--- /dev/null
+++ b/erpnext/patches/v7_2/update_abbr_in_salary_slips.py
@@ -0,0 +1,13 @@
+import frappe
+
+def execute():
+	frappe.reload_doctype('Salary Slip')
+	if not frappe.db.has_column('Salary Detail', 'abbr'):
+		return
+
+	salary_details = frappe.db.sql("""select abbr, salary_component, name from `tabSalary Detail`
+				where abbr is null or abbr = ''""", as_dict=True)
+
+	for salary_detail in salary_details:
+		salary_component_abbr = frappe.get_value("Salary Component", salary_detail.salary_component, "salary_component_abbr")
+		frappe.db.sql("""update `tabSalary Detail` set abbr = %s where name = %s""",(salary_component_abbr, salary_detail.name))
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/update_assessment_modules.py b/erpnext/patches/v7_2/update_assessment_modules.py
new file mode 100644
index 0000000..9c00902
--- /dev/null
+++ b/erpnext/patches/v7_2/update_assessment_modules.py
@@ -0,0 +1,37 @@
+import frappe
+from frappe.model.utils.rename_field import rename_field
+
+def execute():
+	#Rename Grading Structure to Grading Scale
+	frappe.rename_doc("DocType", "Grading Structure", "Grading Scale", force=True)
+	frappe.rename_doc("DocType", "Grade Interval", "Grading Scale Interval", force=True)
+
+	frappe.reload_doc("schools", "doctype", "grading_scale_interval")
+	rename_field("Grading Scale Interval", "to_score", "threshold")
+
+	frappe.rename_doc("DocType", "Assessment", "Assessment Plan", force=True)
+
+	#Rename Assessment Results
+	frappe.reload_doc("schools", "doctype", "assessment_plan")
+	rename_field("Assessment Plan", "grading_structure", "grading_scale")
+
+	frappe.reload_doc("schools", "doctype", "assessment_result")
+	frappe.reload_doc("schools", "doctype", "assessment_result_detail")
+	frappe.reload_doc("schools", "doctype", "assessment_criteria")
+
+
+	for assessment in frappe.get_all("Assessment Plan", fields=["name", "grading_scale"], filters = [["docstatus", "!=", 2 ]]):
+		print assessment
+		for stud_result in frappe.db.sql("select * from `tabAssessment Result` where parent= %s", assessment.name, as_dict=True):
+			if stud_result.result:
+				assessment_result = frappe.new_doc("Assessment Result")
+				assessment_result.student = stud_result.student
+				assessment_result.student_name = stud_result.student_name
+				assessment_result.assessment_plan = assessment.name
+				assessment_result.grading_scale = assessment.grading_scale
+				assessment_result.total_score = stud_result.result
+				assessment_result.flags.ignore_validate = True
+				assessment_result.flags.ignore_mandatory = True
+				assessment_result.save()
+	
+	frappe.db.sql("""delete from `tabAssessment Result` where parent != '' or parent is not null""")
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/update_doctype_status.py b/erpnext/patches/v7_2/update_doctype_status.py
new file mode 100644
index 0000000..c66f3f2
--- /dev/null
+++ b/erpnext/patches/v7_2/update_doctype_status.py
@@ -0,0 +1,11 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	doctypes = ["Opportunity", "Quotation", "Sales Order", "Sales Invoice", "Purchase Invoice", "Purchase Order", "Delivery Note", "Purchase Receipt"]
+	for doctype in doctypes:
+		frappe.db.sql(""" update `tab{doctype}` set status = 'Draft'
+			where status = 'Cancelled' and docstatus = 0 """.format(doctype = doctype))
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/update_guardian_name_in_student_master.py b/erpnext/patches/v7_2/update_guardian_name_in_student_master.py
new file mode 100644
index 0000000..6ac4073
--- /dev/null
+++ b/erpnext/patches/v7_2/update_guardian_name_in_student_master.py
@@ -0,0 +1,9 @@
+import frappe
+from frappe.model.utils.rename_field import rename_field
+
+def execute():
+    frappe.reload_doc("schools", "doctype", "student_guardian")
+    student_guardians = frappe.get_all("Student Guardian", fields=["guardian"])
+    for student_guardian in student_guardians:
+        guardian_name = frappe.db.get_value("Guardian", student_guardian.guardian, "guardian_name")
+        frappe.db.sql("update `tabStudent Guardian` set guardian_name = %s where guardian= %s", (guardian_name, student_guardian.guardian))
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/update_party_type.py b/erpnext/patches/v7_2/update_party_type.py
new file mode 100644
index 0000000..147f5a3
--- /dev/null
+++ b/erpnext/patches/v7_2/update_party_type.py
@@ -0,0 +1,16 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	frappe.reload_doc('setup', 'doctype', 'party_type')
+	make_party_type()
+
+def make_party_type():
+	for party_type in ["Customer", "Supplier", "Employee"]:
+		if not frappe.db.get_value("Party Type", party_type):
+			doc = frappe.new_doc("Party Type")
+			doc.party_type = party_type
+			doc.save(ignore_permissions=True)
\ No newline at end of file
diff --git a/erpnext/patches/v7_2/update_salary_slips.py b/erpnext/patches/v7_2/update_salary_slips.py
new file mode 100644
index 0000000..b7a4050
--- /dev/null
+++ b/erpnext/patches/v7_2/update_salary_slips.py
@@ -0,0 +1,22 @@
+import frappe
+from erpnext.hr.doctype.process_payroll.process_payroll import get_month_details
+from frappe.utils import cint
+
+def execute():
+	frappe.reload_doctype('Salary Slip')
+	if not frappe.db.has_column('Salary Slip', 'fiscal_year'):
+		return
+
+	salary_slips = frappe.db.sql("""select month, name, fiscal_year from `tabSalary Slip`
+				where (month is not null and month != '') and
+				(start_date is null  or start_date = '') and
+				(end_date is null  or end_date = '') and docstatus != 2""", as_dict=True)
+
+	for salary_slip in salary_slips:
+		if not cint(salary_slip.month):
+			continue
+		get_start_end_date = get_month_details(salary_slip.fiscal_year, cint(salary_slip.month))
+		start_date = get_start_end_date['month_start_date']
+		end_date = get_start_end_date['month_end_date']
+		frappe.db.sql("""update `tabSalary Slip` set start_date = %s, end_date = %s where name = %s""",
+		(start_date, end_date, salary_slip.name))
\ No newline at end of file
diff --git a/erpnext/projects/doctype/project/project.json b/erpnext/projects/doctype/project/project.json
index 37ca968..38ebbcb 100644
--- a/erpnext/projects/doctype/project/project.json
+++ b/erpnext/projects/doctype/project/project.json
@@ -10,6 +10,7 @@
  "doctype": "DocType", 
  "document_type": "Setup", 
  "editable_grid": 0, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
@@ -24,7 +25,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Project Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -53,7 +53,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
    "label": "Status", 
    "length": 0, 
    "no_copy": 1, 
@@ -83,7 +82,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
    "label": "Project Type", 
    "length": 0, 
    "no_copy": 0, 
@@ -113,7 +111,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
    "label": "Is Active", 
    "length": 0, 
    "no_copy": 0, 
@@ -144,7 +141,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "% Complete Method", 
    "length": 0, 
    "no_copy": 0, 
@@ -173,7 +169,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -200,7 +195,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 1, 
    "label": "Priority", 
    "length": 0, 
    "no_copy": 0, 
@@ -230,7 +224,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Expected Start Date", 
    "length": 0, 
    "no_copy": 0, 
@@ -259,7 +252,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Expected End Date", 
    "length": 0, 
    "no_copy": 0, 
@@ -288,7 +280,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "% Completed", 
    "length": 0, 
    "no_copy": 1, 
@@ -315,7 +306,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Customer Details", 
    "length": 0, 
    "no_copy": 0, 
@@ -344,7 +334,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Customer", 
    "length": 0, 
    "no_copy": 0, 
@@ -374,7 +363,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -401,7 +389,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Sales Order", 
    "length": 0, 
    "no_copy": 0, 
@@ -430,7 +417,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Users", 
    "length": 0, 
    "no_copy": 0, 
@@ -459,7 +445,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Users", 
    "length": 0, 
    "no_copy": 0, 
@@ -488,7 +473,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Tasks", 
    "length": 0, 
    "no_copy": 0, 
@@ -517,7 +501,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Tasks", 
    "length": 0, 
    "no_copy": 0, 
@@ -546,7 +529,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Notes", 
    "length": 0, 
    "no_copy": 0, 
@@ -575,7 +557,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Notes", 
    "length": 0, 
    "no_copy": 0, 
@@ -604,7 +585,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Start and End Dates", 
    "length": 0, 
    "no_copy": 0, 
@@ -632,7 +612,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Actual Start Date", 
    "length": 0, 
    "no_copy": 0, 
@@ -660,7 +639,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Actual Time (in Hours)", 
    "length": 0, 
    "no_copy": 0, 
@@ -688,7 +666,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -715,7 +692,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Actual End Date", 
    "length": 0, 
    "no_copy": 0, 
@@ -744,7 +720,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Costing and Billing", 
    "length": 0, 
    "no_copy": 0, 
@@ -773,7 +748,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 0, 
    "label": "Estimated Cost", 
    "length": 0, 
    "no_copy": 0, 
@@ -804,7 +778,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Total Costing Amount (via Time Logs)", 
    "length": 0, 
    "no_copy": 0, 
@@ -833,7 +806,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Total Expense Claim (via Expense Claims)", 
    "length": 0, 
    "no_copy": 0, 
@@ -861,7 +833,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Company", 
    "length": 0, 
    "no_copy": 0, 
@@ -889,7 +860,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Default Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -917,7 +887,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -945,7 +914,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Total Billing Amount (via Time Logs)", 
    "length": 0, 
    "no_copy": 0, 
@@ -973,7 +941,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Total Purchase Cost (via Purchase Invoice)", 
    "length": 0, 
    "no_copy": 0, 
@@ -1001,7 +968,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Margin", 
    "length": 0, 
    "no_copy": 0, 
@@ -1030,7 +996,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Gross Margin", 
    "length": 0, 
    "no_copy": 0, 
@@ -1060,7 +1025,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -1087,7 +1051,6 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "in_standard_filter": 0, 
    "label": "Gross Margin %", 
    "length": 0, 
    "no_copy": 0, 
@@ -1117,7 +1080,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 4, 
- "modified": "2016-11-07 05:55:56.179455", 
+ "modified": "2017-01-10 16:33:54.691885", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Project", 
@@ -1164,6 +1127,27 @@
    "share": 0, 
    "submit": 0, 
    "write": 0
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Projects Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
   }
  ], 
  "quick_entry": 1, 
diff --git a/erpnext/projects/doctype/project/project.py b/erpnext/projects/doctype/project/project.py
index 276259b..b5ef4bf 100644
--- a/erpnext/projects/doctype/project/project.py
+++ b/erpnext/projects/doctype/project/project.py
@@ -8,6 +8,8 @@
 from frappe import _
 
 from frappe.model.document import Document
+from erpnext.controllers.queries import get_filters_cond
+from frappe.desk.reportview import get_match_cond
 
 class Project(Document):
 	def get_feed(self):
@@ -117,6 +119,8 @@
 
 	def update_percent_complete(self):
 		total = frappe.db.sql("""select count(name) from tabTask where project=%s""", self.name)[0][0]
+		if not total and self.percent_complete:
+			self.percent_complete = 0
 		if (self.percent_complete_method == "Task Completion" and total > 0) or (not self.percent_complete_method and total > 0):
 			completed = frappe.db.sql("""select count(name) from tabTask where
 				project=%s and status in ('Closed', 'Cancelled')""", self.name)[0][0]
@@ -228,12 +232,29 @@
 	}
 
 def get_users_for_project(doctype, txt, searchfield, start, page_len, filters):
-	return frappe.db.sql("""select name, concat_ws(' ', first_name, middle_name, last_name)
+	conditions = []
+	return frappe.db.sql("""select name, concat_ws(' ', first_name, middle_name, last_name) 
 		from `tabUser`
 		where enabled=1
-		and name not in ("Guest", "Administrator")
+			and name not in ("Guest", "Administrator") 
+			and ({key} like %(txt)s
+				or full_name like %(txt)s)
+			{fcond} {mcond}
 		order by
-		name asc""")
+			if(locate(%(_txt)s, name), locate(%(_txt)s, name), 99999),
+			if(locate(%(_txt)s, full_name), locate(%(_txt)s, full_name), 99999),
+			idx desc,
+			name, full_name
+		limit %(start)s, %(page_len)s""".format(**{
+			'key': searchfield,
+			'fcond': get_filters_cond(doctype, filters, conditions),
+			'mcond': get_match_cond(doctype)
+		}), {
+			'txt': "%%%s%%" % txt,
+			'_txt': txt.replace("%", ""),
+			'start': start,
+			'page_len': page_len
+		})
 
 @frappe.whitelist()
 def get_cost_center_name(project):
diff --git a/erpnext/projects/doctype/task/task.json b/erpnext/projects/doctype/task/task.json
index 9cd2aa8..811626d 100644
--- a/erpnext/projects/doctype/task/task.json
+++ b/erpnext/projects/doctype/task/task.json
@@ -1,7 +1,7 @@
 {
  "allow_copy": 0, 
  "allow_import": 1, 
- "allow_rename": 0, 
+ "allow_rename": 1, 
  "autoname": "TASK.#####", 
  "beta": 0, 
  "creation": "2013-01-29 19:25:50", 
@@ -21,7 +21,8 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Subject", 
@@ -51,6 +52,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Project", 
@@ -81,6 +83,7 @@
    "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, 
@@ -110,6 +113,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Status", 
@@ -139,7 +143,8 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Priority", 
@@ -170,6 +175,7 @@
    "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, 
@@ -197,6 +203,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Expected Start Date", 
@@ -228,6 +235,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Expected Time (in hours)", 
@@ -257,6 +265,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Weight", 
@@ -285,6 +294,7 @@
    "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, 
@@ -311,7 +321,8 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Expected End Date", 
@@ -341,6 +352,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "% Progress", 
@@ -369,6 +381,7 @@
    "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, 
@@ -397,6 +410,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Details", 
@@ -428,6 +442,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Depends On", 
@@ -456,6 +471,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "depends_on", 
@@ -485,6 +501,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "depends_on_tasks", 
@@ -514,6 +531,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -544,6 +562,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Actual Start Date (via Time Sheet)", 
@@ -575,6 +594,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Actual Time (in hours)", 
@@ -604,6 +624,7 @@
    "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, 
@@ -631,6 +652,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Actual End Date (via Time Sheet)", 
@@ -660,6 +682,7 @@
    "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, 
@@ -687,6 +710,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Costing Amount (via Time Sheet)", 
@@ -717,6 +741,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Expense Claim (via Expense Claim)", 
@@ -746,6 +771,7 @@
    "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, 
@@ -773,6 +799,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Billing Amount (via Time Sheet)", 
@@ -801,6 +828,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "", 
@@ -829,6 +857,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Review Date", 
@@ -859,6 +888,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Closing Date", 
@@ -888,6 +918,7 @@
    "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, 
@@ -914,6 +945,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -944,7 +976,7 @@
  "istable": 0, 
  "max_attachments": 5, 
  "menu_index": 0, 
- "modified": "2016-11-07 05:12:23.294476", 
+ "modified": "2017-02-14 22:46:02.027284", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Task", 
@@ -960,7 +992,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -976,8 +1007,10 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "search_fields": "subject", 
+ "show_name_in_global_search": 0, 
  "sort_order": "DESC", 
  "timeline_field": "project", 
  "title_field": "subject", 
+ "track_changes": 0, 
  "track_seen": 1
 }
\ No newline at end of file
diff --git a/erpnext/projects/doctype/task/task_calendar.js b/erpnext/projects/doctype/task/task_calendar.js
index f8fc3d3..d7468a5 100644
--- a/erpnext/projects/doctype/task/task_calendar.js
+++ b/erpnext/projects/doctype/task/task_calendar.js
@@ -7,7 +7,8 @@
 		"end": "exp_end_date",
 		"id": "name",
 		"title": "subject",
-		"allDay": "allDay"
+		"allDay": "allDay",
+		"progress": "progress"
 	},
 	gantt: true,
 	filters: [
diff --git a/erpnext/projects/doctype/timesheet/timesheet.json b/erpnext/projects/doctype/timesheet/timesheet.json
index 8762a23..c7eb076 100644
--- a/erpnext/projects/doctype/timesheet/timesheet.json
+++ b/erpnext/projects/doctype/timesheet/timesheet.json
@@ -23,6 +23,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Series", 
@@ -51,6 +52,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Company", 
@@ -82,6 +84,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Invoice", 
@@ -110,6 +113,7 @@
    "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, 
@@ -137,6 +141,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Salary Slip", 
@@ -167,6 +172,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Status", 
@@ -197,6 +203,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Employee Detail", 
@@ -227,6 +234,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Employee", 
@@ -257,6 +265,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Employee Name", 
@@ -286,6 +295,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "User", 
@@ -315,6 +325,7 @@
    "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, 
@@ -342,6 +353,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Start Date", 
@@ -370,6 +382,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "End Date", 
@@ -400,6 +413,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Production Detail", 
@@ -428,6 +442,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Production Order", 
@@ -457,6 +472,7 @@
    "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, 
@@ -483,6 +499,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Time Sheets", 
@@ -511,6 +528,7 @@
    "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, 
@@ -540,7 +558,8 @@
    "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": "Total Working Hours", 
    "length": 0, 
@@ -567,6 +586,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Billing Details", 
@@ -595,6 +615,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Billable Hours", 
@@ -623,7 +644,8 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
+   "in_global_search": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Total Billed Hours", 
    "length": 0, 
@@ -651,6 +673,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Costing Amount", 
@@ -679,6 +702,7 @@
    "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, 
@@ -709,6 +733,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Billable Amount", 
@@ -737,6 +762,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Total Billed Amount", 
@@ -765,6 +791,7 @@
    "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 Billed", 
@@ -793,6 +820,7 @@
    "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, 
@@ -820,6 +848,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Note", 
@@ -848,6 +877,7 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Amended From", 
@@ -877,7 +907,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-23 17:35:51.194690", 
+ "modified": "2017-02-17 13:08:08.109153", 
  "modified_by": "Administrator", 
  "module": "Projects", 
  "name": "Timesheet", 
@@ -893,7 +923,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -914,7 +943,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -935,7 +963,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -956,7 +983,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -977,7 +1003,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -998,7 +1023,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
@@ -1013,6 +1037,8 @@
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
+ "show_name_in_global_search": 0, 
  "sort_order": "ASC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/projects/doctype/timesheet/timesheet_calendar.js b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
index 0af1a6c..14f016a 100644
--- a/erpnext/projects/doctype/timesheet/timesheet_calendar.js
+++ b/erpnext/projects/doctype/timesheet/timesheet_calendar.js
@@ -4,7 +4,6 @@
 		"end": "end_date",
 		"name": "parent",
 		"id": "name",
-		"title": "name",
 		"allDay": "allDay",
 		"child_name": "name",
 		"title": "title"
diff --git a/erpnext/public/build.json b/erpnext/public/build.json
index 30b0900..c405681 100644
--- a/erpnext/public/build.json
+++ b/erpnext/public/build.json
@@ -28,7 +28,8 @@
         "public/js/templates/item_selector.html",
         "public/js/utils/item_selector.js",
         "public/js/help_links.js",
-        "public/js/schools/student_button.html"
+        "public/js/schools/student_button.html",
+        "public/js/schools/assessment_result_tool.html"
     ],
     "js/item-dashboard.min.js": [
         "stock/dashboard/item_dashboard.html",
diff --git a/erpnext/public/css/erpnext.css b/erpnext/public/css/erpnext.css
index ca3b4b5..cfe9f63 100644
--- a/erpnext/public/css/erpnext.css
+++ b/erpnext/public/css/erpnext.css
@@ -67,7 +67,6 @@
 .pos-toolbar,
 .pos-bill-toolbar {
   padding: 10px 0px;
-  border-bottom: 1px solid #d1d8dd;
   height: 51px;
 }
 .pos-item-toolbar .form-group {
@@ -79,6 +78,7 @@
   margin-right: -1px;
 }
 .pos-bill {
+  border-top: 1px solid #d1d8dd;
   margin-left: -15px;
   margin-right: -15px;
 }
@@ -171,6 +171,9 @@
 .payment-toolbar {
   padding-right: 30px;
 }
+.list-row-head.pos-invoice-list {
+  border-top: 1px solid #d1d8dd;
+}
 body[data-route="pos"] .modal-dialog {
   width: 750px;
 }
@@ -212,3 +215,25 @@
   margin: 15px;
   width: 130px;
 }
+.frappe-control[data-fieldname='result_html'] {
+  overflow: scroll;
+}
+.assessment-result-tool {
+  table-layout: fixed;
+}
+.assessment-result-tool input {
+  width: 100%;
+  border: 0;
+  outline: none;
+  text-align: right;
+}
+.assessment-result-tool th {
+  white-space: nowrap;
+  overflow: hidden;
+  text-overflow: ellipsis;
+}
+.assessment-result-tool .total-score,
+.assessment-result-tool .grade,
+.assessment-result-tool .score {
+  text-align: right;
+}
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 4b14d08..6f55a44 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -588,11 +588,13 @@
 	calculate_paid_amount: function(){
 		var me = this;
 		var paid_amount = base_paid_amount = 0.0;
-		$.each(this.frm.doc['payments'] || [], function(index, data){
-			data.base_amount = flt(data.amount * me.frm.doc.conversion_rate, precision("base_amount"));
-			paid_amount += data.amount;
-			base_paid_amount += data.base_amount;
-		})
+		if(this.frm.doc.is_pos) {
+			$.each(this.frm.doc['payments'] || [], function(index, data){
+				data.base_amount = flt(data.amount * me.frm.doc.conversion_rate, precision("base_amount"));
+				paid_amount += data.amount;
+				base_paid_amount += data.base_amount;
+			})
+		}
 
 		this.frm.doc.paid_amount = flt(paid_amount, precision("paid_amount"));
 		this.frm.doc.base_paid_amount = flt(base_paid_amount, precision("base_paid_amount"));
diff --git a/erpnext/public/js/financial_statements.js b/erpnext/public/js/financial_statements.js
index 16385e1..7115205 100644
--- a/erpnext/public/js/financial_statements.js
+++ b/erpnext/public/js/financial_statements.js
@@ -31,7 +31,8 @@
 			"account": data.account,
 			"company": frappe.query_report_filters_by_name.company.get_value(),
 			"from_date": data.from_date || data.year_start_date,
-			"to_date": data.to_date || data.year_end_date
+			"to_date": data.to_date || data.year_end_date,
+			"project": $.grep(frappe.query_report.filters, function(e){ return e.df.fieldname == 'project'; })[0].$input.val()
 		};
 		frappe.set_route("query-report", "General Ledger");
 	},
diff --git a/erpnext/public/js/pos/pos.html b/erpnext/public/js/pos/pos.html
index 9d0ab60..44e42d7 100644
--- a/erpnext/public/js/pos/pos.html
+++ b/erpnext/public/js/pos/pos.html
@@ -1,14 +1,26 @@
 <div class="pos">
     <div class="row">
-    	<div class="col-sm-5 pos-bill-wrapper">
-            <div class="pos-bill-toolbar row">
-                <div class="party-area col-xs-12"></div>
+    	<div class="col-sm-6 pos-bill-wrapper">
+            <div class="pos-bill-toolbar" style="display: flex;">
+                <div class="party-area" style="flex: 1;"></div>
+				<button class="btn btn-default list-customers-btn" style="margin: 0 5px 0 15px;">
+					<i class="fa fa-list"></i>
+				</button>
+				<button class="btn btn-default add-customer-btn">
+					<i class="fa fa-plus"></i>
+				</button>
+				{% if (allow_delete) { %}
+					<button class="btn btn-default btn-danger" style="margin: 0 5px 0 5px;display:none">
+						<i class="octicon octicon-trashcan"></i>
+					</button>
+				{% } %}
             </div>
     		<div class="pos-bill">
     			<div class="item-cart">
                     <div class="row pos-bill-row pos-bill-header">
-                        <div class="col-xs-5"><h6>{%= __("Item") %}</h6></div>
-                        <div class="col-xs-4"><h6 class="text-right">{%= __("Quantity") %}</h6></div>
+                        <div class="col-xs-4"><h6>{%= __("Item") %}</h6></div>
+                        <div class="col-xs-3"><h6 class="text-right">{%= __("Quantity") %}</h6></div>
+						<div class="col-xs-2"><h6 class="text-right">{%= __("Discount") %}</h6></div>
                         <div class="col-xs-3"><h6 class="text-right">{%= __("Rate") %}</h6></div>
                     </div>
                     <div class="items"></div>
@@ -48,18 +60,27 @@
                     </div>
     			</div>
     		</div>
+			<div class="list-customers">
+
+			</div>
     	</div>
-    	<div class="col-sm-7 pos-items-section">
+    	<div class="col-sm-6 pos-items-section">
 			<div class="row pos-item-area">
 
 			</div>
 			<span id="customer-results" style="color:#68a;"></span>
             <div class="row pos-item-toolbar">
-            	<div class="search-area col-xs-12"></div>
+				<div class="search-item-group col-xs-5"></div>
+				<div class="search-item col-xs-7"></div>
             </div>
-    		<div class="item-list-area">
+    		<div class="item-list-area" style="auto">
 				<div class="app-listing item-list"></ul>
     		</div>
     	</div>
+		<div class="row">
+			<div class="text-right list-paging-area">
+				<button class="btn btn-default btn-more btn-sm" style="margin:5px 20px">{{ __("More") }}</button>
+			</div>
+		</div>
     </div>
 </div>
diff --git a/erpnext/public/js/pos/pos_bill_item.html b/erpnext/public/js/pos/pos_bill_item.html
index d8833bb..1a1f1e2 100644
--- a/erpnext/public/js/pos/pos_bill_item.html
+++ b/erpnext/public/js/pos/pos_bill_item.html
@@ -1,25 +1,30 @@
 <div class="row pos-bill-row pos-bill-item" data-item-code="{%= item_code %}">
-    <div class="col-xs-5"><h6>{%= item_code || "" %}{%= item_name || "" %}</h6></div>
-    <div class="col-xs-4">
+    <div class="col-xs-4"><h6>{%= item_code || "" %}{%= __(item_name) || "" %}</h6></div>
+    <div class="col-xs-3">
         <div class="row pos-qty-row">
-            <div class="col-xs-2 text-center pos-qty-btn" data-action="decrease-qty"><i class="fa fa-minus-sign text-muted"></i></div>
+            <div class="col-xs-2 text-center pos-qty-btn" data-action="decrease-qty"><i class="fa fa-minus text-muted" style="font-size:12px"></i></div>
             <div class="col-xs-8">
 				<div>
-                    <input type="text" value="{%= qty %}" class="form-control input-sm pos-item-qty text-right">
+                    <input type="tel" value="{%= qty %}" class="form-control   pos-item-qty text-right">
                 </div>
                 {% if(actual_qty != null) { %}
                 <div style="margin-top: 5px;" class="text-muted small text-right">
-                    <span title="{%= __("In Stock") %}">{%= actual_qty || 0 %}<span>
+                    {%= __("In Stock: ") %} <span>{%= actual_qty || 0.0 %}</span>
                 </div>
                 {% } %}
             </div>
-            <div class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="fa fa-plus-sign text-muted"></i></div>
+            <div class="col-xs-2 text-center pos-qty-btn" data-action="increase-qty"><i class="fa fa-plus text-muted" style="font-size:12px"></i></div>
+        </div>
+    </div>
+    <div class="col-xs-2 text-right">
+		<div class="row input-sm">
+            <input type="tel" value="{%= discount_percentage %}" class="form-control text-right pos-item-discount">
         </div>
     </div>
     <div class="col-xs-3 text-right">
         <div class="text-muted" style="margin-top: 5px;">
 			{% if(enabled) { %}
-				<input type="text" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right">
+				<input type="tel" value="{%= rate %}" class="form-control input-sm pos-item-rate text-right">
 			{% } else { %}
 				<h6>{%= format_currency(rate) %}</h6>
 			{% } %}
diff --git a/erpnext/public/js/queries.js b/erpnext/public/js/queries.js
index 7c4bf0f..f3167bb 100644
--- a/erpnext/public/js/queries.js
+++ b/erpnext/public/js/queries.js
@@ -36,17 +36,48 @@
 
 	customer_filter: function(doc) {
 		if(!doc.customer) {
-			frappe.throw(__("Please specify a") + " " +
-				__(frappe.meta.get_label(doc.doctype, "customer", doc.name)));
+			frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "customer", doc.name))]));
 		}
 
 		return { filters: { customer: doc.customer } };
 	},
 
+	contact_query: function(doc) {
+		if(frappe.dynamic_link) {
+			if(!doc[frappe.dynamic_link.fieldname]) {
+				frappe.throw(__("Please set {0}",
+					[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
+			}
+
+			return {
+				query: 'frappe.email.doctype.contact.contact.contact_query',
+				filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
+		}
+	},
+
+	address_query: function(doc) {
+		if(frappe.dynamic_link) {
+			if(!doc[frappe.dynamic_link.fieldname]) {
+				frappe.throw(__("Please set {0}", 
+					[__(frappe.meta.get_label(doc.doctype, frappe.dynamic_link.fieldname, doc.name))]));
+			}
+
+			return {
+				query: 'frappe.geo.doctype.address.address.address_query',
+				filters: { link_doctype: frappe.dynamic_link.doctype, link_name: doc[frappe.dynamic_link.fieldname] } };
+		}
+	},
+
+	company_address_query: function(doc) {
+		return {
+			query: 'frappe.geo.doctype.address.address.address_query',
+			filters: { is_your_company_address: 1, link_doctype: 'Company', link_name: doc.company || '' }
+		};
+	},
+
 	supplier_filter: function(doc) {
 		if(!doc.supplier) {
-			frappe.throw(__("Please specify a") + " " +
-				__(frappe.meta.get_label(doc.doctype, "supplier", doc.name)));
+			frappe.throw(__("Please set {0}", [__(frappe.meta.get_label(doc.doctype, "supplier", doc.name))]));
 		}
 
 		return { filters: { supplier: doc.supplier } };
@@ -54,8 +85,8 @@
 
 	lead_filter: function(doc) {
 		if(!doc.lead) {
-			frappe.throw(__("Please specify a") + " " +
-				__(frappe.meta.get_label(doc.doctype, "lead", doc.name)));
+			frappe.throw(__("Please specify a {0}", 
+				[__(frappe.meta.get_label(doc.doctype, "lead", doc.name))]));
 		}
 
 		return { filters: { lead: doc.lead } };
@@ -74,7 +105,7 @@
 			filters: [
 				["Warehouse", "company", "in", ["", cstr(doc.company)]],
 				["Warehouse", "is_group", "=",0]
-				
+
 			]
 		}
 	}
diff --git a/erpnext/public/js/schools/assessment_result_tool.html b/erpnext/public/js/schools/assessment_result_tool.html
new file mode 100644
index 0000000..3c09ccd
--- /dev/null
+++ b/erpnext/public/js/schools/assessment_result_tool.html
@@ -0,0 +1,44 @@
+<table class="table table-bordered assessment-result-tool">
+    <thead>
+        <tr>
+            <th style="width: 100px" rowspan="2">Student</th>
+            <th style="width: 200px" rowspan="2">Student Name</th>
+            {% for c in criteria %}
+            <th class="score" style="width: 100px">{{ c.assessment_criteria }}</th>
+            {% endfor %}
+            <th class="score" style="width: 100px">Total Marks</th>
+            <!--criteria-->
+        </tr>
+        <tr>
+            {% for c in criteria %}
+            <th class="score" style="width: 100px">{{ c.maximum_score }}</th>
+            {% endfor %}
+            <th class="score" style="width: 100px">{{max_total_score}}</th>
+        </tr>
+    </thead>
+    <tbody>
+        {% for s in students %}
+        <tr 
+            {% if(s.assessment_details) { %} class="text-muted" {% } %}
+            data-student="{{s.student}}">
+            <td>{{ s.student }}</td>
+            <td>{{ s.student_name }}</td>
+            {% for c in criteria %}
+            <td>
+                <input type="text"
+                    data-max-score="{{c.maximum_score}}"
+                    data-criteria="{{c.assessment_criteria}}"
+                    data-student="{{s.student}}"
+                    {% if(s.assessment_details) { %}
+                        disabled
+                        value="{{s.assessment_details[c.assessment_criteria]}}"
+                    {% } %}/>
+            </td>
+            {% endfor %}
+            <td data-student="{{s.student}}" class="total-score">
+                {% if(s.assessment_details) { %} {{s.assessment_details.total_score}} {% } %}
+            </td>
+        </tr>
+        {% endfor %}
+    </tbody>
+</table>
\ No newline at end of file
diff --git a/erpnext/public/js/templates/address_list.html b/erpnext/public/js/templates/address_list.html
index 6ee7d78..f9a317f 100644
--- a/erpnext/public/js/templates/address_list.html
+++ b/erpnext/public/js/templates/address_list.html
@@ -2,7 +2,7 @@
 <div class="clearfix"></div>
 {% for(var i=0, l=addr_list.length; i<l; i++) { %}
     <p class="h6">
-        {%= i+1 %}. {%= addr_list[i].address_type %}
+        {%= i+1 %}. {%= addr_list[i].address_type!="Other" ? addr_list[i].address_type : addr_list[i].address_title %}
         {% if(addr_list[i].is_primary_address) { %}
             <span class="text-muted">({%= __("Primary") %})</span>{% } %}
         {% if(addr_list[i].is_shipping_address) { %}
diff --git a/erpnext/public/js/templates/contact_list.html b/erpnext/public/js/templates/contact_list.html
index ddd3e52..abaadff 100644
--- a/erpnext/public/js/templates/contact_list.html
+++ b/erpnext/public/js/templates/contact_list.html
@@ -1,18 +1,23 @@
 <p><button class="btn btn-xs btn-default btn-contact">
     {{ __("New Contact") }}</button></p>
     <div class="clearfix"></div>
-
+<ol>
 {% for(var i=0, l=contact_list.length; i<l; i++) { %}
     <p class="h6">
-        {%= i+1 %}. {%= contact_list[i].first_name %} {%= contact_list[i].last_name %}
-        {% if(contact_list[i].is_primary_contact) { %}
-            <span class="text-muted">({%= __("Primary") %})</span>
-        {% } %}
+		<li>
+	        {%= contact_list[i].first_name %} {%= contact_list[i].last_name %}
+	        {% if(contact_list[i].is_primary_contact) { %}
+	            <span class="text-muted">({%= __("Primary") %})</span>
+	        {% } %}
+	        {% if(contact_list[i].designation){ %}
+	         <span class="text-muted">&ndash; {%= contact_list[i].designation %}</span>
+	        {% } %}
+	        <a href="#Form/Contact/{%= encodeURIComponent(contact_list[i].name) %}"
+	            class="btn btn-xs btn-default pull-right">
+	            {%= __("Edit") %}</a>
+		</li>
+	</p>
 
-        <a href="#Form/Contact/{%= encodeURIComponent(contact_list[i].name) %}"
-            class="btn btn-xs btn-default pull-right">
-            {%= __("Edit") %}</a>
-    </p>
     <div style="padding-left: 15px;">
         <p style="padding-top: 5px; font-size: 12px;">
         {% if(contact_list[i].phone) { %}
@@ -27,6 +32,7 @@
         </p>
     </div>
 {% } %}
+</ol>
 {% if(!contact_list.length) { %}
 <p class="text-muted">{%= __("No contacts added yet.") %}</p>
-{% } %}
+{% } %}
\ No newline at end of file
diff --git a/erpnext/public/js/utils.js b/erpnext/public/js/utils.js
index 74e9fb6..551ea51 100644
--- a/erpnext/public/js/utils.js
+++ b/erpnext/public/js/utils.js
@@ -82,32 +82,6 @@
 
 
 $.extend(erpnext.utils, {
-	clear_address_and_contact: function(frm) {
-		$(frm.fields_dict['address_html'].wrapper).html("");
-		frm.fields_dict['contact_html'] && $(frm.fields_dict['contact_html'].wrapper).html("");
-	},
-
-	render_address_and_contact: function(frm) {
-		// render address
-		$(frm.fields_dict['address_html'].wrapper)
-			.html(frappe.render_template("address_list",
-				cur_frm.doc.__onload))
-			.find(".btn-address").on("click", function() {
-				frappe.new_doc("Address");
-			});
-
-		// render contact
-		if(frm.fields_dict['contact_html']) {
-			$(frm.fields_dict['contact_html'].wrapper)
-				.html(frappe.render_template("contact_list",
-					cur_frm.doc.__onload))
-				.find(".btn-contact").on("click", function() {
-					frappe.new_doc("Contact");
-				}
-			);
-		}
-	},
-
 	set_party_dashboard_indicators: function(frm) {
 		if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
 			var info = frm.doc.__onload.dashboard_info;
diff --git a/erpnext/public/js/utils/party.js b/erpnext/public/js/utils/party.js
index a3f3550..a1d200f 100644
--- a/erpnext/public/js/utils/party.js
+++ b/erpnext/public/js/utils/party.js
@@ -65,7 +65,7 @@
 	if(!display_field) display_field = "address_display";
 	if(frm.doc[address_field]) {
 		frappe.call({
-			method: "erpnext.utilities.doctype.address.address.get_address_display",
+			method: "frappe.geo.doctype.address.address.get_address_display",
 			args: {"address_dict": frm.doc[address_field] },
 			callback: function(r) {
 				if(r.message) {
@@ -151,7 +151,7 @@
 
 erpnext.utils.get_shipping_address = function(frm, callback){
 	frappe.call({
-		method: "erpnext.utilities.doctype.address.address.get_shipping_address",
+		method: "frappe.geo.doctype.address.address.get_shipping_address",
 		args: {company: frm.doc.company},
 		callback: function(r){
 			if(r.message){
diff --git a/erpnext/public/less/erpnext.less b/erpnext/public/less/erpnext.less
index e2ccddd..495e618 100644
--- a/erpnext/public/less/erpnext.less
+++ b/erpnext/public/less/erpnext.less
@@ -82,7 +82,7 @@
 
 .pos-toolbar, .pos-bill-toolbar {
 	padding: 10px 0px;
-	border-bottom: 1px solid #d1d8dd;
+	// border-bottom: 1px solid #d1d8dd;
 	height: 51px;
 }
 
@@ -97,6 +97,7 @@
 }
 
 .pos-bill {
+	border-top: 1px solid @border-color;
 	margin-left: -15px;
 	margin-right: -15px;
 }
@@ -213,6 +214,10 @@
 	padding-right: 30px;
 }
 
+.list-row-head.pos-invoice-list {
+	border-top: 1px solid @border-color;
+}
+
 body[data-route="pos"] .modal-dialog {
 	width: 750px;
 
@@ -257,3 +262,28 @@
 	margin: 15px;
 	width: 130px;
 }
+
+// assessment tool
+.frappe-control[data-fieldname='result_html'] {
+	overflow: scroll;
+}
+.assessment-result-tool {
+	table-layout: fixed;
+
+	input {
+		width: 100%;
+		border: 0;
+		outline: none;
+		text-align: right;
+	}
+
+	th {
+		white-space: nowrap;
+		overflow: hidden;
+		text-overflow: ellipsis;
+	}
+
+	.total-score, .grade, .score {
+		text-align: right;
+	}
+}
\ No newline at end of file
diff --git a/erpnext/schools/api.py b/erpnext/schools/api.py
index bf09351..f1d3753 100644
--- a/erpnext/schools/api.py
+++ b/erpnext/schools/api.py
@@ -7,7 +7,8 @@
 import json
 from frappe import _
 from frappe.model.mapper import get_mapped_doc
-from frappe.utils import flt
+from frappe.utils import flt, cstr
+from frappe.email.doctype.email_group.email_group import add_subscribers
 
 @frappe.whitelist()
 def enroll_student(source_name):
@@ -83,12 +84,23 @@
 	student_attendance.submit()
 
 @frappe.whitelist()
+def get_student_guardians(student):
+	"""Returns List of Guardians of a Student.
+
+	:param student: Student.
+	"""
+	guardians = frappe.get_list("Student Guardian", fields=["guardian"] , 
+		filters={"parent": student})
+	return guardians
+
+@frappe.whitelist()
 def get_student_batch_students(student_batch):
-	"""Returns List of student, student_name in Student Batch.
+	"""Returns List of student, student_name, idx in Student Batch.
 
 	:param student_batch: Student Batch.
 	"""
-	students = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , filters={"parent": student_batch}, order_by= "idx")
+	students = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , 
+		filters={"parent": student_batch, "active": 1}, order_by= "idx")
 	return students
 
 @frappe.whitelist()
@@ -97,7 +109,8 @@
 
 	:param student_group: Student Group.
 	"""
-	students = frappe.get_list("Student Group Student", fields=["student", "student_name"] , filters={"parent": student_group}, order_by= "idx")
+	students = frappe.get_list("Student Group Student", fields=["student", "student_name"] , 
+		filters={"parent": student_group, "active": 1}, order_by= "idx")
 	return students
 
 @frappe.whitelist()
@@ -163,3 +176,111 @@
 			}, as_dict=True, update={"allDay": 0})
 
 	return data
+
+@frappe.whitelist()
+def get_assessment_criteria(course):
+	"""Returns Assessmemt Criteria and their Weightage from Course Master.
+
+	:param Course: Course
+	"""
+	return frappe.get_list("Course Assessment Criteria", \
+		fields=["assessment_criteria", "weightage"], filters={"parent": course}, order_by= "idx")
+
+@frappe.whitelist()
+def get_assessment_students(assessment_plan, student_group=None, student_batch=None):
+	student_list = []
+	if student_group:
+		student_list = get_student_group_students(student_group)
+	elif student_batch:
+		student_list = get_student_batch_students(student_batch)
+	for i, student in enumerate(student_list):
+		result = get_result(student.student, assessment_plan)
+		if result:
+			student_result = {}
+			for d in result.details:
+				student_result.update({d.assessment_criteria: cstr(d.score) + " ("+ d.grade + ")"})
+			student_result.update({"total_score": cstr(result.total_score) + " (" + result.grade + ")"})
+			student.update({'assessment_details': student_result})
+		else:
+			student.update({'assessment_details': None})
+	return student_list
+
+@frappe.whitelist()
+def get_assessment_details(assessment_plan):
+	"""Returns Assessment Criteria  and Maximum Score from Assessment Plan Master.
+
+	:param Assessment Plan: Assessment Plan
+	"""
+	return frappe.get_list("Assessment Plan Criteria", \
+		fields=["assessment_criteria", "maximum_score"], filters={"parent": assessment_plan}, order_by= "idx")
+
+@frappe.whitelist()
+def get_result(student, assessment_plan):
+	"""Returns Submitted Result of given student for specified Assessment Plan
+
+	:param Student: Student
+	:param Assessment Plan: Assessment Plan
+	"""
+	results = frappe.get_all("Assessment Result", filters={"student": student, "assessment_plan": assessment_plan, "docstatus": 1})
+	if results:
+		return frappe.get_doc("Assessment Result", results[0])
+	else:
+		return None
+
+@frappe.whitelist()
+def get_grade(grading_scale, percentage):
+	"""Returns Grade based on the Grading Scale and Score.
+
+	:param Grading Scale: Grading Scale
+	:param Percentage: Score Percentage Percentage
+	"""
+	grading_scale_intervals = {}
+	for d in frappe.get_all("Grading Scale Interval", fields=["grade_code", "threshold"], filters={"parent": grading_scale}):
+		grading_scale_intervals.update({d.threshold:d.grade_code})
+	intervals = sorted(grading_scale_intervals.keys(), key=float, reverse=True)
+	for interval in intervals:
+		if flt(percentage) >= interval:
+			grade = grading_scale_intervals.get(interval)
+			break
+		else:
+			grade = ""
+	return grade
+
+@frappe.whitelist()
+def mark_assessment_result(student, assessment_plan, scores):
+	student_score = json.loads(scores)
+	details = []
+	for s in student_score.keys():
+		details.append({
+			"assessment_criteria": s,
+			"score": flt(student_score[s])
+		})
+	assessment_result = frappe.new_doc("Assessment Result")
+	assessment_result.update({
+		"student": student,
+		"student_name": frappe.db.get_value("Student", student, "title"),
+		"assessment_plan": assessment_plan,
+		"details": details
+	})
+	assessment_result.save()
+	assessment_result.submit()	
+	return assessment_result
+
+@frappe.whitelist()
+def update_email_group(doctype, name):
+	if not frappe.db.exists("Email Group", name):
+		email_group = frappe.new_doc("Email Group")
+		email_group.title = name
+		email_group.save()
+	email_list = []
+	students = []
+	if doctype == "Student Batch":
+		students = get_student_batch_students(name)
+	if doctype == "Student Group":
+		students = get_student_group_students(name)
+	for stud in students:
+		for guard in get_student_guardians(stud.student):
+			email = frappe.db.get_value("Guardian", guard.guardian, "email_address")
+			if email:
+				email_list.append(email)	
+	add_subscribers(name, email_list)
\ No newline at end of file
diff --git a/erpnext/schools/doctype/announcement/announcement.js b/erpnext/schools/doctype/announcement/announcement.js
deleted file mode 100644
index 5b1d1c0..0000000
--- a/erpnext/schools/doctype/announcement/announcement.js
+++ /dev/null
@@ -1,9 +0,0 @@
-// Copyright (c) 2016, Frappe and contributors
-// For license information, please see license.txt
-
-frappe.ui.form.on('Announcement', {
-	onload: function(frm) {
-		frm.add_fetch('instructor', 'instructor_name' , 'posted_by');
-	}
-});
-
diff --git a/erpnext/schools/doctype/announcement/announcement.json b/erpnext/schools/doctype/announcement/announcement.json
deleted file mode 100644
index 831b71f..0000000
--- a/erpnext/schools/doctype/announcement/announcement.json
+++ /dev/null
@@ -1,315 +0,0 @@
-{
- "allow_copy": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
- "autoname": "announcement.#####", 
- "beta": 0, 
- "creation": "2016-06-23 05:37:33.996289", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 0, 
- "fields": [
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "default": "", 
-   "fieldname": "receiver", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Receiver", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Student\nStudent Group\nAll Students", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "instructor", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Instructor", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Instructor", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "column_break_3", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "depends_on": "eval: doc.receiver == \"Student\"", 
-   "fieldname": "student", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Student", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Student", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "depends_on": "eval: doc.receiver == \"Student Group\"", 
-   "fieldname": "student_group", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Student Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Student Group", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "posted_by", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Posted By", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "section_break_5", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "subject", 
-   "fieldtype": "Small Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Subject", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "description", 
-   "fieldtype": "Text Editor", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Description", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "fieldname": "amended_from", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Amended From", 
-   "length": 0, 
-   "no_copy": 1, 
-   "options": "Announcement", 
-   "permlevel": 0, 
-   "print_hide": 1, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "idx": 0, 
- "image_view": 0, 
- "in_create": 0, 
- "in_dialog": 0, 
- "is_submittable": 1, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2016-07-21 06:30:12.825629", 
- "modified_by": "r@r.com", 
- "module": "Schools", 
- "name": "Announcement", 
- "name_case": "", 
- "owner": "demo@erpnext.com", 
- "permissions": [
-  {
-   "amend": 1, 
-   "apply_user_permissions": 0, 
-   "cancel": 1, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Academics User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 1, 
-   "write": 1
-  }
- ], 
- "quick_entry": 0, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "title_field": "subject", 
- "track_seen": 1
-}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/announcement/announcement.py b/erpnext/schools/doctype/announcement/announcement.py
deleted file mode 100644
index 1a3fe75d..0000000
--- a/erpnext/schools/doctype/announcement/announcement.py
+++ /dev/null
@@ -1,75 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.model.document import Document
-from frappe import _
-
-class Announcement(Document):
-	def validate(self):
-		self.validate_receiver()
-		self.set_posted_by()
-
-	def validate_receiver(self):
-		if self.receiver == "Student":
-			if not self.student:
-				frappe.throw(_("Please select a Student"))
-				self.student_group = None
-		elif self.receiver == "Student Group":
-			if not self.student_group:
-				frappe.throw(_("Please select a Student Group"))
-				self.student = None
-		else:
-			self.student_group = None
-			self.student = None
-
-	def set_posted_by(self):
-		if self.instructor:
-			self.posted_by = frappe.db.get_value("Instructor", self.instructor, "instructor_name")
-		else:
-			self.posted_by = frappe.session.user
-
-
-
-
-def get_message_list(doctype, txt, filters, limit_start, limit_page_length=20):
-	user = frappe.session.user
-	student = frappe.db.sql("select name from `tabStudent` where student_email_id= %s", user)
-	if student:
-		sg_list = frappe.db.sql("""select parent from `tabStudent Group Student` as sgs
-				where sgs.student = %s """,(student))
-
-		data = frappe.db.sql("""select name, receiver, subject, description, posted_by, modified,
-			student, student_group
-		    from `tabAnnouncement` as announce
-			where (announce.receiver = "Student" and announce.student = %s)
-			or (announce.receiver = "Student Group" and announce.student_group in %s)
-			or announce.receiver = "All Students"
-			and announce.docstatus = 1	
-			order by announce.idx asc limit {0} , {1}"""
-			.format(limit_start, limit_page_length), (student,sg_list), as_dict = True)
-
-		for announcement in data:
-			try:
-				num_attachments = frappe.db.sql(""" select count(file_url) from tabFile as file
-													where file.attached_to_name=%s 
-													and file.attached_to_doctype=%s""",(announcement.name,"Announcement"))
-
-			except IOError or frappe.DoesNotExistError:
-				pass
-				frappe.local.message_log.pop()
-
-			announcement.num_attachments = num_attachments[0][0]
-
-		return data
-
-def get_list_context(context=None):
-	return {
-		"show_sidebar": True,
-		'no_breadcrumbs': True,
-		"title": _("Announcements"),
-		"get_list": get_message_list,
-		"row_template": "templates/includes/announcement/announcement_row.html"
-	}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/announcement/test_announcement.py b/erpnext/schools/doctype/announcement/test_announcement.py
deleted file mode 100644
index b0200a2..0000000
--- a/erpnext/schools/doctype/announcement/test_announcement.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and Contributors
-# See license.txt
-from __future__ import unicode_literals
-
-import frappe
-import unittest
-
-# test_records = frappe.get_test_records('Announcement')
-
-class TestAnnouncement(unittest.TestCase):
-	pass
diff --git a/erpnext/schools/doctype/assessment/assessment.js b/erpnext/schools/doctype/assessment/assessment.js
deleted file mode 100644
index e842f41..0000000
--- a/erpnext/schools/doctype/assessment/assessment.js
+++ /dev/null
@@ -1,51 +0,0 @@
-// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
-// For license information, please see license.txt
-
-cur_frm.add_fetch("student_group", "course", "course");
-cur_frm.add_fetch("examiner", "instructor_name", "examiner_name");
-cur_frm.add_fetch("supervisor", "instructor_name", "supervisor_name");
-cur_frm.add_fetch("student", "title", "student_name");
-
-frappe.ui.form.on("Assessment", {
-    student_group: function(frm) {
-        frm.set_value("results", "");
-        if (frm.doc.student_group) {
-            frappe.call({
-                method: "erpnext.schools.api.get_student_group_students",
-                args: {
-                    "student_group": frm.doc.student_group
-                },
-                callback: function(r) {
-                    if (r.message) {
-                        $.each(r.message, function(i, d) {
-                            var row = frappe.model.add_child(cur_frm.doc, "Assessment Result", "results");
-                            row.student = d.student;
-                            row.student_name = d.student_name;
-                        });
-                    }
-                    refresh_field("results");
-                }
-            });
-        }
-    }
-});
-
-frappe.ui.form.on("Assessment Result", {
-    result: function(frm, cdt, cdn) {
-        if (frm.doc.grading_structure) {
-            var assessment_result = locals[cdt][cdn];
-            frappe.call({
-                method: "erpnext.schools.doctype.assessment.assessment.get_grade",
-                args: {
-                    grading_structure: frm.doc.grading_structure,
-                    result: assessment_result.result
-                },
-                callback: function(r) {
-                    if (r.message) {
-                        frappe.model.set_value(cdt, cdn, 'grade', r.message);
-                    }
-                }
-            });
-        }
-    }
-});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/assessment.py b/erpnext/schools/doctype/assessment/assessment.py
deleted file mode 100644
index 003b427..0000000
--- a/erpnext/schools/doctype/assessment/assessment.py
+++ /dev/null
@@ -1,73 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-from frappe.model.document import Document
-import frappe
-from frappe import _
-
-class Assessment(Document):
-	def validate(self):
-		self.validate_overlap()
-
-	def validate_overlap(self):
-		"""Validates overlap for Student Group/Student Batch, Instructor, Room"""
-		
-		from erpnext.schools.utils import validate_overlap_for
-
-		#Validate overlapping course schedules.
-		if self.student_batch:
-			validate_overlap_for(self, "Course Schedule", "student_batch")
-
-		if self.student_group:
-			validate_overlap_for(self, "Course Schedule", "student_group")
-		
-		validate_overlap_for(self, "Course Schedule", "instructor")
-		validate_overlap_for(self, "Course Schedule", "room")
-
-		#validate overlapping assessment schedules.
-		if self.student_batch:
-			validate_overlap_for(self, "Assessment", "student_batch")
-		
-		if self.student_group:
-			validate_overlap_for(self, "Assessment", "student_group")
-		
-		validate_overlap_for(self, "Assessment", "room")
-		validate_overlap_for(self, "Assessment", "supervisor", self.instructor)
-
-
-def get_assessment_list(doctype, txt, filters, limit_start, limit_page_length=20):
-	user = frappe.session.user
-	student = frappe.db.sql("select name from `tabStudent` where student_email_id= %s", user)
-	if student:
-		return frappe. db.sql('''select course, schedule_date, from_time, to_time, sgs.name from `tabAssessment` as assessment, 
-			`tabStudent Group Student` as sgs where assessment.student_group = sgs.parent and sgs.student = %s and assessment.docstatus=1
-			order by assessment.name asc limit {0} , {1}'''
-			.format(limit_start, limit_page_length), student, as_dict = True)
-
-def get_list_context(context=None):
-	return {
-		"show_sidebar": True,
-		'no_breadcrumbs': True,
-		"title": _("Assessment Schedule"),
-		"get_list": get_assessment_list,
-		"row_template": "templates/includes/assessment/assessment_row.html"
-	}
-
-@frappe.whitelist()
-def get_grade(grading_structure, result):
-	grade = frappe.db.sql("""select gi.from_score, gi.to_score, gi.grade_code, gi.grade_description 
-		from `tabGrading Structure` as gs, `tabGrade Interval` as gi 
-		where gs.name = gi.parent and gs.name = %(grading_structure)s and gi.from_score <= %(result)s 
-		and gi.to_score >= %(result)s""".format(), 
-		{
-			"grading_structure":grading_structure,
-			"result": result
-		},
-		as_dict=True)
-   	 
-	return grade[0].grade_code if grade else ""
-
-def validate_grade(score, grade):
-	pass
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_criteria/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/assessment/__init__.py
copy to erpnext/schools/doctype/assessment_criteria/__init__.py
diff --git a/erpnext/schools/doctype/assessment_criteria/assessment_criteria.js b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.js
new file mode 100644
index 0000000..44b9ca3
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Assessment Criteria', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/schools/doctype/assessment_criteria/assessment_criteria.json b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.json
new file mode 100644
index 0000000..990b22b
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.json
@@ -0,0 +1,116 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 1, 
+ "allow_rename": 0, 
+ "autoname": "field:assessment_criteria", 
+ "beta": 0, 
+ "creation": "2016-12-14 16:40:15.144115", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "assessment_criteria", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "assessment_criteria_group", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria Group", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Assessment Criteria Group", 
+   "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
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-02-03 05:53:39.248759", 
+ "modified_by": "Administrator", 
+ "module": "Schools", 
+ "name": "Assessment Criteria", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Academics User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_changes": 0, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_criteria/assessment_criteria.py b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.py
new file mode 100644
index 0000000..e666a74
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria/assessment_criteria.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AssessmentCriteria(Document):
+	pass
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/schools/doctype/assessment_criteria/test_assessment_criteria.py
similarity index 62%
copy from erpnext/schools/doctype/assessment/test_assessment.py
copy to erpnext/schools/doctype/assessment_criteria/test_assessment_criteria.py
index ce06007..fc0d745 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/schools/doctype/assessment_criteria/test_assessment_criteria.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Assessment Criteria')
 
-class TestAssessment(unittest.TestCase):
+class TestAssessmentCriteria(unittest.TestCase):
 	pass
diff --git a/erpnext/schools/doctype/assessment_criteria/test_records.json b/erpnext/schools/doctype/assessment_criteria/test_records.json
new file mode 100644
index 0000000..7af63b3
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria/test_records.json
@@ -0,0 +1,8 @@
+[
+ {
+  "assessment_criteria": "_Test Assessment Criteria"
+ }, 
+ {
+  "assessment_criteria": "_Test Assessment Criteria 1"
+ }
+]
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_criteria_group/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/assessment/__init__.py
copy to erpnext/schools/doctype/assessment_criteria_group/__init__.py
diff --git a/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.js b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.js
new file mode 100644
index 0000000..89358d2
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Assessment Criteria Group', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.json b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.json
new file mode 100644
index 0000000..0319868
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.json
@@ -0,0 +1,89 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 1, 
+ "allow_rename": 1, 
+ "autoname": "field:assessment_criteria_group", 
+ "beta": 0, 
+ "creation": "2017-01-27 15:17:38.855910", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "assessment_criteria_group", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria Group", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-02-01 17:39:12.453618", 
+ "modified_by": "Administrator", 
+ "module": "Schools", 
+ "name": "Assessment Criteria Group", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Academics User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_changes": 0, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.py b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.py
new file mode 100644
index 0000000..75381e1
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_criteria_group/assessment_criteria_group.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AssessmentCriteriaGroup(Document):
+	pass
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/schools/doctype/assessment_criteria_group/test_assessment_criteria_group.py
similarity index 60%
copy from erpnext/schools/doctype/assessment/test_assessment.py
copy to erpnext/schools/doctype/assessment_criteria_group/test_assessment_criteria_group.py
index ce06007..5b29337 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/schools/doctype/assessment_criteria_group/test_assessment_criteria_group.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Assessment Criteria Group')
 
-class TestAssessment(unittest.TestCase):
+class TestAssessmentCriteriaGroup(unittest.TestCase):
 	pass
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_plan/__init__.py
similarity index 100%
rename from erpnext/schools/doctype/assessment/__init__.py
rename to erpnext/schools/doctype/assessment_plan/__init__.py
diff --git a/erpnext/schools/doctype/assessment_plan/assessment_plan.js b/erpnext/schools/doctype/assessment_plan/assessment_plan.js
new file mode 100644
index 0000000..9685e0e
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_plan/assessment_plan.js
@@ -0,0 +1,47 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+cur_frm.add_fetch("student_group", "course", "course");
+cur_frm.add_fetch("student_group", "student_batch", "student_batch");
+cur_frm.add_fetch("examiner", "instructor_name", "examiner_name");
+cur_frm.add_fetch("supervisor", "instructor_name", "supervisor_name");
+
+frappe.ui.form.on("Assessment Plan", {
+        refresh: function(frm) {
+        if (!frm.doc.__islocal) {
+            frm.add_custom_button(__("Assessment Result"), function() {
+                frappe.route_options = {
+                    assessment_plan: frm.doc.name
+                }
+                frappe.set_route("Form", "Assessment Result Tool");
+            });
+        }
+    },
+
+    course: function(frm) {
+        if (frm.doc.course && frm.doc.maximum_assessment_score) {
+            frappe.call({
+                method: "erpnext.schools.api.get_assessment_criteria",
+                args: {
+                    course: frm.doc.course
+                },
+                callback: function(r) {
+                    if (r.message) {
+                        frm.doc.assessment_criteria = [];
+                        $.each(r.message, function(i, d) {
+                            var row = frappe.model.add_child(frm.doc, "Assessment Plan Criteria", "assessment_criteria");
+                            row.assessment_criteria = d.assessment_criteria;
+                            row.maximum_score = d.weightage / 100 * frm.doc.maximum_assessment_score;
+                        });
+                    }
+                    refresh_field("assessment_criteria");
+
+                }
+            });
+        }
+    },
+
+    maximum_assessment_score: function(frm) {
+        frm.trigger("course");
+    }
+});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/assessment.json b/erpnext/schools/doctype/assessment_plan/assessment_plan.json
similarity index 85%
rename from erpnext/schools/doctype/assessment/assessment.json
rename to erpnext/schools/doctype/assessment_plan/assessment_plan.json
index 845f2f6..64ff487 100644
--- a/erpnext/schools/doctype/assessment/assessment.json
+++ b/erpnext/schools/doctype/assessment_plan/assessment_plan.json
@@ -73,6 +73,175 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "assessment_group", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 1, 
+   "label": "Assessment Group", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Assessment Group", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "course", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 1, 
+   "label": "Course", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Course", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "maximum_assessment_score", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Maximum Assessment Score", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "grading_scale", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 1, 
+   "label": "Grading Scale", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Grading Scale", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_10", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_group", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -102,6 +271,33 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "column_break_10", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_batch", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -130,234 +326,6 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "grading_structure", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Grading Structure", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Grading Structure", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "course", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Course", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Course", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 1, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break_2", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "assessment_group", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Assessment Group", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Assessment Group", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "supervisor", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supervisor", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Instructor", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "supervisor_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supervisor Name", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "examiner", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Examiner", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Instructor", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "examiner_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Examiner Name", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
    "collapsible_depends_on": "", 
    "columns": 0, 
    "depends_on": "", 
@@ -447,6 +415,63 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "examiner", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Examiner", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Instructor", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "examiner_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Examiner Name", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_4", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -528,9 +553,66 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 1, 
+   "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "section_break_11", 
+   "fieldname": "supervisor", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Supervisor", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Instructor", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "supervisor_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Supervisor Name", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_20", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -538,7 +620,6 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Results", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -558,7 +639,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "results", 
+   "fieldname": "assessment_criteria", 
    "fieldtype": "Table", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -566,10 +647,10 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "results", 
+   "label": "Assessment Criteria", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Assessment Result", 
+   "options": "Assessment Plan Criteria", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -577,7 +658,7 @@
    "read_only": 0, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 0, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -598,7 +679,7 @@
    "label": "Amended From", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "Assessment", 
+   "options": "Assessment Plan", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -622,10 +703,10 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-16 13:05:54.953750", 
+ "modified": "2017-02-01 17:22:11.816270", 
  "modified_by": "Administrator", 
  "module": "Schools", 
- "name": "Assessment", 
+ "name": "Assessment Plan", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [
@@ -639,7 +720,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -656,5 +736,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_plan/assessment_plan.py b/erpnext/schools/doctype/assessment_plan/assessment_plan.py
new file mode 100644
index 0000000..31e96aa
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_plan/assessment_plan.py
@@ -0,0 +1,52 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+from frappe.model.document import Document
+import frappe
+from frappe import _
+
+class AssessmentPlan(Document):
+	def validate(self):
+		if not (self.student_batch or self.student_group):
+			frappe.throw(_("Please select Student Group or Student Batch"))
+		self.validate_student_batch()
+		self.validate_overlap()
+		self.validate_max_score()
+
+	def validate_overlap(self):
+		"""Validates overlap for Student Group/Student Batch, Instructor, Room"""
+		
+		from erpnext.schools.utils import validate_overlap_for
+
+		#Validate overlapping course schedules.
+		if self.student_batch:
+			validate_overlap_for(self, "Course Schedule", "student_batch")
+
+		if self.student_group:
+			validate_overlap_for(self, "Course Schedule", "student_group")
+		
+		validate_overlap_for(self, "Course Schedule", "instructor")
+		validate_overlap_for(self, "Course Schedule", "room")
+
+		#validate overlapping assessment schedules.
+		if self.student_batch:
+			validate_overlap_for(self, "Assessment Plan", "student_batch")
+		
+		if self.student_group:
+			validate_overlap_for(self, "Assessment Plan", "student_group")
+		
+		validate_overlap_for(self, "Assessment Plan", "room")
+		validate_overlap_for(self, "Assessment Plan", "supervisor", self.supervisor)
+
+	def validate_student_batch(self):
+		if self.student_group:
+			self.student_batch = frappe.db.get_value("Student Group", self.student_group, "student_batch")
+
+	def validate_max_score(self):
+		max_score = 0
+		for d in self.assessment_criteria:
+			max_score += d.maximum_score
+		if self.maximum_assessment_score != max_score:
+			frappe.throw(_("Sum of Scores of Assessment Criteria needs to be {0}.".format(self.maximum_assessment_score)))
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/schools/doctype/assessment_plan/test_assessment_plan.py
similarity index 64%
copy from erpnext/schools/doctype/assessment/test_assessment.py
copy to erpnext/schools/doctype/assessment_plan/test_assessment_plan.py
index ce06007..2de4f23 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/schools/doctype/assessment_plan/test_assessment_plan.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Assessment Plan')
 
-class TestAssessment(unittest.TestCase):
+class TestAssessmentPlan(unittest.TestCase):
 	pass
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_plan_criteria/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/assessment/__init__.py
copy to erpnext/schools/doctype/assessment_plan_criteria/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.json
similarity index 60%
copy from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
copy to erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.json
index 6b80efc..2ba5ca7 100644
--- a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.json
@@ -2,35 +2,67 @@
  "allow_copy": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
+ "autoname": "", 
  "beta": 0, 
- "creation": "2016-09-03 19:20:14.561962", 
+ "creation": "2016-12-14 17:20:27.738226", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
+ "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "service_item", 
-   "fieldtype": "Select", 
+   "fieldname": "assessment_criteria", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Service Item", 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
+   "options": "Assessment Criteria", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "", 
+   "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, 
@@ -42,68 +74,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
+   "fieldname": "maximum_score", 
+   "fieldtype": "Float", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nInspection\nService\nChange", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "frequency", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Frequency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "expense_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Expense", 
+   "in_standard_filter": 0, 
+   "label": "Maximum Score", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -111,8 +90,9 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 0, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -128,10 +108,10 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-20 07:29:50.852748", 
+ "modified": "2017-02-01 17:11:47.164623", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle Service", 
+ "module": "Schools", 
+ "name": "Assessment Plan Criteria", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [], 
@@ -140,5 +120,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.py b/erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.py
new file mode 100644
index 0000000..53b477f
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_plan_criteria/assessment_plan_criteria.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AssessmentPlanCriteria(Document):
+	pass
diff --git a/erpnext/schools/doctype/assessment_result/assessment_result.js b/erpnext/schools/doctype/assessment_result/assessment_result.js
new file mode 100644
index 0000000..0af5adc
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result/assessment_result.js
@@ -0,0 +1,51 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+cur_frm.add_fetch("student", "title", "student_name");
+cur_frm.add_fetch("assessment_plan", "grading_scale", "grading_scale");
+cur_frm.add_fetch("assessment_plan", "maximum_assessment_score", "maximum_score");
+
+frappe.ui.form.on("Assessment Result", {
+    assessment_plan: function(frm) {
+        frappe.call({
+            method: "erpnext.schools.api.get_assessment_details",
+            args: {
+                assessment_plan: frm.doc.assessment_plan
+            },
+            callback: function(r) {
+                if (r.message) {
+                    frm.doc.details = [];
+                    $.each(r.message, function(i, d) {
+                        var row = frappe.model.add_child(frm.doc, "Assessment Result Detail", "details");
+                        row.assessment_criteria = d.assessment_criteria;
+                        row.maximum_score = d.maximum_score;
+                    });
+                }
+                refresh_field("details");
+            }
+        });
+    }
+});
+
+frappe.ui.form.on("Assessment Result Detail", {
+    score: function(frm, cdt, cdn) {
+        var d  = locals[cdt][cdn];
+        if (d.score >= d.maximum_score) {
+            frappe.throw(_("Score cannot be greater than Maximum Score"));
+        }
+        else {
+            frappe.call({
+                method: "erpnext.schools.api.get_grade",
+                args: {
+                    grading_scale: frm.doc.grading_scale,
+                    percentage: ((d.score/d.maximum_score) * 100)
+                },
+                callback: function(r) {
+                    if (r.message) {
+                        frappe.model.set_value(cdt, cdn, "grade", r.message);
+                    }
+                }
+            });
+        }
+    }
+});
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_result/assessment_result.json b/erpnext/schools/doctype/assessment_result/assessment_result.json
index 91e580d..3bf9758 100644
--- a/erpnext/schools/doctype/assessment_result/assessment_result.json
+++ b/erpnext/schools/doctype/assessment_result/assessment_result.json
@@ -2,6 +2,7 @@
  "allow_copy": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
+ "autoname": "RES.######", 
  "beta": 0, 
  "creation": "2015-11-13 17:18:06.468332", 
  "custom": 0, 
@@ -9,18 +10,21 @@
  "doctype": "DocType", 
  "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Student", 
    "length": 0, 
    "no_copy": 0, 
@@ -30,6 +34,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -40,6 +45,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -47,6 +53,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Student Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -55,6 +62,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, 
@@ -65,6 +73,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_3", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -72,6 +81,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -79,6 +89,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, 
@@ -89,21 +100,54 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "result", 
-   "fieldtype": "Data", 
+   "columns": 0, 
+   "fieldname": "assessment_plan", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Result", 
+   "in_standard_filter": 0, 
+   "label": "Assessment Plan", 
    "length": 0, 
    "no_copy": 0, 
+   "options": "Assessment Plan", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "grading_scale", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Grading Scale", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Grading Scale", 
+   "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, 
@@ -114,6 +158,174 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_5", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "", 
+   "fieldname": "details", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Details", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Assessment Result Detail", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_8", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "maximum_score", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Maximum Score", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "total_score", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Total Score", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_11", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grade", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -121,6 +333,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Grade", 
    "length": 0, 
    "no_copy": 0, 
@@ -129,6 +342,35 @@
    "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "amended_from", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Amended From", 
+   "length": 0, 
+   "no_copy": 1, 
+   "options": "Assessment Result", 
+   "permlevel": 0, 
+   "print_hide": 1, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -142,21 +384,45 @@
  "image_view": 0, 
  "in_create": 0, 
  "in_dialog": 0, 
- "is_submittable": 0, 
+ "is_submittable": 1, 
  "issingle": 0, 
- "istable": 1, 
+ "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-27 12:15:01.923000", 
+ "modified": "2017-01-04 16:56:33.868949", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Assessment Result", 
  "name_case": "", 
  "owner": "Administrator", 
- "permissions": [], 
+ "permissions": [
+  {
+   "amend": 1, 
+   "apply_user_permissions": 0, 
+   "cancel": 1, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Academics User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 1, 
+   "write": 1
+  }
+ ], 
  "quick_entry": 0, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "title_field": "student_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_result/assessment_result.py b/erpnext/schools/doctype/assessment_result/assessment_result.py
index 84cbcfa..c878ec3 100644
--- a/erpnext/schools/doctype/assessment_result/assessment_result.py
+++ b/erpnext/schools/doctype/assessment_result/assessment_result.py
@@ -4,7 +4,33 @@
 
 from __future__ import unicode_literals
 import frappe
+from frappe import _
+from frappe.utils import flt
 from frappe.model.document import Document
+from erpnext.schools.api import get_grade
+from erpnext.schools.api import get_assessment_details
 
 class AssessmentResult(Document):
-	pass
+	def validate(self):
+		self.grading_scale = frappe.db.get_value("Assessment Plan", self.assessment_plan, "grading_scale")
+		self.validate_maximum_score()
+		self.validate_grade()
+	
+	def validate_maximum_score(self):
+		self.maximum_score = frappe.db.get_value("Assessment Plan", self.assessment_plan, "maximum_assessment_score")
+		assessment_details = get_assessment_details(self.assessment_plan)
+		max_scores = {}
+		for d in assessment_details:
+			max_scores.update({d.assessment_criteria: d.maximum_score})
+
+		for d in self.details:
+			d.maximum_score = max_scores.get(d.assessment_criteria)
+			if d.score > d.maximum_score:
+				frappe.throw(_("Score cannot be greater than Maximum Score"))
+		
+	def validate_grade(self):
+		self.total_score = 0.0
+		for d in self.details:
+			d.grade = get_grade(self.grading_scale, (flt(d.score)/d.maximum_score)*100)
+			self.total_score += d.score
+		self.grade = get_grade(self.grading_scale, (self.total_score/self.maximum_score)*100)
diff --git a/erpnext/schools/doctype/assessment_result/test_assessment_result.py b/erpnext/schools/doctype/assessment_result/test_assessment_result.py
new file mode 100644
index 0000000..66e611c
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result/test_assessment_result.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# See license.txt
+from __future__ import unicode_literals
+
+import frappe
+import unittest
+from erpnext.schools.api import get_grade
+
+# test_records = frappe.get_test_records('Assessment Result')
+
+class TestAssessmentResult(unittest.TestCase):
+	def test_grade(self):
+		grade = get_grade("_Test Grading Scale", 80)
+		self.assertEquals("A", grade)
+
+		grade = get_grade("_Test Grading Scale", 70)
+		self.assertEquals("B", grade)
+		
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_result_detail/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/assessment/__init__.py
copy to erpnext/schools/doctype/assessment_result_detail/__init__.py
diff --git a/erpnext/schools/doctype/topic/topic.json b/erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.json
similarity index 64%
rename from erpnext/schools/doctype/topic/topic.json
rename to erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.json
index 0a69f88..7956a32 100644
--- a/erpnext/schools/doctype/topic/topic.json
+++ b/erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.json
@@ -1,43 +1,71 @@
 {
  "allow_copy": 0, 
  "allow_import": 0, 
- "allow_rename": 1, 
- "autoname": "Topic.####", 
+ "allow_rename": 0, 
+ "autoname": "", 
  "beta": 0, 
- "creation": "2016-06-28 07:06:38.749398", 
+ "creation": "2016-12-14 17:44:35.583123", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 0, 
+ "document_type": "", 
+ "editable_grid": 1, 
  "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "course", 
+   "columns": 4, 
+   "fieldname": "assessment_criteria", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Course", 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Course", 
+   "options": "Assessment Criteria", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
-   "search_index": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "maximum_score", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Maximum Score", 
+   "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
   }, 
@@ -46,7 +74,63 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "topic_name", 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "score", 
+   "fieldtype": "Float", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Score", 
+   "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": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 2, 
+   "fieldname": "grade", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -54,73 +138,17 @@
    "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 0, 
-   "label": "Topic Name", 
+   "label": "Grade", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "introduction", 
-   "fieldtype": "Text", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Introduction", 
-   "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": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "content", 
-   "fieldtype": "Text Editor", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Content", 
-   "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": 1, 
+   "reqd": 0, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -134,42 +162,20 @@
  "in_dialog": 0, 
  "is_submittable": 0, 
  "issingle": 0, 
- "istable": 0, 
+ "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:29:20.531725", 
+ "modified": "2017-02-01 18:33:06.006040", 
  "modified_by": "Administrator", 
  "module": "Schools", 
- "name": "Topic", 
+ "name": "Assessment Result Detail", 
  "name_case": "", 
  "owner": "Administrator", 
- "permissions": [
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Academics User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }
- ], 
+ "permissions": [], 
  "quick_entry": 1, 
  "read_only": 0, 
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
- "title_field": "course", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.py b/erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.py
new file mode 100644
index 0000000..d051593
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result_detail/assessment_result_detail.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AssessmentResultDetail(Document):
+	pass
diff --git a/erpnext/schools/doctype/assessment/__init__.py b/erpnext/schools/doctype/assessment_result_tool/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/assessment/__init__.py
copy to erpnext/schools/doctype/assessment_result_tool/__init__.py
diff --git a/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.js b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.js
new file mode 100644
index 0000000..8fd670e
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.js
@@ -0,0 +1,106 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+cur_frm.add_fetch("assessment_plan", "student_group", "student_group");
+cur_frm.add_fetch("assessment_plan", "student_batch", "student_batch");
+
+frappe.ui.form.on('Assessment Result Tool', {
+    refresh: function(frm) {
+       frm.disable_save();
+	   frm.page.clear_indicator();
+    },
+
+	assessment_plan: function(frm) {
+		if(!(frm.doc.student_batch || frm.doc.student_group)) return;
+		frappe.call({
+			method: "erpnext.schools.api.get_assessment_students",
+			args: {
+				"assessment_plan": frm.doc.assessment_plan,
+				"student_batch": frm.doc.student_batch,
+				"student_group": frm.doc.student_group
+			},
+			callback: function(r) {
+				frm.events.render_table(frm, r.message);
+			}
+		});
+	},
+
+	render_table: function(frm, students) {
+		$(frm.fields_dict.result_html.wrapper).empty();
+		var assessment_plan = frm.doc.assessment_plan;
+		var student_scores = {};
+		students.forEach(function(stu) {
+			student_scores[stu.student] = {}
+		});
+		
+		frappe.call({
+			method: "erpnext.schools.api.get_assessment_details",
+			args: {
+				assessment_plan: assessment_plan
+			},
+			callback: function(r) {
+				var criteria_list = r.message;
+				var max_total_score = 0;
+				criteria_list.forEach(function(c) {
+					max_total_score += c.maximum_score
+				});
+				var result_table = $(frappe.render_template('assessment_result_tool', {
+					frm: frm,
+					students: students,
+					criteria: criteria_list,
+					max_total_score: max_total_score
+				}));
+				result_table.appendTo(frm.fields_dict.result_html.wrapper)
+
+				result_table.on('change', 'input', function(e) {
+					var $input = $(e.target);
+					var max_score = $input.data().maxScore;
+					var student = $input.data().student;
+					var criteria = $input.data().criteria;
+					var value = $input.val();
+					if(value < 0) {
+						$input.val(0);
+						value = 0;
+					}
+					if(value > max_score) {
+						$input.val(max_score);
+						value = max_score;
+					}
+					student_scores[student][criteria] = value;
+					if(Object.keys(student_scores[student]).length == criteria_list.length) {
+						console.log("ok");
+						frappe.call(({
+							method: "erpnext.schools.api.mark_assessment_result",
+							args: {
+								"student": student,
+								"assessment_plan": assessment_plan,
+								"scores": student_scores[student]
+							},
+							callback: function(r) {
+								var doc = r.message;
+								var student = doc.student;
+								result_table.find(`[data-student=${student}].total-score`)
+									.html(doc.total_score + ' ('+ doc.grade + ')');
+								var details = doc.details;
+								result_table.find(`tr[data-student=${student}]`).addClass('text-muted');
+								result_table.find(`input[data-student=${student}]`).each(function(el, input) {
+									var $input = $(input);
+									var criteria = $input.data().criteria;
+									var value = $input.val();
+									var grade = details.find(function(d) {
+										return d.assessment_criteria === criteria;
+									}).grade;
+									$input.val(`${value} (${grade})`);
+									$input.attr('disabled', true);
+								});
+
+							}
+						}))
+					}
+				});
+
+			}
+		});
+	},
+
+});
diff --git a/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.json b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.json
new file mode 100644
index 0000000..87dff4d
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.json
@@ -0,0 +1,232 @@
+{
+ "allow_copy": 1, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "beta": 0, 
+ "creation": "2017-01-05 12:27:48.951036", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "", 
+   "fieldname": "assessment_plan", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment Plan", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Assessment Plan", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "student_group", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Student Group", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Group", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "student_batch", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Student Batch", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Batch", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "depends_on": "assessment_plan", 
+   "fieldname": "section_break_5", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "result_html", 
+   "fieldtype": "HTML", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Result HTML", 
+   "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
+  }
+ ], 
+ "hide_heading": 1, 
+ "hide_toolbar": 1, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 1, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-01-05 15:45:59.338722", 
+ "modified_by": "Administrator", 
+ "module": "Schools", 
+ "name": "Assessment Result Tool", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 0, 
+   "email": 1, 
+   "export": 0, 
+   "if_owner": 0, 
+   "import": 0, 
+   "is_custom": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 0, 
+   "role": "Academics User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_changes": 0, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.py b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.py
new file mode 100644
index 0000000..a0d286c
--- /dev/null
+++ b/erpnext/schools/doctype/assessment_result_tool/assessment_result_tool.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class AssessmentResultTool(Document):
+	pass
diff --git a/erpnext/schools/doctype/course/course.js b/erpnext/schools/doctype/course/course.js
index fe38806..c667eca 100644
--- a/erpnext/schools/doctype/course/course.js
+++ b/erpnext/schools/doctype/course/course.js
@@ -21,11 +21,11 @@
 			frappe.set_route("List", "Course Schedule");
 		});
 		
-		frm.add_custom_button(__("Assessment"), function() {
+		frm.add_custom_button(__("Assessment Plan"), function() {
 			frappe.route_options = {
 				course: frm.doc.name
 			}
-			frappe.set_route("List", "Assessment");
+			frappe.set_route("List", "Assessment Plan");
 		});
 	}
 });
\ No newline at end of file
diff --git a/erpnext/schools/doctype/course/course.json b/erpnext/schools/doctype/course/course.json
index 6fada19..aab3bbb 100644
--- a/erpnext/schools/doctype/course/course.json
+++ b/erpnext/schools/doctype/course/course.json
@@ -206,6 +206,92 @@
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "assessment", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "default_grading_scale", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Default Grading Scale", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Grading Scale", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "assessment_criteria", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Course Assessment Criteria", 
+   "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
   }
  ], 
  "hide_heading": 0, 
@@ -219,7 +305,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-08-08 05:26:26.442635", 
+ "modified": "2017-02-01 17:24:52.874364", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Course", 
@@ -236,7 +322,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -274,5 +359,6 @@
  "search_fields": "department", 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/course/course.py b/erpnext/schools/doctype/course/course.py
index b590acb..0ac11ec 100644
--- a/erpnext/schools/doctype/course/course.py
+++ b/erpnext/schools/doctype/course/course.py
@@ -8,21 +8,13 @@
 from frappe import _
 
 class Course(Document):
-	pass
-
-def get_sg_list(doctype, txt, filters, limit_start, limit_page_length=20):
-	user = frappe.session.user
-	student = frappe.db.sql("select name from `tabStudent` where student_email_id= %s", user)
-	if student:
-		return frappe.db.sql('''select course, academic_term, academic_year, SG.name from `tabStudent Group`
-			as SG, `tabStudent Group Student` as SGS where SG.name = SGS.parent and SGS.student = %s
-			order by SG.name asc limit {0} , {1}'''.format(limit_start, limit_page_length), student, as_dict=True)
-
-def get_list_context(context=None):
-	return {
-		"show_sidebar": True,
-		'no_breadcrumbs': True,
-		"title": _("Courses"),
-		"get_list": get_sg_list,
-		"row_template": "templates/includes/course/course_row.html"
-	}
\ No newline at end of file
+	def validate(self):
+		self.validate_assessment_criteria()
+	
+	def validate_assessment_criteria(self):
+		if self.assessment_criteria:
+			total_weightage = 0
+			for criteria in self.assessment_criteria:
+				total_weightage += criteria.weightage
+			if total_weightage != 100:
+				frappe.throw(_("Total Weightage of all Assessment Criteria must be 100%"))
diff --git a/erpnext/schools/doctype/announcement/__init__.py b/erpnext/schools/doctype/course_assessment_criteria/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/announcement/__init__.py
copy to erpnext/schools/doctype/course_assessment_criteria/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.json
similarity index 60%
copy from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
copy to erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.json
index 6b80efc..6646d20 100644
--- a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.json
@@ -2,35 +2,67 @@
  "allow_copy": 0, 
  "allow_import": 0, 
  "allow_rename": 0, 
+ "autoname": "", 
  "beta": 0, 
- "creation": "2016-09-03 19:20:14.561962", 
+ "creation": "2016-12-14 16:46:46.786353", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
+ "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "service_item", 
-   "fieldtype": "Select", 
+   "fieldname": "assessment_criteria", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Service Item", 
+   "in_standard_filter": 0, 
+   "label": "Assessment Criteria", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
+   "options": "Assessment Criteria", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "", 
+   "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, 
@@ -42,68 +74,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
+   "fieldname": "weightage", 
+   "fieldtype": "Percent", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nInspection\nService\nChange", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "frequency", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Frequency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "expense_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Expense", 
+   "in_standard_filter": 0, 
+   "label": "Weightage", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -111,6 +90,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, 
@@ -128,10 +108,10 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-20 07:29:50.852748", 
+ "modified": "2017-02-01 18:01:40.682674", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle Service", 
+ "module": "Schools", 
+ "name": "Course Assessment Criteria", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [], 
@@ -140,5 +120,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.py b/erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.py
new file mode 100644
index 0000000..ade2a39
--- /dev/null
+++ b/erpnext/schools/doctype/course_assessment_criteria/course_assessment_criteria.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class CourseAssessmentCriteria(Document):
+	pass
diff --git a/erpnext/schools/doctype/course_schedule/course_schedule.py b/erpnext/schools/doctype/course_schedule/course_schedule.py
index ec30c62..7550ab1 100644
--- a/erpnext/schools/doctype/course_schedule/course_schedule.py
+++ b/erpnext/schools/doctype/course_schedule/course_schedule.py
@@ -55,11 +55,11 @@
 
 		#validate overlapping assessment schedules.
 		if self.student_batch:
-			validate_overlap_for(self, "Assessment", "student_batch")
+			validate_overlap_for(self, "Assessment Plan", "student_batch")
 		
 		if self.student_group:
-			validate_overlap_for(self, "Assessment", "student_group")
+			validate_overlap_for(self, "Assessment Plan", "student_group")
 		
-		validate_overlap_for(self, "Assessment", "room")
-		validate_overlap_for(self, "Assessment", "supervisor", self.instructor)
+		validate_overlap_for(self, "Assessment Plan", "room")
+		validate_overlap_for(self, "Assessment Plan", "supervisor", self.instructor)
 
diff --git a/erpnext/schools/doctype/discussion/__init__.py b/erpnext/schools/doctype/discussion/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/schools/doctype/discussion/__init__.py
+++ /dev/null
diff --git a/erpnext/schools/doctype/discussion/discussion.js b/erpnext/schools/doctype/discussion/discussion.js
deleted file mode 100644
index df3c2b8..0000000
--- a/erpnext/schools/doctype/discussion/discussion.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (c) 2016, Frappe and contributors
-// For license information, please see license.txt
-
-frappe.ui.form.on('Discussion', {
-	refresh: function(frm) {
-
-	}
-});
diff --git a/erpnext/schools/doctype/discussion/discussion.py b/erpnext/schools/doctype/discussion/discussion.py
deleted file mode 100644
index 96732e3..0000000
--- a/erpnext/schools/doctype/discussion/discussion.py
+++ /dev/null
@@ -1,37 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe import _
-from frappe.model.document import Document
-
-class Discussion(Document):
-	def validate(self):
-		if not self.owner== frappe.session.user:
-			frappe.throw(_("Not Permitted"))
-
-def get_discussions(doctype, txt, filters, limit_start, limit_page_length=20):
-	from frappe.www.list import get_list
-	if not filters:
-		filters = []
-		filters.append(("Discussion", "course", "=", frappe.form_dict.course))
-	return get_list(doctype, txt, filters, limit_start, limit_page_length, ignore_permissions=True)
-
-def get_list_context(context=None):
-	course_name = frappe.form_dict.course
-	portal_items = [{'reference_doctype': u'Topic', 'route': u"/topic?course=" + str(course_name), 'show_always': 0L, 'title': u'Topics'},
-				{'reference_doctype': u'Discussion', 'route': u"/discussion?course=" + str(course_name), 'show_always': 0L, 'title': u'Discussions'},
-
-	]
-	sidebar_title = course_name
-	return {
-		"show_sidebar": True,
-		'no_breadcrumbs': True,
-		"get_list" : get_discussions,
-		"title": _("Discussions"),
-		"sidebar_items" : portal_items,
-		"sidebar_title" : sidebar_title,
-		"row_template": "templates/includes/discussion/discussion_row.html"
-	}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/discussion/test_discussion.py b/erpnext/schools/doctype/discussion/test_discussion.py
deleted file mode 100644
index 31799f0..0000000
--- a/erpnext/schools/doctype/discussion/test_discussion.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and Contributors
-# See license.txt
-from __future__ import unicode_literals
-
-import frappe
-import unittest
-
-# test_records = frappe.get_test_records('Discussion')
-
-class TestDiscussion(unittest.TestCase):
-	pass
diff --git a/erpnext/schools/doctype/grade_interval/grade_interval.json b/erpnext/schools/doctype/grade_interval/grade_interval.json
index 79ef9f4..c9c5949 100644
--- a/erpnext/schools/doctype/grade_interval/grade_interval.json
+++ b/erpnext/schools/doctype/grade_interval/grade_interval.json
@@ -9,11 +9,13 @@
  "doctype": "DocType", 
  "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grade_code", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -21,6 +23,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Grade Code", 
    "length": 0, 
    "no_copy": 0, 
@@ -29,6 +32,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -39,14 +43,16 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "from_score", 
-   "fieldtype": "Float", 
+   "columns": 0, 
+   "fieldname": "min_score", 
+   "fieldtype": "Percent", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "From Score", 
+   "in_standard_filter": 0, 
+   "label": "Min Score", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -54,6 +60,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -64,31 +71,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "to_score", 
-   "fieldtype": "Float", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "To Score", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "1", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grade_description", 
    "fieldtype": "Small Text", 
    "hidden": 0, 
@@ -96,6 +79,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Grade Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -104,6 +88,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, 
@@ -121,7 +106,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-08-27 15:45:04.657328", 
+ "modified": "2016-12-14 12:54:56.902465", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Grade Interval", 
diff --git a/erpnext/schools/doctype/announcement/__init__.py b/erpnext/schools/doctype/grading_scale/__init__.py
similarity index 100%
rename from erpnext/schools/doctype/announcement/__init__.py
rename to erpnext/schools/doctype/grading_scale/__init__.py
diff --git a/erpnext/schools/doctype/grading_scale/grading_scale.js b/erpnext/schools/doctype/grading_scale/grading_scale.js
new file mode 100644
index 0000000..622388c
--- /dev/null
+++ b/erpnext/schools/doctype/grading_scale/grading_scale.js
@@ -0,0 +1,8 @@
+// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Grading Scale', {
+	refresh: function(frm) {
+
+	}
+});
diff --git a/erpnext/schools/doctype/discussion/discussion.json b/erpnext/schools/doctype/grading_scale/grading_scale.json
similarity index 70%
rename from erpnext/schools/doctype/discussion/discussion.json
rename to erpnext/schools/doctype/grading_scale/grading_scale.json
index 57ebfba..99c6948 100644
--- a/erpnext/schools/doctype/discussion/discussion.json
+++ b/erpnext/schools/doctype/grading_scale/grading_scale.json
@@ -1,15 +1,15 @@
 {
  "allow_copy": 0, 
- "allow_import": 1, 
- "allow_rename": 0, 
- "autoname": "Discussion.####", 
+ "allow_import": 0, 
+ "allow_rename": 1, 
+ "autoname": "field:grading_scale_name", 
  "beta": 0, 
- "creation": "2016-06-13 07:57:38.326925", 
+ "creation": "2016-08-26 03:06:53.922972", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
- "editable_grid": 0, 
+ "document_type": "", 
+ "editable_grid": 1, 
  "engine": "InnoDB", 
  "fields": [
   {
@@ -17,7 +17,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "subject", 
+   "fieldname": "grading_scale_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
@@ -25,7 +25,7 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Subject", 
+   "label": "Grading Scale Name", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -36,36 +36,7 @@
    "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "course", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Course", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Course", 
-   "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": 1, 
+   "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
   }, 
@@ -75,12 +46,12 @@
    "collapsible": 0, 
    "columns": 0, 
    "fieldname": "description", 
-   "fieldtype": "Text", 
+   "fieldtype": "Small Text", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 0, 
+   "in_list_view": 1, 
    "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
@@ -102,6 +73,63 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "grading_intervals_section", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Grading Scale Intervals", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "intervals", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Intervals", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Grading Scale Interval", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "amended_from", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -113,7 +141,7 @@
    "label": "Amended From", 
    "length": 0, 
    "no_copy": 1, 
-   "options": "Discussion", 
+   "options": "Grading Scale", 
    "permlevel": 0, 
    "print_hide": 1, 
    "print_hide_if_no_value": 0, 
@@ -136,17 +164,17 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:28:34.032169", 
+ "modified": "2016-12-14 14:35:22.907023", 
  "modified_by": "Administrator", 
  "module": "Schools", 
- "name": "Discussion", 
+ "name": "Grading Scale", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [
   {
    "amend": 0, 
    "apply_user_permissions": 0, 
-   "cancel": 0, 
+   "cancel": 1, 
    "create": 1, 
    "delete": 1, 
    "email": 1, 
@@ -170,6 +198,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
- "title_field": "subject", 
- "track_seen": 1
+ "title_field": "", 
+ "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/grading_scale/grading_scale.py b/erpnext/schools/doctype/grading_scale/grading_scale.py
new file mode 100644
index 0000000..4abff96
--- /dev/null
+++ b/erpnext/schools/doctype/grading_scale/grading_scale.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import cint
+from frappe.model.document import Document
+
+class GradingScale(Document):
+	def validate(self):
+		thresholds = []
+		for d in self.intervals:
+			if d.threshold in thresholds:
+				frappe.throw(_("Treshold {0}% appears more than once".format(d.threshold)))
+			else:
+				thresholds.append(cint(d.threshold))
+		if 0 not in thresholds:
+			frappe.throw(_("Please define grade for treshold 0%"))
\ No newline at end of file
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/schools/doctype/grading_scale/test_grading_scale.py
similarity index 64%
copy from erpnext/schools/doctype/assessment/test_assessment.py
copy to erpnext/schools/doctype/grading_scale/test_grading_scale.py
index ce06007..5364d7c 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/schools/doctype/grading_scale/test_grading_scale.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Grading Scale')
 
-class TestAssessment(unittest.TestCase):
+class TestGradingScale(unittest.TestCase):
 	pass
diff --git a/erpnext/schools/doctype/grading_scale/test_records.json b/erpnext/schools/doctype/grading_scale/test_records.json
new file mode 100644
index 0000000..72b6954
--- /dev/null
+++ b/erpnext/schools/doctype/grading_scale/test_records.json
@@ -0,0 +1,19 @@
+[
+ {
+  "grading_scale_name": "_Test Grading Scale",
+  "intervals": [
+      {
+         "grade_code": "A",
+         "threshold": 75
+      },
+      {
+          "grade_code": "B",
+          "threshold": 50
+      },
+      {
+          "grade_code": "C",
+          "threshold": 0
+      }
+  ]
+ }
+]
\ No newline at end of file
diff --git a/erpnext/schools/doctype/announcement/__init__.py b/erpnext/schools/doctype/grading_scale_interval/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/announcement/__init__.py
copy to erpnext/schools/doctype/grading_scale_interval/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.json
similarity index 60%
copy from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
copy to erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.json
index 6b80efc..10b229c 100644
--- a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.json
@@ -3,36 +3,38 @@
  "allow_import": 0, 
  "allow_rename": 0, 
  "beta": 0, 
- "creation": "2016-09-03 19:20:14.561962", 
+ "creation": "2016-08-26 03:11:09.591049", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
+ "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "service_item", 
-   "fieldtype": "Select", 
+   "fieldname": "grade_code", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Service Item", 
+   "in_standard_filter": 0, 
+   "label": "Grade Code", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
    "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, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -42,24 +44,26 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
+   "default": "0", 
+   "fieldname": "threshold", 
+   "fieldtype": "Percent", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Type", 
+   "in_standard_filter": 0, 
+   "label": "Threshold", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nInspection\nService\nChange", 
    "permlevel": 0, 
-   "precision": "", 
+   "precision": "1", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
-   "reqd": 0, 
+   "reqd": 1, 
    "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
@@ -69,41 +73,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "frequency", 
-   "fieldtype": "Select", 
+   "fieldname": "grade_description", 
+   "fieldtype": "Small Text", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Frequency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "expense_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Expense", 
+   "in_standard_filter": 0, 
+   "label": "Grade Description", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -111,6 +89,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, 
@@ -128,10 +107,10 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-20 07:29:50.852748", 
+ "modified": "2017-01-04 15:27:56.729286", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle Service", 
+ "module": "Schools", 
+ "name": "Grading Scale Interval", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [], 
@@ -140,5 +119,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.py b/erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.py
new file mode 100644
index 0000000..41ac5ff
--- /dev/null
+++ b/erpnext/schools/doctype/grading_scale_interval/grading_scale_interval.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class GradingScaleInterval(Document):
+	pass
diff --git a/erpnext/schools/doctype/grading_structure/grading_structure.json b/erpnext/schools/doctype/grading_structure/grading_structure.json
index cda6bd4..3c30f29 100644
--- a/erpnext/schools/doctype/grading_structure/grading_structure.json
+++ b/erpnext/schools/doctype/grading_structure/grading_structure.json
@@ -10,11 +10,13 @@
  "doctype": "DocType", 
  "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grading_system_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -22,6 +24,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Grading System Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -30,6 +33,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -40,6 +44,34 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "description", 
    "fieldtype": "Text", 
    "hidden": 0, 
@@ -47,6 +79,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -55,6 +88,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, 
@@ -65,30 +99,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "column_break_3", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grading_intervals_section", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -96,6 +107,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Grading Intervals", 
    "length": 0, 
    "no_copy": 0, 
@@ -104,6 +116,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, 
@@ -114,6 +127,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "grade_intervals", 
    "fieldtype": "Table", 
    "hidden": 0, 
@@ -121,6 +135,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Grade Intervals", 
    "length": 0, 
    "no_copy": 0, 
@@ -130,6 +145,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -147,7 +163,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-08-27 14:20:50.709823", 
+ "modified": "2016-12-14 12:35:39.690256", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Grading Structure", 
@@ -164,6 +180,7 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
+   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
diff --git a/erpnext/schools/doctype/guardian/guardian.json b/erpnext/schools/doctype/guardian/guardian.json
index 8368f4a..6f5e25d 100644
--- a/erpnext/schools/doctype/guardian/guardian.json
+++ b/erpnext/schools/doctype/guardian/guardian.json
@@ -129,14 +129,15 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "column_break_3", 
-   "fieldtype": "Column Break", 
+   "fieldname": "date_of_birth", 
+   "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Date of Birth", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -156,15 +157,14 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "date_of_birth", 
-   "fieldtype": "Date", 
+   "fieldname": "column_break_3", 
+   "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
-   "label": "Date of Birth", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -268,61 +268,6 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "image", 
-   "fieldtype": "Attach Image", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Image", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "section_break_9", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "work_address", 
    "fieldtype": "Text", 
    "hidden": 0, 
@@ -351,6 +296,91 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "image", 
+   "fieldtype": "Attach Image", 
+   "hidden": 1, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Image", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "section_break_13", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Guardian Of ", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "students", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Students", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Guardian Student", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_8", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -359,6 +389,7 @@
    "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
+   "label": "Guardian Interests", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -414,7 +445,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-28 16:14:58.836437", 
+ "modified": "2017-01-31 16:47:23.436075", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Guardian", 
@@ -431,7 +462,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -449,5 +479,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "guardian_name", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/guardian/guardian.py b/erpnext/schools/doctype/guardian/guardian.py
index 1388cfe..38597f0 100644
--- a/erpnext/schools/doctype/guardian/guardian.py
+++ b/erpnext/schools/doctype/guardian/guardian.py
@@ -7,4 +7,22 @@
 from frappe.model.document import Document
 
 class Guardian(Document):
-	pass
+	def __setup__(self):
+		self.onload()
+
+	def onload(self):
+		"""Load Students for quick view"""
+		self.load_students()
+
+	def load_students(self):
+		"""Load `students` from the database"""
+		self.students = []
+		students = frappe.get_all("Student Guardian", filters={"guardian":self.name}, fields=["parent"])
+		for student in students:
+			self.append("students", {
+				"student":student.parent,
+				"student_name": frappe.db.get_value("Student", student.parent, "title")
+			})
+
+	def validate(self):
+		self.students = []
\ No newline at end of file
diff --git a/erpnext/schools/doctype/announcement/__init__.py b/erpnext/schools/doctype/guardian_student/__init__.py
similarity index 100%
copy from erpnext/schools/doctype/announcement/__init__.py
copy to erpnext/schools/doctype/guardian_student/__init__.py
diff --git a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json b/erpnext/schools/doctype/guardian_student/guardian_student.json
similarity index 60%
copy from erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
copy to erpnext/schools/doctype/guardian_student/guardian_student.json
index 6b80efc..948ed70 100644
--- a/erpnext/fleet_management/doctype/vehicle_service/vehicle_service.json
+++ b/erpnext/schools/doctype/guardian_student/guardian_student.json
@@ -3,34 +3,37 @@
  "allow_import": 0, 
  "allow_rename": 0, 
  "beta": 0, 
- "creation": "2016-09-03 19:20:14.561962", 
+ "creation": "2017-01-31 11:53:21.580099", 
  "custom": 0, 
  "docstatus": 0, 
  "doctype": "DocType", 
- "document_type": "Document", 
+ "document_type": "", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "service_item", 
-   "fieldtype": "Select", 
+   "fieldname": "student", 
+   "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Service Item", 
+   "in_standard_filter": 0, 
+   "label": "Student", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nBrake Oil\nBrake Pad\nClutch Plate\nEngine Oil\nOil Change\nWheels", 
+   "options": "Student", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -42,22 +45,22 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "type", 
-   "fieldtype": "Select", 
+   "fieldname": "column_break_2", 
+   "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Type", 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
-   "options": "\nInspection\nService\nChange", 
    "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, 
@@ -69,48 +72,23 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "fieldname": "frequency", 
-   "fieldtype": "Select", 
+   "fieldname": "student_name", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
-   "label": "Frequency", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "\nMileage\nMonthly\nQuarterly\nHalf Yearly\nYearly", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "expense_amount", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Expense", 
+   "in_standard_filter": 0, 
+   "label": "Student Name", 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
-   "read_only": 0, 
+   "read_only": 1, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 0, 
    "search_index": 0, 
@@ -128,10 +106,10 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-20 07:29:50.852748", 
+ "modified": "2017-01-31 16:40:26.551040", 
  "modified_by": "Administrator", 
- "module": "Fleet Management", 
- "name": "Vehicle Service", 
+ "module": "Schools", 
+ "name": "Guardian Student", 
  "name_case": "", 
  "owner": "Administrator", 
  "permissions": [], 
@@ -140,5 +118,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/guardian_student/guardian_student.py b/erpnext/schools/doctype/guardian_student/guardian_student.py
new file mode 100644
index 0000000..bf6f5c1
--- /dev/null
+++ b/erpnext/schools/doctype/guardian_student/guardian_student.py
@@ -0,0 +1,10 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class GuardianStudent(Document):
+	pass
diff --git a/erpnext/schools/doctype/student/student.js b/erpnext/schools/doctype/student/student.js
index e69de29..10fefae 100644
--- a/erpnext/schools/doctype/student/student.js
+++ b/erpnext/schools/doctype/student/student.js
@@ -0,0 +1 @@
+cur_frm.add_fetch("guardian", "guardian_name", "guardian_name");
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student/student.json b/erpnext/schools/doctype/student/student.json
index edaae07..ff33051 100644
--- a/erpnext/schools/doctype/student/student.json
+++ b/erpnext/schools/doctype/student/student.json
@@ -472,6 +472,63 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "section_break_18", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Guardian Details", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "guardians", 
+   "fieldtype": "Table", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Guardians", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "Student Guardian", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "section_break_22", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -667,63 +724,6 @@
    "bold": 0, 
    "collapsible": 1, 
    "columns": 0, 
-   "fieldname": "section_break_18", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Guardian Details", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "guardians", 
-   "fieldtype": "Table", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Guardians", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Student Guardian", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 1, 
-   "columns": 0, 
    "fieldname": "section_break_20", 
    "fieldtype": "Section Break", 
    "hidden": 0, 
@@ -780,6 +780,145 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
+   "collapsible": 1, 
+   "columns": 0, 
+   "fieldname": "exit", 
+   "fieldtype": "Section Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Exit", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "date_of_leaving", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Date of Leaving", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "leaving_certificate_number", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Leaving Certificate Number", 
+   "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "column_break_31", 
+   "fieldtype": "Column Break", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "reason_for_leaving", 
+   "fieldtype": "Text", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Reason For Leaving", 
+   "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_on_submit": 0, 
+   "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
    "default": "", 
@@ -819,7 +958,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-12-01 12:55:32.453131", 
+ "modified": "2017-02-12 01:17:09.872249", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student", 
@@ -836,7 +975,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -856,8 +994,7 @@
    "email": 1, 
    "export": 1, 
    "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
+   "import": 1, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -875,5 +1012,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "title", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student/student.py b/erpnext/schools/doctype/student/student.py
index a34bb6a..b660bb3 100644
--- a/erpnext/schools/doctype/student/student.py
+++ b/erpnext/schools/doctype/student/student.py
@@ -5,9 +5,9 @@
 from __future__ import unicode_literals
 import frappe
 from frappe.model.document import Document
+from frappe import _
 
 class Student(Document):
-
 	def validate(self):
 		self.title = " ".join(filter(None, [self.first_name, self.middle_name, self.last_name]))
 
@@ -19,7 +19,7 @@
 		"""Validates if the Student Applicant is Unique"""
 		student = frappe.db.sql("select name from `tabStudent` where student_applicant=%s and name!=%s", (self.student_applicant, self.name))
 		if student:
-			frappe.throw("Student {0} exist against student applicant {1}".format(student[0][0], self.student_applicant))
+			frappe.throw(_("Student {0} exist against student applicant {1}").format(student[0][0], self.student_applicant))
 
 	def update_applicant_status(self):
 		"""Updates Student Applicant status to Admitted"""
@@ -28,10 +28,9 @@
 
 def get_timeline_data(doctype, name):
 	'''Return timeline for attendance'''
-	return dict(frappe.db.sql('''select unix_timestamp(cs.schedule_date), count(*)
-		from `tabCourse Schedule` as cs , `tabStudent Attendance` as sa where
-			sa.course_schedule = cs.name
-			and sa.student=%s
-			and cs.schedule_date > date_sub(curdate(), interval 1 year)
+	return dict(frappe.db.sql('''select unix_timestamp(`date`), count(*)
+		from `tabStudent Attendance` where
+			student=%s
+			and `date` > date_sub(curdate(), interval 1 year)
 			and status = 'Present'
-			group by cs.schedule_date''', name))
+			group by date''', name))
diff --git a/erpnext/schools/doctype/student/student_dashboard.py b/erpnext/schools/doctype/student/student_dashboard.py
index 8b5fb41..ca2a660 100644
--- a/erpnext/schools/doctype/student/student_dashboard.py
+++ b/erpnext/schools/doctype/student/student_dashboard.py
@@ -10,7 +10,7 @@
 				'items': ['Student Log', 'Student Batch', 'Student Group', 'Program Enrollment']
 			},
 			{
-				'items': ['Fees', 'Assessment', 'Student Attendance', 'Student Leave Application']
+				'items': ['Fees', 'Assessment Result', 'Student Attendance', 'Student Leave Application']
 			}
 		]
 	}
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_applicant/student_applicant.json b/erpnext/schools/doctype/student_applicant/student_applicant.json
index 2c6947c..c9f5af3 100644
--- a/erpnext/schools/doctype/student_applicant/student_applicant.json
+++ b/erpnext/schools/doctype/student_applicant/student_applicant.json
@@ -560,7 +560,7 @@
    "collapsible": 0, 
    "columns": 0, 
    "fieldname": "nationality", 
-   "fieldtype": "Link", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
@@ -570,7 +570,7 @@
    "label": "Nationality", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "Country", 
+   "options": "", 
    "permlevel": 0, 
    "precision": "", 
    "print_hide": 0, 
@@ -988,7 +988,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-11-17 10:26:13.225135", 
+ "modified": "2017-02-12 01:27:56.600827", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Applicant", 
@@ -1005,7 +1005,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 1, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1023,5 +1022,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "title", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_attendance/student_attendance.py b/erpnext/schools/doctype/student_attendance/student_attendance.py
index e2d01b5..8e806e4 100644
--- a/erpnext/schools/doctype/student_attendance/student_attendance.py
+++ b/erpnext/schools/doctype/student_attendance/student_attendance.py
@@ -6,11 +6,15 @@
 import frappe
 from frappe.model.document import Document
 from frappe import _
+from erpnext.schools.api import get_student_batch_students, get_student_group_students
+
 
 class StudentAttendance(Document):
 	def validate(self):
 		self.validate_date()
 		self.validate_mandatory()
+		self.validate_course_schedule()
+		self.validate_student()
 		self.validate_duplication()
 		
 	def validate_date(self):
@@ -21,9 +25,27 @@
 		if not (self.student_batch or self.course_schedule):
 			frappe.throw(_("""Student Batch or Course Schedule is mandatory"""))
 	
+	def validate_course_schedule(self):
+		if self.course_schedule:
+			self.student_batch = frappe.db.get_value("Course Schedule", self.course_schedule, "student_batch")
+	
+	def validate_student(self):
+		if self.course_schedule:
+			student_group = frappe.db.get_value("Course Schedule", self.course_schedule, "student_group")
+			student_group_students = []
+			for d in get_student_group_students(student_group):
+				student_group_students.append(d.student)
+			if student_group and self.student not in student_group_students:
+				frappe.throw(_("""Student {0}: {1} does not belong to Student Group {2}""".format(self.student, self.student_name, student_group)))
+		else:
+			student_batch_students = []
+			for d in get_student_batch_students(self.student_batch):
+				student_batch_students.append(d.student)
+			if self.student not in student_batch_students:
+				frappe.throw(_("""Student {0}: {1} does not belong to Student Batch {2}""".format(self.student, self.student_name, self.student_batch)))
+
 	def validate_duplication(self):
 		"""Check if the Attendance Record is Unique"""
-		
 		attendance_records=None
 		if self.course_schedule:
 			attendance_records= frappe.db.sql("""select name from `tabStudent Attendance` where \
diff --git a/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py
index 30a692c..58588a9 100644
--- a/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py
+++ b/erpnext/schools/doctype/student_attendance_tool/student_attendance_tool.py
@@ -18,11 +18,12 @@
 		student_group = frappe.db.get_value("Course Schedule", course_schedule, "student_group")
 		if student_group:
 			student_list = frappe.get_list("Student Group Student", fields=["student", "student_name", "idx"] , \
-			filters={"parent": student_group}, order_by= "idx")
+			filters={"parent": student_group, "active": 1}, order_by= "idx")
 		else:
 			student_batch = frappe.db.get_value("Course Schedule", course_schedule, "student_batch")
 	if not student_list: 
-		student_list = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , filters={"parent": student_batch}, order_by= "idx")
+		student_list = frappe.get_list("Student Batch Student", fields=["student", "student_name", "idx"] , 
+			filters={"parent": student_batch, "active": 1}, order_by= "idx")
 	
 	if course_schedule:
 		student_attendance_list= frappe.db.sql("""select student, status from `tabStudent Attendance` where \
diff --git a/erpnext/schools/doctype/student_batch/student_batch.js b/erpnext/schools/doctype/student_batch/student_batch.js
index 931e41b..7fad5d7 100644
--- a/erpnext/schools/doctype/student_batch/student_batch.js
+++ b/erpnext/schools/doctype/student_batch/student_batch.js
@@ -3,7 +3,23 @@
 
 frappe.ui.form.on('Student Batch', {
 	refresh: function(frm) {
-
+		if (!frm.doc.__islocal) {
+			frm.add_custom_button(__("Update Email Group"), function() {
+				frappe.call({
+					method: "erpnext.schools.api.update_email_group",
+					args: {
+						"doctype": "Student Batch",
+						"name": frm.doc.name
+					}
+				});
+			});
+			frm.add_custom_button(__("Newsletter"), function() {
+				frappe.route_options = {
+					email_group: frm.doc.name
+				}
+				frappe.set_route("List", "Newsletter");
+			});
+		}
 	},
 	
 	onload: function(frm){
diff --git a/erpnext/schools/doctype/student_batch/student_batch.json b/erpnext/schools/doctype/student_batch/student_batch.json
index f571d9d..4909ff0 100644
--- a/erpnext/schools/doctype/student_batch/student_batch.json
+++ b/erpnext/schools/doctype/student_batch/student_batch.json
@@ -1,7 +1,7 @@
 {
  "allow_copy": 0, 
- "allow_import": 0, 
- "allow_rename": 0, 
+ "allow_import": 1, 
+ "allow_rename": 1, 
  "autoname": "", 
  "beta": 0, 
  "creation": "2016-07-21 15:49:53.776461", 
@@ -22,7 +22,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Student Batch Name", 
@@ -51,7 +50,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Academic Year", 
@@ -81,7 +79,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Active", 
@@ -109,7 +106,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -136,7 +132,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Program", 
@@ -165,7 +160,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 1, 
    "label": "Academic Term", 
@@ -194,7 +188,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Students", 
@@ -222,7 +215,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Students", 
@@ -251,7 +243,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Instructors", 
@@ -279,7 +270,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Instructors", 
@@ -309,7 +299,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-12-01 13:18:12.024001", 
+ "modified": "2017-02-03 05:19:35.037148", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Batch", 
@@ -325,8 +315,7 @@
    "email": 1, 
    "export": 1, 
    "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
+   "import": 1, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -347,7 +336,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -365,5 +353,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_batch/student_batch.py b/erpnext/schools/doctype/student_batch/student_batch.py
index 1a0d799..9c0f3d7 100644
--- a/erpnext/schools/doctype/student_batch/student_batch.py
+++ b/erpnext/schools/doctype/student_batch/student_batch.py
@@ -6,6 +6,7 @@
 from frappe.model.document import Document
 from erpnext.schools.utils import validate_duplicate_student
 import frappe
+from frappe import _
 
 class StudentBatch(Document):
 	def autoname(self):
@@ -16,3 +17,8 @@
 		
 	def validate(self):
 		validate_duplicate_student(self.students)
+		self.validate_name()
+		
+	def validate_name(self):
+		if frappe.db.exists("Student Group", self.name):
+			frappe.throw(_("""Student Group exists with same name"""))
diff --git a/erpnext/schools/doctype/student_batch_student/student_batch_student.json b/erpnext/schools/doctype/student_batch_student/student_batch_student.json
index c9b1b01..3558cc8 100644
--- a/erpnext/schools/doctype/student_batch_student/student_batch_student.json
+++ b/erpnext/schools/doctype/student_batch_student/student_batch_student.json
@@ -14,13 +14,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student", 
    "fieldtype": "Link", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Student", 
    "length": 0, 
    "no_copy": 0, 
@@ -30,6 +31,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -40,13 +42,14 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -54,6 +57,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, 
@@ -64,22 +68,52 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Student Name", 
    "length": 0, 
    "no_copy": 0, 
-   "options": "", 
+   "options": "student.title", 
    "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "1", 
+   "fieldname": "active", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Active", 
+   "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, 
@@ -97,7 +131,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-22 03:27:52.913126", 
+ "modified": "2017-02-03 05:26:35.518004", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Batch Student", 
@@ -109,5 +143,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_group/student_group.js b/erpnext/schools/doctype/student_group/student_group.js
index 6f4084b..1dcbc3a 100644
--- a/erpnext/schools/doctype/student_group/student_group.js
+++ b/erpnext/schools/doctype/student_group/student_group.js
@@ -1,33 +1,48 @@
 cur_frm.add_fetch("student", "title", "student_name");
 
 frappe.ui.form.on("Student Group", {
-    refresh: function(frm) {
-        if (!frm.doc.__islocal) {
-            frm.add_custom_button(__("Course Schedule"), function() {
-                frappe.route_options = {
-                    student_group: frm.doc.name
-                }
-                frappe.set_route("List", "Course Schedule");
-            });
+	refresh: function(frm) {
+		if (!frm.doc.__islocal) {
+			frm.add_custom_button(__("Course Schedule"), function() {
+				frappe.route_options = {
+					student_group: frm.doc.name
+				}
+				frappe.set_route("List", "Course Schedule");
+			});
 
-            frm.add_custom_button(__("Assessment"), function() {
-                frappe.route_options = {
-                    student_group: frm.doc.name
-                }
-                frappe.set_route("List", "Assessment");
-            });
-        }
-    },
+			frm.add_custom_button(__("Assessment Plan"), function() {
+				frappe.route_options = {
+					student_group: frm.doc.name
+				}
+				frappe.set_route("List", "Assessment Plan");
+			});
+			frm.add_custom_button(__("Update Email Group"), function() {
+				frappe.call({
+					method: "erpnext.schools.api.update_email_group",
+					args: {
+						"doctype": "Student Group",
+						"name": frm.doc.name
+					}
+				});
+			});
+			frm.add_custom_button(__("Newsletter"), function() {
+				frappe.route_options = {
+					email_group: frm.doc.name
+				}
+				frappe.set_route("List", "Newsletter");
+			});
+		}
+	},
 
-    onload: function(frm) {
-        cur_frm.set_query("academic_term", function() {
-            return {
-                "filters": {
-                    "academic_year": (frm.doc.academic_year)
-                }
-            };
-        });
-    }
+	onload: function(frm) {
+		frm.set_query("academic_term", function() {
+			return {
+				"filters": {
+					"academic_year": (frm.doc.academic_year)
+				}
+			};
+		});
+	}
 });
 
 //If Student Batch is entered, deduce program, academic_year and academic term from it
diff --git a/erpnext/schools/doctype/student_group/student_group.json b/erpnext/schools/doctype/student_group/student_group.json
index 9e44f51..01e161e 100644
--- a/erpnext/schools/doctype/student_group/student_group.json
+++ b/erpnext/schools/doctype/student_group/student_group.json
@@ -216,7 +216,7 @@
   {
    "allow_on_submit": 0, 
    "bold": 0, 
-   "collapsible": 1, 
+   "collapsible": 0, 
    "collapsible_depends_on": "", 
    "columns": 0, 
    "fieldname": "section_break_6", 
@@ -311,7 +311,7 @@
  "istable": 0, 
  "max_attachments": 0, 
  "menu_index": 0, 
- "modified": "2016-12-01 12:57:17.125085", 
+ "modified": "2017-01-27 14:50:36.107270", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Group", 
@@ -328,7 +328,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -349,7 +348,6 @@
    "export": 1, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -368,5 +366,6 @@
  "sort_field": "modified", 
  "sort_order": "DESC", 
  "title_field": "", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_group/student_group.py b/erpnext/schools/doctype/student_group/student_group.py
index f604773..996f518 100644
--- a/erpnext/schools/doctype/student_group/student_group.py
+++ b/erpnext/schools/doctype/student_group/student_group.py
@@ -7,6 +7,7 @@
 from frappe.model.document import Document
 from frappe import _
 from erpnext.schools.utils import validate_duplicate_student
+from erpnext.schools.api import get_student_batch_students
 
 class StudentGroup(Document):
 	def autoname(self):
@@ -29,6 +30,9 @@
 	def validate(self):
 		self.validate_strength()
 		self.validate_student_name()
+		self.validate_name()
+		if self.student_batch:
+			self.validate_student_batch()
 		validate_duplicate_student(self.students)
 
 	def validate_strength(self):
@@ -39,4 +43,14 @@
 		for d in self.students:
 			d.student_name = frappe.db.get_value("Student", d.student, "title")
 	
-	
\ No newline at end of file
+	def validate_name(self):
+		if frappe.db.exists("Student Batch", self.name):
+			frappe.throw(_("""Student Batch exists with same name"""))
+
+	def validate_student_batch(self):
+		student_batch_students = []
+		for d in get_student_batch_students(self.student_batch):
+			student_batch_students.append(d.student)
+		for d in self.students:
+			if d.student not in student_batch_students:
+				frappe.throw(_("""Student {0}: {1} does not belong to Student Batch {2}""".format(d.student, d.student_name, self.student_batch)))
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_group_student/student_group_student.json b/erpnext/schools/doctype/student_group_student/student_group_student.json
index 94493ae..5ca7b66 100644
--- a/erpnext/schools/doctype/student_group_student/student_group_student.json
+++ b/erpnext/schools/doctype/student_group_student/student_group_student.json
@@ -14,6 +14,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -21,6 +22,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Student", 
    "length": 0, 
    "no_copy": 0, 
@@ -30,6 +32,7 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -40,6 +43,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "column_break_2", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -47,6 +51,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -54,6 +59,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, 
@@ -64,6 +70,7 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "student_name", 
    "fieldtype": "Data", 
    "hidden": 0, 
@@ -71,6 +78,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Student Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -79,6 +87,36 @@
    "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_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "default": "1", 
+   "fieldname": "active", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Active", 
+   "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, 
@@ -96,7 +134,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-07-21 12:27:02.479077", 
+ "modified": "2017-01-27 14:49:54.533005", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Group Student", 
@@ -108,5 +146,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/student_guardian/student_guardian.json b/erpnext/schools/doctype/student_guardian/student_guardian.json
index d8e50c9..0a41538 100644
--- a/erpnext/schools/doctype/student_guardian/student_guardian.json
+++ b/erpnext/schools/doctype/student_guardian/student_guardian.json
@@ -22,6 +22,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Guardian", 
    "length": 0, 
    "no_copy": 0, 
@@ -31,6 +32,35 @@
    "print_hide": 0, 
    "print_hide_if_no_value": 0, 
    "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }, 
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "guardian_name", 
+   "fieldtype": "Data", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Guardian Name", 
+   "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": 1, 
    "search_index": 0, 
@@ -49,6 +79,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Relation", 
    "length": 0, 
    "no_copy": 0, 
@@ -58,6 +89,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, 
@@ -75,7 +107,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-09-01 14:39:03.576590", 
+ "modified": "2017-01-27 13:36:47.177809", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "Student Guardian", 
@@ -87,5 +119,6 @@
  "read_only_onload": 0, 
  "sort_field": "modified", 
  "sort_order": "DESC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/schools/doctype/topic/__init__.py b/erpnext/schools/doctype/topic/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/schools/doctype/topic/__init__.py
+++ /dev/null
diff --git a/erpnext/schools/doctype/topic/test_topic.py b/erpnext/schools/doctype/topic/test_topic.py
deleted file mode 100644
index 1d2974e..0000000
--- a/erpnext/schools/doctype/topic/test_topic.py
+++ /dev/null
@@ -1,12 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and Contributors
-# See license.txt
-from __future__ import unicode_literals
-
-import frappe
-import unittest
-
-# test_records = frappe.get_test_records('Topic')
-
-class TestTopic(unittest.TestCase):
-	pass
diff --git a/erpnext/schools/doctype/topic/topic.js b/erpnext/schools/doctype/topic/topic.js
deleted file mode 100644
index bd9379d..0000000
--- a/erpnext/schools/doctype/topic/topic.js
+++ /dev/null
@@ -1,8 +0,0 @@
-// Copyright (c) 2016, Frappe and contributors
-// For license information, please see license.txt
-
-frappe.ui.form.on('Topic', {
-	refresh: function(frm) {
-
-	}
-});
diff --git a/erpnext/schools/doctype/topic/topic.py b/erpnext/schools/doctype/topic/topic.py
deleted file mode 100644
index 5dba561..0000000
--- a/erpnext/schools/doctype/topic/topic.py
+++ /dev/null
@@ -1,49 +0,0 @@
-# -*- coding: utf-8 -*-
-# Copyright (c) 2015, Frappe and contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.model.document import Document
-from frappe import _
-
-class Topic(Document):
-	pass
-
-def get_topic_list(doctype, txt, filters, limit_start, limit_page_length=20):
-	user = frappe.session.user
-	student = frappe.db.sql("select name from `tabStudent` where student_email_id= %s", user)
-	if student:
-		data = frappe. db.sql('''select name, course, modified,topic_name, introduction, content from `tabTopic` as topic
-								where topic.course = %s 
-								order by idx asc limit {0} , {1}'''.format(limit_start, limit_page_length),filters.course,as_dict = True)
-		
-		for topic in data:
-			try:
-				num_attachments = frappe.db.sql(""" select count(file_url) from tabFile as file
-													where file.attached_to_name=%s 
-													and file.attached_to_doctype=%s""",(topic.name,"Topic"))
-
-			except IOError or frappe.DoesNotExistError:
-				pass
-				frappe.local.message_log.pop()
-
-			topic.num_attachments = num_attachments[0][0]
-
-		return data
-
-def get_list_context(context=None):
-	course = frappe.get_doc('Course', frappe.form_dict.course)
-	portal_items = [{'reference_doctype': u'Topic', 'route': u"/topic?course=" + str(course.name), 'show_always': 0L, 'title': u'Topics'},
-				{'reference_doctype': u'Discussion', 'route': u"/discussion?course=" + str(course.name), 'show_always': 0L, 'title': u'Discussions'},
-
-	]
-	return {
-		"show_sidebar": True,
-		"title": _("Topic"),
-		'no_breadcrumbs': True,
-		"sidebar_items" : portal_items,
-		"sidebar_title" : course.name,
-		"get_list": get_topic_list,
-		"row_template": "templates/includes/topic/topic_row.html"
-	}
\ No newline at end of file
diff --git a/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py
index c112b59..b6bedcb 100644
--- a/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py
+++ b/erpnext/schools/report/student_batch_wise_attendance/student_batch_wise_attendance.py
@@ -53,7 +53,7 @@
 
 def get_student_batch_strength(student_batch):
 	student_batch_strength = frappe.db.sql("""select count(*) from `tabStudent Batch Student` 
-		where parent = %s""", student_batch)[0][0]
+		where parent = %s and active=1""", student_batch)[0][0]
 	return student_batch_strength
 
 def get_student_attendance(student_batch, date):
diff --git a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
index cd2c82c..01cee58 100644
--- a/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
+++ b/erpnext/schools/report/student_monthly_attendance_sheet/student_monthly_attendance_sheet.py
@@ -61,7 +61,7 @@
 	students_with_leave_application = get_students_with_leave_application(from_date, to_date, students_list)
 	for d in attendance_list:
 		att_map.setdefault(d.student, frappe._dict()).setdefault(d.date, "")
-		if students_with_leave_application and d.student in students_with_leave_application.get(d.date,[]):
+		if students_with_leave_application and d.student in students_with_leave_application.get(d.date):
 			att_map[d.student][d.date] = "Present"
 		else:
 			att_map[d.student][d.date] = d.status
diff --git a/erpnext/schools/web_form/student_applicant/student_applicant.json b/erpnext/schools/web_form/student_applicant/student_applicant.json
index c28958a..1feb159 100644
--- a/erpnext/schools/web_form/student_applicant/student_applicant.json
+++ b/erpnext/schools/web_form/student_applicant/student_applicant.json
@@ -1,22 +1,30 @@
 {
+ "accept_payment": 0, 
  "allow_comments": 0, 
  "allow_delete": 0, 
  "allow_edit": 1, 
+ "allow_incomplete": 0, 
  "allow_multiple": 1, 
- "creation": "2016-09-12 02:26:42.447103", 
+ "allow_print": 0, 
+ "amount": 0.0, 
+ "amount_based_on_field": 0, 
+ "creation": "2016-09-22 13:10:10.792735", 
  "doc_type": "Student Applicant", 
  "docstatus": 0, 
  "doctype": "Web Form", 
  "idx": 0, 
  "is_standard": 1, 
  "login_required": 1, 
- "modified": "2016-09-15 02:00:28.493759", 
+ "max_attachment_size": 0, 
+ "modified": "2017-02-12 01:28:57.997942", 
  "modified_by": "Administrator", 
  "module": "Schools", 
  "name": "student-applicant", 
  "owner": "Administrator", 
+ "payment_button_label": "Buy Now", 
  "published": 1, 
  "route": "student-applicant", 
+ "show_sidebar": 1, 
  "sidebar_items": [], 
  "success_url": "/student-applicant", 
  "title": "Student Applicant", 
@@ -26,6 +34,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "First Name", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 1
   }, 
@@ -34,6 +44,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Middle Name", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -42,6 +54,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Last Name", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -50,6 +64,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Image", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -58,6 +74,8 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "label": "Program", 
+   "max_length": 0, 
+   "max_value": 0, 
    "options": "Program", 
    "read_only": 0, 
    "reqd": 1
@@ -67,6 +85,8 @@
    "fieldtype": "Link", 
    "hidden": 0, 
    "label": "Academic Year", 
+   "max_length": 0, 
+   "max_value": 0, 
    "options": "Academic Year", 
    "read_only": 0, 
    "reqd": 0
@@ -76,6 +96,8 @@
    "fieldtype": "Date", 
    "hidden": 0, 
    "label": "Date of Birth", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -84,6 +106,8 @@
    "fieldtype": "Select", 
    "hidden": 0, 
    "label": "Blood Group", 
+   "max_length": 0, 
+   "max_value": 0, 
    "options": "\nA+\nA-\nB+\nB-\nO+\nO-\nAB+\nAB-", 
    "read_only": 0, 
    "reqd": 0
@@ -92,7 +116,9 @@
    "fieldname": "student_email_id", 
    "fieldtype": "Data", 
    "hidden": 0, 
-   "label": "Student Email Address", 
+   "label": "Student Email ID", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -101,15 +127,19 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Student Mobile Number", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
   {
    "fieldname": "nationality", 
-   "fieldtype": "Link", 
+   "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Nationality", 
-   "options": "Country", 
+   "max_length": 0, 
+   "max_value": 0, 
+   "options": "", 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -118,6 +148,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Address Line 1", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -126,6 +158,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Address Line 2", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -134,6 +168,8 @@
    "fieldtype": "Data", 
    "hidden": 0, 
    "label": "Pincode", 
+   "max_length": 0, 
+   "max_value": 0, 
    "read_only": 0, 
    "reqd": 0
   }, 
@@ -142,6 +178,8 @@
    "fieldtype": "Table", 
    "hidden": 0, 
    "label": "Guardians", 
+   "max_length": 0, 
+   "max_value": 0, 
    "options": "Student Guardian", 
    "read_only": 0, 
    "reqd": 0
@@ -151,6 +189,8 @@
    "fieldtype": "Table", 
    "hidden": 0, 
    "label": "Siblings", 
+   "max_length": 0, 
+   "max_value": 0, 
    "options": "Student Sibling", 
    "read_only": 0, 
    "reqd": 0
diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js
index ea88e8b..540ec28 100644
--- a/erpnext/selling/doctype/customer/customer.js
+++ b/erpnext/selling/doctype/customer/customer.js
@@ -32,10 +32,12 @@
 			erpnext.toggle_naming_series();
 		}
 
+		frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Customer'}
+
 		frm.toggle_display(['address_html','contact_html'], !frm.doc.__islocal);
 
 		if(!frm.doc.__islocal) {
-			erpnext.utils.render_address_and_contact(frm);
+			frappe.geo.render_address_and_contact(frm);
 
 			// custom buttons
 			frm.add_custom_button(__('Accounting Ledger'), function() {
@@ -51,7 +53,7 @@
 			erpnext.utils.set_party_dashboard_indicators(frm);
 
 		} else {
-			erpnext.utils.clear_address_and_contact(frm);
+			frappe.geo.clear_address_and_contact(frm);
 		}
 
 		var grid = cur_frm.get_field("sales_team").grid;
diff --git a/erpnext/selling/doctype/customer/customer.json b/erpnext/selling/doctype/customer/customer.json
index 77cc624..81e17a6 100644
--- a/erpnext/selling/doctype/customer/customer.json
+++ b/erpnext/selling/doctype/customer/customer.json
@@ -23,7 +23,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Name and Type", 
@@ -52,7 +51,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Series", 
@@ -80,7 +78,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Full Name", 
@@ -109,7 +106,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Type", 
@@ -139,7 +135,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "From Lead", 
@@ -169,7 +164,6 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Image", 
@@ -192,42 +186,11 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
-   "default": "Active", 
-   "fieldname": "status", 
-   "fieldtype": "Select", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Status", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Active\nDormant\nOpen", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
    "fieldname": "column_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -255,7 +218,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Customer Group", 
@@ -286,7 +248,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 1, 
    "in_standard_filter": 1, 
    "label": "Territory", 
@@ -316,7 +277,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Tax ID", 
@@ -345,7 +305,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Disabled", 
@@ -373,7 +332,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Currency and Price List", 
@@ -401,7 +359,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Billing Currency", 
@@ -429,7 +386,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Default Price List", 
@@ -457,7 +413,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -484,7 +439,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Print Language", 
@@ -514,7 +468,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Address and Contact", 
@@ -542,7 +495,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Address HTML", 
@@ -569,7 +521,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Website", 
@@ -596,7 +547,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "length": 0, 
@@ -623,7 +573,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Contact HTML", 
@@ -652,7 +601,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Accounting", 
@@ -681,7 +629,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Accounts", 
@@ -710,7 +657,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Credit Limit", 
@@ -738,7 +684,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Credit Days Based On", 
@@ -768,7 +713,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Credit Days", 
@@ -797,7 +741,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Credit Limit", 
@@ -828,7 +771,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "More Information", 
@@ -858,7 +800,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Customer Details", 
@@ -887,7 +828,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Is Frozen", 
@@ -916,7 +856,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Partner and Commission", 
@@ -945,7 +884,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Partner", 
@@ -975,7 +913,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Commission Rate", 
@@ -1005,7 +942,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Team", 
@@ -1033,7 +969,6 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Sales Team Details", 
@@ -1066,7 +1001,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-07 05:26:57.948263", 
+ "modified": "2017-02-01 12:00:06.045170", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Customer", 
@@ -1083,7 +1018,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1104,7 +1038,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
@@ -1125,7 +1058,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1146,7 +1078,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1167,7 +1098,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 1, 
    "print": 0, 
    "read": 1, 
@@ -1188,7 +1118,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1209,7 +1138,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1230,7 +1158,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1251,7 +1178,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -1269,5 +1195,6 @@
  "search_fields": "customer_name,customer_group,territory", 
  "sort_order": "ASC", 
  "title_field": "customer_name", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/selling/doctype/customer/customer.py b/erpnext/selling/doctype/customer/customer.py
index 48e2982..e4101af 100644
--- a/erpnext/selling/doctype/customer/customer.py
+++ b/erpnext/selling/doctype/customer/customer.py
@@ -9,9 +9,8 @@
 from frappe.utils import flt, cint, cstr
 from frappe.desk.reportview import build_match_conditions
 from erpnext.utilities.transaction_base import TransactionBase
-from erpnext.utilities.address_and_contact import load_address_and_contact
+from frappe.geo.address_and_contact import load_address_and_contact, delete_contact_and_address
 from erpnext.accounts.party import validate_party_accounts, get_timeline_data # keep this
-from erpnext.accounts.party_status import get_party_status
 from erpnext import get_default_currency
 
 class Customer(TransactionBase):
@@ -70,7 +69,6 @@
 		self.flags.is_new_doc = self.is_new()
 		self.flags.old_lead = self.lead_name
 		validate_party_accounts(self)
-		self.status = get_party_status(self)
 		self.validate_credit_limit_on_change()
 
 	def on_update(self):
@@ -79,9 +77,6 @@
 		if self.flags.old_lead != self.lead_name:
 			self.update_lead_status()
 
-		self.update_address()
-		self.update_contact()
-
 		if self.flags.is_new_doc:
 			self.create_lead_address_contact()
 
@@ -95,34 +90,35 @@
 				for d in frappe.get_all(doctype, {'lead': self.lead_name}):
 					frappe.db.set_value(doctype, d.name, 'customer', self.name, update_modified=False)
 
-	def update_address(self):
-		frappe.db.sql("""update `tabAddress` set customer_name=%s, modified=NOW()
-			where customer=%s""", (self.customer_name, self.name))
-
-	def update_contact(self):
-		frappe.db.sql("""update `tabContact` set customer_name=%s, modified=NOW()
-			where customer=%s""", (self.customer_name, self.name))
-
 	def create_lead_address_contact(self):
 		if self.lead_name:
-			if not frappe.db.get_value("Address", {"lead": self.lead_name, "customer": self.name}):
-				frappe.db.sql("""update `tabAddress` set customer=%s, customer_name=%s where lead=%s""",
-					(self.name, self.customer_name, self.lead_name))
+			# assign lead address to customer (if already not set)
+			address_names = frappe.get_all('Dynamic Link', filters={
+								"parenttype":"Address",
+								"link_doctype":"Lead",
+								"link_name":self.lead_name
+							}, fields=["parent as name"])
+
+			for address_name in address_names:
+				address = frappe.get_doc('Address', address_name.get('name'))
+				if not address.has_link('Customer', self.name):
+					address.append('links', dict(link_doctype='Customer', link_name=self.name))
+					address.save()
 
 			lead = frappe.db.get_value("Lead", self.lead_name, ["lead_name", "email_id", "phone", "mobile_no"], as_dict=True)
 
-			c = frappe.new_doc('Contact')
-			c.first_name = lead.lead_name
-			c.email_id = lead.email_id
-			c.phone = lead.phone
-			c.mobile_no = lead.mobile_no
-			c.customer = self.name
-			c.customer_name = self.customer_name
-			c.is_primary_contact = 1
-			c.flags.ignore_permissions = self.flags.ignore_permissions
-			c.autoname()
-			if not frappe.db.exists("Contact", c.name):
-				c.insert()
+			# create contact from lead
+			contact = frappe.new_doc('Contact')
+			contact.first_name = lead.lead_name
+			contact.email_id = lead.email_id
+			contact.phone = lead.phone
+			contact.mobile_no = lead.mobile_no
+			contact.is_primary_contact = 1
+			contact.append('links', dict(link_doctype='Customer', link_name=self.name))
+			contact.flags.ignore_permissions = self.flags.ignore_permissions
+			contact.autoname()
+			if not frappe.db.exists("Contact", contact.name):
+				contact.insert()
 
 	def validate_name_with_customer_group(self):
 		if frappe.db.exists("Customer Group", self.name):
@@ -137,40 +133,14 @@
 			if flt(self.credit_limit) < outstanding_amt:
 				frappe.throw(_("""New credit limit is less than current outstanding amount for the customer. Credit limit has to be atleast {0}""").format(outstanding_amt))
 
-	def delete_customer_address(self):
-		addresses = frappe.db.sql("""select name, lead from `tabAddress`
-			where customer=%s""", (self.name,))
-
-		for name, lead in addresses:
-			if lead:
-				frappe.db.sql("""update `tabAddress` set customer=null, customer_name=null
-					where name=%s""", name)
-			else:
-				frappe.db.sql("""delete from `tabAddress` where name=%s""", name)
-
-	def delete_customer_contact(self):
-		for contact in frappe.db.sql_list("""select name from `tabContact`
-			where customer=%s""", self.name):
-				frappe.delete_doc("Contact", contact)
-
 	def on_trash(self):
-		self.delete_customer_address()
-		self.delete_customer_contact()
+		delete_contact_and_address('Customer', self.name)
 		if self.lead_name:
-			frappe.db.sql("update `tabLead` set status='Interested' where name=%s",self.lead_name)
+			frappe.db.sql("update `tabLead` set status='Interested' where name=%s", self.lead_name)
 
 	def after_rename(self, olddn, newdn, merge=False):
-		set_field = ''
 		if frappe.defaults.get_global_default('cust_master_name') == 'Customer Name':
 			frappe.db.set(self, "customer_name", newdn)
-			self.update_contact()
-			set_field = ", customer_name=%(newdn)s"
-		self.update_customer_address(newdn, set_field)
-
-	def update_customer_address(self, newdn, set_field):
-		frappe.db.sql("""update `tabAddress` set address_title=%(newdn)s
-			{set_field} where customer=%(newdn)s"""\
-			.format(set_field=set_field), ({"newdn": newdn}))
 
 
 def get_customer_list(doctype, txt, searchfield, start, page_len, filters):
diff --git a/erpnext/selling/doctype/customer/customer_list.js b/erpnext/selling/doctype/customer/customer_list.js
index 57cebd4..09c3e93 100644
--- a/erpnext/selling/doctype/customer/customer_list.js
+++ b/erpnext/selling/doctype/customer/customer_list.js
@@ -1,12 +1,3 @@
 frappe.listview_settings['Customer'] = {
-	add_fields: ["customer_name", "territory", "customer_group", "customer_type", 'status'],
-	get_indicator: function(doc) {
-		color = {
-			'Open': 'red',
-			'Active': 'green',
-			'Dormant': 'darkgrey'
-		}
-		return [__(doc.status), color[doc.status], "status,=," + doc.status];
-	}
-
+	add_fields: ["customer_name", "territory", "customer_group", "customer_type"],
 };
diff --git a/erpnext/selling/doctype/customer/test_customer.py b/erpnext/selling/doctype/customer/test_customer.py
index 23df503..0d74d23 100644
--- a/erpnext/selling/doctype/customer/test_customer.py
+++ b/erpnext/selling/doctype/customer/test_customer.py
@@ -10,12 +10,17 @@
 from erpnext.exceptions import PartyFrozen, PartyDisabled
 from frappe.utils import flt
 from erpnext.selling.doctype.customer.customer import get_credit_limit, get_customer_outstanding
+from erpnext.tests.utils import create_test_contact_and_address
 
 test_ignore = ["Price List"]
 
 test_records = frappe.get_test_records('Customer')
 
 class TestCustomer(unittest.TestCase):
+	def setUp(self):
+		if not frappe.get_value('Item', '_Test Item'):
+			make_test_records('Item')
+
 	def tearDown(self):
 		frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', 0.0)
 
@@ -26,21 +31,21 @@
 			'selling_price_list': None,
 			'customer_group': '_Test Customer Group',
 			'contact_designation': None,
-			'customer_address': '_Test Address-Office',
+			'customer_address': '_Test Address for Customer-Office',
 			'contact_department': None,
 			'contact_email': 'test_contact_customer@example.com',
 			'contact_mobile': None,
 			'sales_team': [],
-			'contact_display': '_Test Contact For _Test Customer',
-			'contact_person': '_Test Contact For _Test Customer-_Test Customer',
+			'contact_display': '_Test Contact for _Test Customer',
+			'contact_person': '_Test Contact for _Test Customer-_Test Customer',
 			'territory': u'_Test Territory',
 			'contact_phone': '+91 0000000000',
 			'customer_name': '_Test Customer'
 		}
 
-		make_test_records("Address")
-		make_test_records("Contact")
-		frappe.db.set_value("Contact", "_Test Contact For _Test Customer-_Test Customer",
+		create_test_contact_and_address()
+
+		frappe.db.set_value("Contact", "_Test Contact for _Test Customer-_Test Customer",
 			"is_primary_contact", 1)
 
 		details = get_party_details("_Test Customer")
@@ -117,6 +122,7 @@
 		self.assertEquals(test_customer_1.customer_name, duplicate_customer.customer_name)
 
 	def get_customer_outstanding_amount(self):
+		from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
 		outstanding_amt = get_customer_outstanding('_Test Customer', '_Test Company')
 
 		# If outstanding is negative make a transaction to get positive outstanding amount
@@ -124,7 +130,7 @@
 			return outstanding_amt
 
 		item_qty = int((abs(outstanding_amt) + 200)/100)
-		make_sales_order({'qty':item_qty})
+		make_sales_order(qty=item_qty)
 		return get_customer_outstanding('_Test Customer', '_Test Company')
 
 	def test_customer_credit_limit(self):
@@ -138,7 +144,7 @@
 
 		if outstanding_amt <= 0.0:
 			item_qty = int((abs(outstanding_amt) + 200)/100)
-			make_sales_order({'qty':item_qty})
+			make_sales_order(qty=item_qty)
 
 		if credit_limit == 0.0:
 			frappe.db.set_value("Customer", '_Test Customer', 'credit_limit', outstanding_amt - 50.0)
@@ -165,11 +171,7 @@
 		self.assertRaises(frappe.ValidationError, make_sales_order)
 
 	def test_customer_credit_limit_on_change(self):
-		from erpnext.selling.doctype.sales_order.test_sales_order import make_sales_order
-
 		outstanding_amt = self.get_customer_outstanding_amount()
-		credit_limit = get_credit_limit('_Test Customer', '_Test Company')
-
 		customer = frappe.get_doc("Customer", '_Test Customer')
 		customer.credit_limit = flt(outstanding_amt - 100)
 		self.assertRaises(frappe.ValidationError, customer.save)
diff --git a/erpnext/selling/doctype/installation_note/installation_note.js b/erpnext/selling/doctype/installation_note/installation_note.js
index 0334ae7..d4b2179 100644
--- a/erpnext/selling/doctype/installation_note/installation_note.js
+++ b/erpnext/selling/doctype/installation_note/installation_note.js
@@ -32,11 +32,7 @@
 			}
 		});
 
-		this.frm.set_query("contact_person", function() {
-			return {
-				filters: {'customer': me.frm.doc.customer }
-			}
-		});
+		this.frm.set_query('contact_person', erpnext.queries.contact_query);
 
 		this.frm.set_query("customer", function() {
 			return {
diff --git a/erpnext/selling/doctype/quotation/quotation.js b/erpnext/selling/doctype/quotation/quotation.js
index d111c14..e06f963 100644
--- a/erpnext/selling/doctype/quotation/quotation.js
+++ b/erpnext/selling/doctype/quotation/quotation.js
@@ -16,6 +16,7 @@
 	},
 	refresh: function(doc, dt, dn) {
 		this._super(doc, dt, dn);
+
 		if(doc.docstatus == 1 && doc.status!=='Lost') {
 			cur_frm.add_custom_button(__('Make Sales Order'),
 				cur_frm.cscript['Make Sales Order']);
@@ -66,12 +67,8 @@
 		this.frm.toggle_reqd("customer", this.frm.doc.quotation_to == "Customer");
 
 		// to overwrite the customer_filter trigger from queries.js
-		$.each(["customer_address", "shipping_address_name"],
-			function(i, opts) {
-				me.frm.set_query(opts, me.frm.doc.quotation_to==="Lead"
-					? erpnext.queries["lead_filter"] : erpnext.queries["customer_filter"]);
-			}
-		);
+		this.frm.set_query('customer_address', erpnext.queries.address_query);
+		this.frm.set_query('shipping_address_name', erpnext.queries.address_query);
 	},
 
 	tc_name: function() {
diff --git a/erpnext/selling/doctype/quotation/test_quotation.py b/erpnext/selling/doctype/quotation/test_quotation.py
index 7a59dd7..36cc472 100644
--- a/erpnext/selling/doctype/quotation/test_quotation.py
+++ b/erpnext/selling/doctype/quotation/test_quotation.py
@@ -68,47 +68,6 @@
 		self.assertEquals(quotation.get("items")[0].rate, total_margin)
 		si.save()
 
-	def test_party_status_open(self):
-		from erpnext.selling.doctype.customer.test_customer import get_customer_dict
-
-		customer = frappe.get_doc(get_customer_dict('Party Status Test')).insert()
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
-
-		quotation = frappe.get_doc(get_quotation_dict(customer=customer.name)).insert()
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Open')
-
-		quotation.submit()
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
-
-		quotation.cancel()
-		quotation.delete()
-		customer.delete()
-
-	def test_party_status_close(self):
-		from erpnext.selling.doctype.customer.test_customer import get_customer_dict
-
-		customer = frappe.get_doc(get_customer_dict('Party Status Test')).insert()
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Active')
-
-		# open quotation
-		quotation = frappe.get_doc(get_quotation_dict(customer=customer.name)).insert()
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Open')
-
-		# close quotation (submit)
-		quotation.submit()
-
-		quotation1 = frappe.get_doc(get_quotation_dict(customer=customer.name)).insert()
-
-		# still open
-		self.assertEquals(frappe.db.get_value('Customer', customer.name, 'status'), 'Open')
-
-		quotation.cancel()
-		quotation.delete()
-
-		quotation1.delete()
-
-		customer.delete()
-
 test_records = frappe.get_test_records('Quotation')
 
 def get_quotation_dict(customer=None, item_code=None):
diff --git a/erpnext/selling/doctype/sales_order/sales_order.js b/erpnext/selling/doctype/sales_order/sales_order.js
index f1eeccc..f01e484 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.js
+++ b/erpnext/selling/doctype/sales_order/sales_order.js
@@ -4,11 +4,23 @@
 {% include 'erpnext/selling/sales_common.js' %}
 
 frappe.ui.form.on("Sales Order", {
+	setup: function(frm) {
+		$.extend(frm.cscript, new erpnext.selling.SalesOrderController({frm: frm}));
+	},
 	onload: function(frm) {
 		erpnext.queries.setup_queries(frm, "Warehouse", function() {
 			return erpnext.queries.warehouse(frm.doc);
 		});
 
+		frm.set_query('project', function(doc, cdt, cdn) {
+			return {
+				query: "erpnext.controllers.queries.get_project_name",
+				filters: {
+					'customer': doc.customer
+				}
+			}
+		});
+
 		// formatter for material request item
 		frm.set_indicator_formatter('item_code',
 			function(doc) { return (doc.qty<=doc.delivered_qty) ? "green" : "orange" })
@@ -17,6 +29,7 @@
 
 erpnext.selling.SalesOrderController = erpnext.selling.SellingController.extend({
 	refresh: function(doc, dt, dn) {
+		var me = this;
 		this._super();
 		var allow_purchase = false;
 		var allow_delivery = false;
@@ -24,8 +37,8 @@
 		if(doc.docstatus==1) {
 			if(doc.status != 'Closed') {
 
-				for (var i in cur_frm.doc.items) {
-					var item = cur_frm.doc.items[i];
+				for (var i in this.frm.doc.items) {
+					var item = this.frm.doc.items[i];
 					if(item.delivered_by_supplier === 1 || item.supplier){
 						if(item.qty > flt(item.ordered_qty)
 							&& item.qty > flt(item.delivered_qty)) {
@@ -47,55 +60,69 @@
 				if (this.frm.has_perm("submit")) {
 					// close
 					if(flt(doc.per_delivered, 2) < 100 || flt(doc.per_billed) < 100) {
-							cur_frm.add_custom_button(__('Close'), this.close_sales_order, __("Status"))
+							this.frm.add_custom_button(__('Close'),
+								function() { me.close_sales_order() }, __("Status"))
 						}
 				}
 
 				// delivery note
 				if(flt(doc.per_delivered, 2) < 100 && ["Sales", "Shopping Cart"].indexOf(doc.order_type)!==-1 && allow_delivery) {
-					cur_frm.add_custom_button(__('Delivery'), this.make_delivery_note, __("Make"));
-					cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
+					this.frm.add_custom_button(__('Delivery'),
+						function() { me.make_delivery_note() }, __("Make"));
+					this.frm.add_custom_button(__('Production Order'),
+						function() { me.make_production_order() }, __("Make"));
+
+					this.frm.page.set_inner_btn_group_as_primary(__("Make"));
 				}
 
 				// sales invoice
 				if(flt(doc.per_billed, 2) < 100) {
-					cur_frm.add_custom_button(__('Invoice'), this.make_sales_invoice, __("Make"));
+					this.frm.add_custom_button(__('Invoice'),
+						function() { me.make_sales_invoice() }, __("Make"));
 				}
 
 				// material request
 				if(!doc.order_type || ["Sales", "Shopping Cart"].indexOf(doc.order_type)!==-1
 					&& flt(doc.per_delivered, 2) < 100) {
-						cur_frm.add_custom_button(__('Material Request'), this.make_material_request, __("Make"));
+						this.frm.add_custom_button(__('Material Request'),
+							function() { me.make_material_request() }, __("Make"));
 				}
 
 				// make purchase order
 				if(flt(doc.per_delivered, 2) < 100 && allow_purchase) {
-					cur_frm.add_custom_button(__('Purchase Order'), cur_frm.cscript.make_purchase_order, __("Make"));
+					this.frm.add_custom_button(__('Purchase Order'),
+						function() { me.make_purchase_order() }, __("Make"));
 				}
 
+				// payment request
 				if(flt(doc.per_billed)==0) {
-					cur_frm.add_custom_button(__('Payment Request'), this.make_payment_request, __("Make"));
-					cur_frm.add_custom_button(__('Payment'), cur_frm.cscript.make_payment_entry, __("Make"));
+					this.frm.add_custom_button(__('Payment Request'),
+						function() { me.make_payment_request() }, __("Make"));
+					this.frm.add_custom_button(__('Payment'),
+						function() { me.make_payment_entry() }, __("Make"));
 				}
 
 				// maintenance
 				if(flt(doc.per_delivered, 2) < 100 &&
 						["Sales", "Shopping Cart"].indexOf(doc.order_type)===-1) {
-					cur_frm.add_custom_button(__('Maintenance Visit'), this.make_maintenance_visit, __("Make"));
-					cur_frm.add_custom_button(__('Maintenance Schedule'), this.make_maintenance_schedule, __("Make"));
+					this.frm.add_custom_button(__('Maintenance Visit'),
+						function() { me.make_maintenance_visit() }, __("Make"));
+					this.frm.add_custom_button(__('Maintenance Schedule'),
+						function() { me.make_maintenance_schedule() }, __("Make"));
 				}
 
-
 			} else {
 				if (this.frm.has_perm("submit")) {
 					// un-close
-					cur_frm.add_custom_button(__('Re-open'), cur_frm.cscript['Unclose Sales Order'], __("Status"));
+					this.frm.add_custom_button(__('Re-open'), function() {
+						me.frm.cscript.update_status('Re-open', 'Draft')
+					}, __("Status"));
 				}
 			}
 		}
 
 		if (this.frm.doc.docstatus===0) {
-			cur_frm.add_custom_button(__('Quotation'),
+			this.frm.add_custom_button(__('Quotation'),
 				function() {
 					erpnext.utils.map_current_doc({
 						method: "erpnext.selling.doctype.quotation.quotation.make_sales_order",
@@ -103,9 +130,9 @@
 						get_query_filters: {
 							docstatus: 1,
 							status: ["!=", "Lost"],
-							order_type: cur_frm.doc.order_type,
-							customer: cur_frm.doc.customer || undefined,
-							company: cur_frm.doc.company
+							order_type: me.frm.doc.order_type,
+							customer: me.frm.doc.customer || undefined,
+							company: me.frm.doc.company
 						}
 					})
 				}, __("Get items from"));
@@ -114,6 +141,82 @@
 		this.order_type(doc);
 	},
 
+	make_production_order() {
+		var me = this;
+		this.frm.call({
+			doc: this.frm.doc,
+			method: 'get_production_order_items',
+			callback: function(r) {
+				if(!r.message.every(function(d) { return !!d.bom })) {
+					frappe.msgprint({
+						title: __('Production Order not created'),
+						message: __('No Items with Bill of Materials to Manufacture'),
+						indicator: 'orange'
+					});
+					return;
+				}
+				else if(!r.message.every(function(d) { return !!d.pending_qty })) {
+					frappe.msgprint({
+						title: __('Production Order not created'),
+						message: __('Production Order already created for all items with BOM'),
+						indicator: 'orange'
+					});
+					return;
+				} else {
+					var fields = [
+						{fieldtype:'Table', fieldname: 'items',
+							description: __('Select BOM and Qty for Production'),
+							fields: [
+								{fieldtype:'Read Only', fieldname:'item_code',
+									label: __('Item Code'), in_list_view:1},
+								{fieldtype:'Link', fieldname:'bom', options: 'BOM',
+									label: __('Select BOM'), in_list_view:1, get_query: function(doc) {
+										return {filters: {item: doc.item_code}};
+									}},
+								{fieldtype:'Float', fieldname:'pending_qty',
+									label: __('Qty'), in_list_view:1},
+							],
+							get_data: function() {
+								return r.message
+							}
+						}
+					]
+					var d = new frappe.ui.Dialog({
+						title: __('Select Items to Manufacture'),
+						fields: fields,
+						primary_action: function() {
+							data = d.get_values();
+							me.frm.call({
+								method: 'make_production_orders',
+								args: {
+									items: data,
+									company: me.frm.doc.company,
+									sales_order: me.frm.docname,
+									project: me.frm.project
+								},
+								freeze: true,
+								callback: function(r) {
+									if(r.message) {
+										frappe.msgprint({
+											message: __('Production Orders Created: {0}',
+												[r.message.map(function(d) {
+													return repl('<a href="#Form/Production Order/%(name)s">%(name)s</a>', {name:d})
+												}).join(', ')]),
+											indicator: 'green'
+										})
+									}
+									d.hide();
+								}
+							});
+						},
+						primary_action_label: __('Make')
+					});
+					d.show();
+				}
+			}
+		});
+	},
+
 	order_type: function() {
 		this.frm.toggle_reqd("delivery_date", this.frm.doc.order_type == "Sales");
 	},
@@ -125,39 +228,40 @@
 	make_material_request: function() {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.selling.doctype.sales_order.sales_order.make_material_request",
-			frm: cur_frm
+			frm: this.frm
 		})
 	},
 
 	make_delivery_note: function() {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.selling.doctype.sales_order.sales_order.make_delivery_note",
-			frm: cur_frm
+			frm: this.frm
 		})
 	},
 
 	make_sales_invoice: function() {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.selling.doctype.sales_order.sales_order.make_sales_invoice",
-			frm: cur_frm
+			frm: this.frm
 		})
 	},
 
 	make_maintenance_schedule: function() {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_schedule",
-			frm: cur_frm
+			frm: this.frm
 		})
 	},
 
 	make_maintenance_visit: function() {
 		frappe.model.open_mapped_doc({
 			method: "erpnext.selling.doctype.sales_order.sales_order.make_maintenance_visit",
-			frm: cur_frm
+			frm: this.frm
 		})
 	},
 
 	make_purchase_order: function(){
+		var me = this;
 		var dialog = new frappe.ui.Dialog({
 			title: __("For Supplier"),
 			fields: [
@@ -165,7 +269,7 @@
 					"get_query": function () {
 						return {
 							query:"erpnext.selling.doctype.sales_order.sales_order.get_supplier",
-							filters: {'parent': cur_frm.doc.name}
+							filters: {'parent': me.frm.doc.name}
 						}
 					}, "reqd": 1 },
 				{"fieldtype": "Button", "label": __("Make Purchase Order"), "fieldname": "make_purchase_order", "cssClass": "btn-primary"},
@@ -180,7 +284,7 @@
 				type: "GET",
 				method: "erpnext.selling.doctype.sales_order.sales_order.make_purchase_order_for_drop_shipment",
 				args: {
-					"source_name": cur_frm.doc.name,
+					"source_name": me.frm.doc.name,
 					"for_supplier": args.supplier
 				},
 				freeze: true,
@@ -195,51 +299,25 @@
 		dialog.show();
 	},
 	close_sales_order: function(){
-		cur_frm.cscript.update_status("Close", "Closed")
+		this.frm.cscript.update_status("Close", "Closed")
+	},
+	update_status: function(label, status){
+		var doc = this.frm.doc;
+		frappe.ui.form.is_saving = true;
+		frappe.call({
+			method: "erpnext.selling.doctype.sales_order.sales_order.update_status",
+			args: {status: status, name: doc.name},
+			callback: function(r){
+				this.frm.reload_doc();
+			},
+			always: function() {
+				frappe.ui.form.is_saving = false;
+			}
+		});
+	},
+	on_submit: function(doc, cdt, cdn) {
+		if(cint(frappe.boot.notification_settings.sales_order)) {
+			this.frm.email_doc(frappe.boot.notification_settings.sales_order_message);
+		}
 	}
-
 });
-
-// for backward compatibility: combine new and previous states
-$.extend(cur_frm.cscript, new erpnext.selling.SalesOrderController({frm: cur_frm}));
-
-cur_frm.cscript.new_contact = function(){
-	tn = frappe.model.make_new_doc_and_get_name('Contact');
-	locals['Contact'][tn].is_customer = 1;
-	if(doc.customer) locals['Contact'][tn].customer = doc.customer;
-	frappe.set_route('Form', 'Contact', tn);
-}
-
-cur_frm.fields_dict['project'].get_query = function(doc, cdt, cdn) {
-	return {
-		query: "erpnext.controllers.queries.get_project_name",
-		filters: {
-			'customer': doc.customer
-		}
-	}
-}
-
-cur_frm.cscript.update_status = function(label, status){
-	var doc = cur_frm.doc;
-	frappe.ui.form.is_saving = true;
-	frappe.call({
-		method: "erpnext.selling.doctype.sales_order.sales_order.update_status",
-		args: {status: status, name: doc.name},
-		callback: function(r){
-			cur_frm.reload_doc();
-		},
-		always: function() {
-			frappe.ui.form.is_saving = false;
-		}
-	});
-}
-
-cur_frm.cscript['Unclose Sales Order'] = function() {
-	cur_frm.cscript.update_status('Re-open', 'Draft')
-}
-
-cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
-	if(cint(frappe.boot.notification_settings.sales_order)) {
-		cur_frm.email_doc(frappe.boot.notification_settings.sales_order_message);
-	}
-};
diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py
index acae0e5..fdaadd8 100644
--- a/erpnext/selling/doctype/sales_order/sales_order.py
+++ b/erpnext/selling/doctype/sales_order/sales_order.py
@@ -304,6 +304,24 @@
 			self.indicator_color = "green"
 			self.indicator_title = _("Paid")
 
+	def get_production_order_items(self):
+		'''Returns items with BOM that already do not have a linked production order'''
+		items = []
+		for i in self.packed_items or self.items:
+			bom = frappe.get_all('BOM', dict(item=i.item_code, is_active=True),
+					order_by='is_default desc')
+			bom = bom[0].name if bom else None
+			items.append(dict(
+				item_code= i.item_code,
+				bom = bom,
+				warehouse = i.warehouse,
+				pending_qty= i.qty - flt(frappe.db.sql('''select sum(qty) from `tabProduction Order`
+					where production_item=%s and sales_order=%s''', (i.item_code, self.name))[0][0])
+			))
+
+		return items
+
+
 	def on_recurring(self, reference_doc):
 		mcount = month_map[reference_doc.recurring_type]
 		self.set("delivery_date", get_next_date(reference_doc.delivery_date, mcount,
@@ -442,7 +460,7 @@
 		target.amount = flt(source.amount) - flt(source.billed_amt)
 		target.base_amount = target.amount * flt(source_parent.conversion_rate)
 		target.qty = target.amount / flt(source.rate) if (source.rate and source.billed_amt) else source.qty
-		
+
 		item = frappe.db.get_value("Item", target.item_code, ["item_group", "selling_cost_center"], as_dict=1)
 		target.cost_center = frappe.db.get_value("Project", source_parent.project, "cost_center") \
 			or item.selling_cost_center \
@@ -653,6 +671,27 @@
 		})
 
 @frappe.whitelist()
+def make_production_orders(items, sales_order, company, project=None):
+	'''Make Production Orders against the given Sales Order for the given `items`'''
+	items = json.loads(items).get('items')
+	out = []
+
+	for i in items:
+		production_order = frappe.get_doc(dict(
+			doctype='Production Order',
+			production_item=i['item_code'],
+			bom_no=i['bom'],
+			qty=i['pending_qty'],
+			company=company,
+			sales_order=sales_order,
+			project=project,
+			fg_warehouse=i['warehouse']
+		)).insert()
+		out.append(production_order)
+
+	return [p.name for p in out]
+
+@frappe.whitelist()
 def update_status(status, name):
 	so = frappe.get_doc("Sales Order", name)
 	so.update_status(status)
diff --git a/erpnext/selling/page/sales_analytics/sales_analytics.js b/erpnext/selling/page/sales_analytics/sales_analytics.js
index 2f9b02c..73793d4 100644
--- a/erpnext/selling/page/sales_analytics/sales_analytics.js
+++ b/erpnext/selling/page/sales_analytics/sales_analytics.js
@@ -202,7 +202,9 @@
 				if (posting_date >= from_date && posting_date <= to_date) {
 					var item = me.item_by_name[tl[me.tree_grid.item_key]] ||
 						me.item_by_name['Not Set'];
-					item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
+					if(item){
+						item[me.column_map[tl.posting_date].field] += (is_val ? tl.base_net_amount : tl.qty);
+					}
 				}
 			}
 		});
diff --git a/erpnext/selling/page/sales_funnel/sales_funnel.py b/erpnext/selling/page/sales_funnel/sales_funnel.py
index 4d12efd..3c4d528 100644
--- a/erpnext/selling/page/sales_funnel/sales_funnel.py
+++ b/erpnext/selling/page/sales_funnel/sales_funnel.py
@@ -12,9 +12,9 @@
 		where (date(`modified`) between %s and %s)
 		and status != "Do Not Contact" """, (from_date, to_date))[0][0]
 
-	active_leads += frappe.db.sql("""select count(distinct customer) from `tabContact`
-		where (date(`modified`) between %s and %s)
-		and status != "Passive" """, (from_date, to_date))[0][0]
+	active_leads += frappe.db.sql("""select count(distinct contact.name) from `tabContact` contact
+		left join `tabDynamic Link` dl on (dl.parent=contact.name) where dl.link_doctype='Customer' 
+		and (date(contact.modified) between %s and %s) and status != "Passive" """, (from_date, to_date))[0][0]
 
 	opportunities = frappe.db.sql("""select count(*) from `tabOpportunity`
 		where (date(`creation`) between %s and %s)
diff --git a/erpnext/selling/report/customer_addresses_and_contacts/__init__.py b/erpnext/selling/report/customer_addresses_and_contacts/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/selling/report/customer_addresses_and_contacts/__init__.py
+++ /dev/null
diff --git a/erpnext/selling/report/customer_addresses_and_contacts/customer_addresses_and_contacts.json b/erpnext/selling/report/customer_addresses_and_contacts/customer_addresses_and_contacts.json
deleted file mode 100644
index 1f6707b..0000000
--- a/erpnext/selling/report/customer_addresses_and_contacts/customer_addresses_and_contacts.json
+++ /dev/null
@@ -1,19 +0,0 @@
-{
- "add_total_row": 0, 
- "apply_user_permissions": 1, 
- "creation": "2012-10-04 18:45:27", 
- "disabled": 0, 
- "docstatus": 0, 
- "doctype": "Report", 
- "idx": 1, 
- "is_standard": "Yes", 
- "modified": "2015-08-24 11:44:00.711112", 
- "modified_by": "Administrator", 
- "module": "Selling", 
- "name": "Customer Addresses And Contacts", 
- "owner": "Administrator", 
- "query": "SELECT\n\t`tabCustomer`.name as \"Customer ID:Link/Customer\",\n\t`tabCustomer`.customer_name as \"Customer Name\",\n\t`tabCustomer`.customer_group as \"Customer Group:Link/Customer Group\",\n\t`tabAddress`.address_line1 as \"Address Line 1\",\n\t`tabAddress`.address_line2 as \"Address Line 2\",\n\t`tabAddress`.city as \"City\",\n\t`tabAddress`.state as \"State\",\n\t`tabAddress`.pincode as \"Postal Code\",\n\t`tabAddress`.country as \"Country\",\n\t`tabAddress`.is_primary_address as \"Is Primary Address:Check\", \n\t`tabContact`.first_name as \"First Name\",\n\t`tabContact`.last_name as \"Last Name\",\n\t`tabContact`.phone as \"Phone\",\n\t`tabContact`.mobile_no as \"Mobile No\",\n\t`tabContact`.email_id as \"Email Address\",\n\t`tabContact`.is_primary_contact as \"Is Primary Contact:Check\"\nFROM\n\t`tabCustomer`\n\tleft join `tabAddress` on (\n\t\t`tabAddress`.customer=`tabCustomer`.name\n\t)\n\tleft join `tabContact` on (\n\t\t`tabContact`.customer=`tabCustomer`.name\n\t)\nWHERE\n\t`tabCustomer`.docstatus<2\nORDER BY\n\t`tabCustomer`.name asc", 
- "ref_doctype": "Customer", 
- "report_name": "Customer Addresses And Contacts", 
- "report_type": "Query Report"
-}
\ No newline at end of file
diff --git a/erpnext/selling/report/lead_details/lead_details.json b/erpnext/selling/report/lead_details/lead_details.json
index 387b5f8..047b4b7 100644
--- a/erpnext/selling/report/lead_details/lead_details.json
+++ b/erpnext/selling/report/lead_details/lead_details.json
@@ -1,16 +1,18 @@
 {
+ "add_total_row": 0, 
  "apply_user_permissions": 1, 
  "creation": "2013-10-22 11:58:16", 
+ "disabled": 0, 
  "docstatus": 0, 
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "modified": "2015-02-02 11:39:57.231750", 
+ "modified": "2017-01-19 15:44:59.742195", 
  "modified_by": "Administrator", 
  "module": "Selling", 
  "name": "Lead Details", 
  "owner": "Administrator", 
- "query": "SELECT\n    `tabLead`.name as \"Lead Id:Link/Lead:120\",\n    `tabLead`.lead_name as \"Lead Name::120\",\n\t`tabLead`.company_name as \"Company Name::120\",\n\t`tabLead`.status as \"Status::120\",\n\tconcat_ws(', ', \n\t\ttrim(',' from `tabAddress`.address_line1), \n\t\ttrim(',' from tabAddress.address_line2)\n\t) as 'Address::180',\n\t`tabAddress`.state as \"State::100\",\n\t`tabAddress`.pincode as \"Pincode::70\",\n\t`tabAddress`.country as \"Country::100\",\n\t`tabLead`.phone as \"Phone::100\",\n\t`tabLead`.mobile_no as \"Mobile No::100\",\n\t`tabLead`.email_id as \"Email Address::120\",\n\t`tabLead`.lead_owner as \"Lead Owner::120\",\n\t`tabLead`.source as \"Source::120\",\n\t`tabLead`.territory as \"Territory::120\",\n    `tabLead`.owner as \"Owner:Link/User:120\"\nFROM\n\t`tabLead`\n\tleft join `tabAddress` on (\n\t\t`tabAddress`.lead=`tabLead`.name\n\t)\nWHERE\n\t`tabLead`.docstatus<2\nORDER BY\n\t`tabLead`.name asc", 
+ "query": "SELECT\n    `tabLead`.name as \"Lead Id:Link/Lead:120\",\n    `tabLead`.lead_name as \"Lead Name::120\",\n\t`tabLead`.company_name as \"Company Name::120\",\n\t`tabLead`.status as \"Status::120\",\n\tconcat_ws(', ', \n\t\ttrim(',' from `tabAddress`.address_line1), \n\t\ttrim(',' from tabAddress.address_line2)\n\t) as 'Address::180',\n\t`tabAddress`.state as \"State::100\",\n\t`tabAddress`.pincode as \"Pincode::70\",\n\t`tabAddress`.country as \"Country::100\",\n\t`tabLead`.phone as \"Phone::100\",\n\t`tabLead`.mobile_no as \"Mobile No::100\",\n\t`tabLead`.email_id as \"Email Id::120\",\n\t`tabLead`.lead_owner as \"Lead Owner::120\",\n\t`tabLead`.source as \"Source::120\",\n\t`tabLead`.territory as \"Territory::120\",\n    `tabLead`.owner as \"Owner:Link/User:120\"\nFROM\n\t`tabLead`\n\tleft join `tabDynamic Link` on (\n\t\t`tabDynamic Link`.link_name=`tabLead`.name\n\t)\n\tleft join `tabAddress` on (\n\t\t`tabAddress`.name=`tabDynamic Link`.parent\n\t)\nWHERE\n\t`tabLead`.docstatus<2\nORDER BY\n\t`tabLead`.name asc", 
  "ref_doctype": "Lead", 
  "report_name": "Lead Details", 
  "report_type": "Query Report"
diff --git a/erpnext/selling/sales_common.js b/erpnext/selling/sales_common.js
index 7ddf45d..9d9511e 100644
--- a/erpnext/selling/sales_common.js
+++ b/erpnext/selling/sales_common.js
@@ -26,16 +26,17 @@
 
 		this.frm.add_fetch("sales_partner", "commission_rate", "commission_rate");
 
-		$.each([["customer_address", "customer_filter"],
-			["shipping_address_name", "customer_filter"],
-			["contact_person", "customer_filter"],
-			["customer", "customer"],
+		$.each([["customer", "customer"],
 			["lead", "lead"]],
 			function(i, opts) {
 				if(me.frm.fields_dict[opts[0]])
 					me.frm.set_query(opts[0], erpnext.queries[opts[1]]);
 			});
 
+		me.frm.set_query('contact_person', erpnext.queries.contact_query);
+		me.frm.set_query('customer_address', erpnext.queries.address_query);
+		me.frm.set_query('shipping_address_name', erpnext.queries.address_query);
+
 		if(this.frm.fields_dict.taxes_and_charges) {
 			this.frm.set_query("taxes_and_charges", function() {
 				return {
@@ -104,6 +105,9 @@
 
 	refresh: function() {
 		this._super();
+
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
+
 		this.frm.toggle_display("customer_name",
 			(this.frm.doc.customer_name && this.frm.doc.customer_name!==this.frm.doc.customer));
 		if(this.frm.fields_dict.packed_items) {
diff --git a/erpnext/setup/doctype/company/company.js b/erpnext/setup/doctype/company/company.js
index f22e63e..5dd8ceb 100644
--- a/erpnext/setup/doctype/company/company.js
+++ b/erpnext/setup/doctype/company/company.js
@@ -4,6 +4,17 @@
 frappe.provide("erpnext.company");
 
 frappe.ui.form.on("Company", {
+	setup: function(frm) {
+		frm.fields_dict['default_payable_account'].get_query = function() {
+			return{
+				filters: {
+					"root_type": "Liability",
+					"account_type": "Payable"
+				}
+			}
+		}
+	},
+
 	onload: function(frm) {
 		erpnext.company.setup_queries(frm);
 	},
diff --git a/erpnext/setup/doctype/company/company.py b/erpnext/setup/doctype/company/company.py
index 32ad8eb..93f02f8 100644
--- a/erpnext/setup/doctype/company/company.py
+++ b/erpnext/setup/doctype/company/company.py
@@ -153,6 +153,8 @@
 			self.db_set("default_income_account", frappe.db.get_value("Account",
 				{"account_name": _("Sales"), "company": self.name}))
 
+		if not self.default_payable_account:
+			self.db_set("default_payable_account", self.default_payable_account)
 
 	def _set_default_account(self, fieldname, account_type):
 		if self.get(fieldname):
diff --git a/erpnext/setup/doctype/company/delete_company_transactions.py b/erpnext/setup/doctype/company/delete_company_transactions.py
index eb5c043..eef8599 100644
--- a/erpnext/setup/doctype/company/delete_company_transactions.py
+++ b/erpnext/setup/doctype/company/delete_company_transactions.py
@@ -73,11 +73,23 @@
 
 def delete_lead_addresses(company_name):
 	"""Delete addresses to which leads are linked"""
-	for lead in frappe.get_all("Lead", filters={"company": company_name}):
-		frappe.db.sql("""delete from `tabAddress`
-			where lead=%s and (customer='' or customer is null) and (supplier='' or supplier is null)""", lead.name)
+	leads = frappe.get_all("Lead", filters={"company": company_name})
+	leads = [ "'%s'"%row.get("name") for row in leads ]
+	addresses = []
+	if leads:
+		addresses = frappe.db.sql_list("""select parent from `tabDynamic Link` where link_name 
+			in ({leads})""".format(leads=",".join(leads)), debug=True)
+		addresses = ["'%s'"%addr for addr in addresses]
 
-		frappe.db.sql("""update `tabAddress` set lead=null, lead_name=null where lead=%s""", lead.name)
+		frappe.db.sql("""delete from tabAddress where name in ({addresses}) and 
+			name not in (select distinct dl1.parent from `tabDynamic Link` dl1 
+			inner join `tabDynamic Link` dl2 on dl1.parent=dl2.parent 
+			and dl1.link_doctype<>dl2.link_doctype)""".format(addresses=",".join(addresses)), debug=True)
+
+		frappe.db.sql("""delete from `tabDynamic Link` where link_doctype='Lead' and parenttype='Address' 
+			and link_name in ({leads})""".format(leads=",".join(leads)), debug=True)
+
+		frappe.db.sql("""update tabCustomer set lead_name=NULL where lead_name in ({leads})""".format(leads=",".join(leads)), debug=True)
 
 def delete_communications(doctype, company_name, company_fieldname):
 		frappe.db.sql("""
diff --git a/erpnext/setup/doctype/naming_series/naming_series.py b/erpnext/setup/doctype/naming_series/naming_series.py
index dfe3ec0..a9832de 100644
--- a/erpnext/setup/doctype/naming_series/naming_series.py
+++ b/erpnext/setup/doctype/naming_series/naming_series.py
@@ -8,17 +8,19 @@
 from frappe import msgprint, throw, _
 
 from frappe.model.document import Document
+from frappe.permissions import get_doctypes_with_read
 
 class NamingSeriesNotSetError(frappe.ValidationError): pass
 
 class NamingSeries(Document):
 	def get_transactions(self, arg=None):
 		doctypes = list(set(frappe.db.sql_list("""select parent
-				from `tabDocField` df where fieldname='naming_series' and 
-				exists(select * from `tabDocPerm` dp, `tabRole` role where dp.role = role.name and dp.parent = df.parent and not role.disabled)""")
+				from `tabDocField` df where fieldname='naming_series'""")
 			+ frappe.db.sql_list("""select dt from `tabCustom Field`
 				where fieldname='naming_series'""")))
 
+		doctypes = list(set(get_doctypes_with_read()) | set(doctypes))
+
 		prefixes = ""
 		for d in doctypes:
 			options = ""
@@ -128,7 +130,8 @@
 			throw(_('Special Characters except "-", "#", "." and "/" not allowed in naming series'))
 
 	def get_options(self, arg=None):
-		return frappe.get_meta(arg or self.select_doc_for_series).get_field("naming_series").options
+		if frappe.get_meta(arg or self.select_doc_for_series).get_field("naming_series"):
+			return frappe.get_meta(arg or self.select_doc_for_series).get_field("naming_series").options
 
 	def get_current(self, arg=None):
 		"""get series current"""
diff --git a/erpnext/fleet_management/doctype/__init__.py b/erpnext/setup/doctype/party_type/__init__.py
similarity index 100%
copy from erpnext/fleet_management/doctype/__init__.py
copy to erpnext/setup/doctype/party_type/__init__.py
diff --git a/erpnext/setup/doctype/party_type/party_type.js b/erpnext/setup/doctype/party_type/party_type.js
new file mode 100644
index 0000000..7a96dc5
--- /dev/null
+++ b/erpnext/setup/doctype/party_type/party_type.js
@@ -0,0 +1,15 @@
+// Copyright (c) 2016, Frappe Technologies and contributors
+// For license information, please see license.txt
+
+frappe.ui.form.on('Party Type', {
+	setup: function(frm) {
+		frm.fields_dict["party_type"].get_query = function(frm) {
+			return {
+				filters: {
+					"istable": 0,
+					"is_submittable": 0
+				}
+			}
+		}
+	}
+});
diff --git a/erpnext/setup/doctype/party_type/party_type.json b/erpnext/setup/doctype/party_type/party_type.json
new file mode 100644
index 0000000..f49e7b3
--- /dev/null
+++ b/erpnext/setup/doctype/party_type/party_type.json
@@ -0,0 +1,130 @@
+{
+ "allow_copy": 0, 
+ "allow_import": 0, 
+ "allow_rename": 0, 
+ "autoname": "field:party_type", 
+ "beta": 0, 
+ "creation": "2016-12-26 11:26:51.508286", 
+ "custom": 0, 
+ "docstatus": 0, 
+ "doctype": "DocType", 
+ "document_type": "", 
+ "editable_grid": 1, 
+ "engine": "InnoDB", 
+ "fields": [
+  {
+   "allow_on_submit": 0, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "party_type", 
+   "fieldtype": "Link", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 1, 
+   "in_standard_filter": 0, 
+   "label": "Party Type", 
+   "length": 0, 
+   "no_copy": 0, 
+   "options": "DocType", 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 0, 
+   "print_hide_if_no_value": 0, 
+   "read_only": 0, 
+   "remember_last_selected_value": 0, 
+   "report_hide": 0, 
+   "reqd": 1, 
+   "search_index": 0, 
+   "set_only_once": 0, 
+   "unique": 0
+  }
+ ], 
+ "hide_heading": 0, 
+ "hide_toolbar": 0, 
+ "idx": 0, 
+ "image_view": 0, 
+ "in_create": 0, 
+ "in_dialog": 0, 
+ "is_submittable": 0, 
+ "issingle": 0, 
+ "istable": 0, 
+ "max_attachments": 0, 
+ "modified": "2017-01-19 17:55:33.428335", 
+ "modified_by": "Administrator", 
+ "module": "Setup", 
+ "name": "Party Type", 
+ "name_case": "", 
+ "owner": "Administrator", 
+ "permissions": [
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "System Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Accounts User", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }, 
+  {
+   "amend": 0, 
+   "apply_user_permissions": 0, 
+   "cancel": 0, 
+   "create": 1, 
+   "delete": 1, 
+   "email": 1, 
+   "export": 1, 
+   "if_owner": 0, 
+   "import": 0, 
+   "permlevel": 0, 
+   "print": 1, 
+   "read": 1, 
+   "report": 1, 
+   "role": "Accounts Manager", 
+   "set_user_permissions": 0, 
+   "share": 1, 
+   "submit": 0, 
+   "write": 1
+  }
+ ], 
+ "quick_entry": 1, 
+ "read_only": 0, 
+ "read_only_onload": 0, 
+ "sort_field": "modified", 
+ "sort_order": "DESC", 
+ "track_changes": 1, 
+ "track_seen": 0
+}
\ No newline at end of file
diff --git a/erpnext/setup/doctype/party_type/party_type.py b/erpnext/setup/doctype/party_type/party_type.py
new file mode 100644
index 0000000..74db037
--- /dev/null
+++ b/erpnext/setup/doctype/party_type/party_type.py
@@ -0,0 +1,20 @@
+# -*- coding: utf-8 -*-
+# Copyright (c) 2015, Frappe Technologies and contributors
+# For license information, please see license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.model.document import Document
+
+class PartyType(Document):
+	pass
+
+@frappe.whitelist()
+def get_party_type(doctype, txt, searchfield, start, page_len, filters):
+	return frappe.db.sql("""select name from `tabParty Type`
+			where `{key}` LIKE %(txt)s
+			order by name limit %(start)s, %(page_len)s"""
+			.format(key=searchfield), {
+				'txt': "%%%s%%" % frappe.db.escape(txt),
+				'start': start, 'page_len': page_len
+			})
diff --git a/erpnext/schools/doctype/assessment/test_assessment.py b/erpnext/setup/doctype/party_type/test_party_type.py
similarity index 65%
rename from erpnext/schools/doctype/assessment/test_assessment.py
rename to erpnext/setup/doctype/party_type/test_party_type.py
index ce06007..079fe2f 100644
--- a/erpnext/schools/doctype/assessment/test_assessment.py
+++ b/erpnext/setup/doctype/party_type/test_party_type.py
@@ -6,7 +6,7 @@
 import frappe
 import unittest
 
-# test_records = frappe.get_test_records('Assessment')
+# test_records = frappe.get_test_records('Party Type')
 
-class TestAssessment(unittest.TestCase):
+class TestPartyType(unittest.TestCase):
 	pass
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.js b/erpnext/setup/doctype/sales_partner/sales_partner.js
index 143bf44..84cf749 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.js
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.js
@@ -1,14 +1,17 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-cur_frm.cscript.refresh = function(doc,dt,dn){
+frappe.ui.form.on('Sales Partner', {
+	refresh: function(frm) {
+		frappe.dynamic_link = {doc: frm.doc, fieldname: 'name', doctype: 'Sales Person'}
 
-	if(doc.__islocal){
-		hide_field(['address_html', 'contact_html']);
-		erpnext.utils.clear_address_and_contact(cur_frm);
+		if(frm.doc.__islocal){
+			hide_field(['address_html', 'contact_html', 'address_contacts']);
+			frappe.geo.clear_address_and_contact(frm);
+		}
+		else{
+			unhide_field(['address_html', 'contact_html', 'address_contacts']);
+			frappe.geo.render_address_and_contact(frm);
+		}
 	}
-	else{
-		unhide_field(['address_html', 'contact_html']);
-		erpnext.utils.render_address_and_contact(cur_frm);
-	}
-}
+});
diff --git a/erpnext/setup/doctype/sales_partner/sales_partner.py b/erpnext/setup/doctype/sales_partner/sales_partner.py
index 5a2aa49..96211af 100644
--- a/erpnext/setup/doctype/sales_partner/sales_partner.py
+++ b/erpnext/setup/doctype/sales_partner/sales_partner.py
@@ -5,7 +5,7 @@
 import frappe
 from frappe.utils import cstr, filter_strip_join
 from frappe.website.website_generator import WebsiteGenerator
-from erpnext.utilities.address_and_contact import load_address_and_contact
+from frappe.geo.address_and_contact import load_address_and_contact
 
 class SalesPartner(WebsiteGenerator):
 	website = frappe._dict(
@@ -28,15 +28,6 @@
 		if self.partner_website and not self.partner_website.startswith("http"):
 			self.partner_website = "http://" + self.partner_website
 
-	def get_contacts(self, nm):
-		if nm:
-			return frappe.db.convert_to_lists(frappe.db.sql("""
-				select name, CONCAT(IFNULL(first_name,''),
-					' ',IFNULL(last_name,'')),contact_no,email_id
-				from `tabContact` where sales_partner = %s""", nm))
-		else:
-			return ''
-
 	def get_context(self, context):
 		address = frappe.db.get_value("Address",
 			{"sales_partner": self.name, "is_primary_address": 1},
diff --git a/erpnext/setup/setup_wizard/install_fixtures.py b/erpnext/setup/setup_wizard/install_fixtures.py
index 1589b3b..5e08203 100644
--- a/erpnext/setup/setup_wizard/install_fixtures.py
+++ b/erpnext/setup/setup_wizard/install_fixtures.py
@@ -171,6 +171,10 @@
 		{'doctype': "Email Account", "email_id": "support@example.com", "append_to": "Issue"},
 		{'doctype': "Email Account", "email_id": "jobs@example.com", "append_to": "Job Applicant"},
 
+		{'doctype': "Party Type", "party_type": "Customer"},
+		{'doctype': "Party Type", "party_type": "Supplier"},
+		{'doctype': "Party Type", "party_type": "Employee"},
+
 		{"doctype": "Offer Term", "offer_term": _("Date of Joining")},
 		{"doctype": "Offer Term", "offer_term": _("Annual Salary")},
 		{"doctype": "Offer Term", "offer_term": _("Probationary Period")},
diff --git a/erpnext/setup/setup_wizard/setup_wizard.py b/erpnext/setup/setup_wizard/setup_wizard.py
index 395ea51..664c089 100644
--- a/erpnext/setup/setup_wizard/setup_wizard.py
+++ b/erpnext/setup/setup_wizard/setup_wizard.py
@@ -407,7 +407,7 @@
 
 				if args.get("customer_contact_" + str(i)):
 					create_contact(args.get("customer_contact_" + str(i)),
-						"customer", doc.name)
+						"Customer", doc.name)
 			except frappe.NameError:
 				pass
 
@@ -425,7 +425,7 @@
 
 				if args.get("supplier_contact_" + str(i)):
 					create_contact(args.get("supplier_contact_" + str(i)),
-						"supplier", doc.name)
+						"Supplier", doc.name)
 			except frappe.NameError:
 				pass
 
@@ -433,12 +433,13 @@
 	"""Create contact based on given contact name"""
 	contact = contact.strip().split(" ")
 
-	frappe.get_doc({
+	contact = frappe.get_doc({
 		"doctype":"Contact",
-		party_type: party,
 		"first_name":contact[0],
 		"last_name": len(contact) > 1 and contact[1] or ""
-	}).insert()
+	})
+	contact.append('links', dict(link_doctype=party_type, link_name=party))
+	contact.insert()
 
 def create_letter_head(args):
 	if args.get("attach_letterhead"):
diff --git a/erpnext/setup/setup_wizard/test_setup_data.py b/erpnext/setup/setup_wizard/test_setup_data.py
index de54a1d..25378f4 100644
--- a/erpnext/setup/setup_wizard/test_setup_data.py
+++ b/erpnext/setup/setup_wizard/test_setup_data.py
@@ -13,7 +13,7 @@
 "customer_2": "Mahesh Engg",
 "customer_contact_1": "Aditya Duggal",
 "customer_contact_2": "Mahesh Malani",
-"first_name": "Rushabh",
+"full_name": "Rushabh Mehta",
 "fy_start": "1st Apr",
 "item_1": "Enterprise Plan",
 "item_2": "Small Business",
@@ -42,7 +42,6 @@
 "item_uom_3": "Unit",
 "item_uom_4": "Unit",
 "item_uom_5": "Unit",
-"last_name": "Mehta",
 "supplier_1": "Google",
 "supplier_2": "Hetzner",
 "supplier_3": "Digital Ocean",
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 0c214e4..cb63837 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -6,7 +6,7 @@
 from frappe import _, throw
 from frappe.utils import flt
 from frappe.utils import get_datetime_str, nowdate
-	
+
 def get_company_currency(company):
 	currency = frappe.db.get_value("Company", company, "default_currency", cache=True)
 	if not currency:
@@ -37,8 +37,7 @@
 	if not frappe.get_list("Company"):
 		setup_complete({
 			"currency"			:"USD",
-			"first_name"		:"Test",
-			"last_name"			:"User",
+			"full_name"			:"Test User",
 			"company_name"		:"Wind Power LLC",
 			"timezone"			:"America/New_York",
 			"company_abbr"		:"WP",
@@ -52,7 +51,7 @@
 			"password"			:"test",
 			"chart_of_accounts" : "Standard",
 			"domain"			: "Manufacturing",
-			
+
 		})
 
 	frappe.db.sql("delete from `tabLeave Allocation`")
@@ -71,18 +70,18 @@
 	if not (from_currency and to_currency):
 		# manqala 19/09/2016: Should this be an empty return or should it throw and exception?
 		return
-	
+
 	if from_currency == to_currency:
 		return 1
-	
+
 	# cksgb 19/09/2016: get last entry in Currency Exchange with from_currency and to_currency.
-	entries = frappe.get_all("Currency Exchange", fields = ["exchange_rate"], 
+	entries = frappe.get_all("Currency Exchange", fields = ["exchange_rate"],
 		filters=[
-			["date", "<=", get_datetime_str(transaction_date)], 
-			["from_currency", "=", from_currency], 
+			["date", "<=", get_datetime_str(transaction_date)],
+			["from_currency", "=", from_currency],
 			["to_currency", "=", to_currency]
 		], order_by="date desc", limit=1)
-	
+
 	if entries:
 		return flt(entries[0].exchange_rate)
 
diff --git a/erpnext/shopping_cart/cart.py b/erpnext/shopping_cart/cart.py
index d5cde4a..b427b94 100644
--- a/erpnext/shopping_cart/cart.py
+++ b/erpnext/shopping_cart/cart.py
@@ -6,7 +6,7 @@
 from frappe import throw, _
 import frappe.defaults
 from frappe.utils import cint, flt, get_fullname, cstr
-from erpnext.utilities.doctype.address.address import get_address_display
+from frappe.geo.doctype.address.address import get_address_display
 from erpnext.shopping_cart.doctype.shopping_cart_settings.shopping_cart_settings import get_shopping_cart_settings
 from frappe.utils.nestedset import get_root_of
 from erpnext.accounts.utils import get_account_name
@@ -160,6 +160,7 @@
 	return doc
 
 def _get_cart_quotation(party=None):
+	'''Return the open Quotation of type "Shopping Cart" or make a new one'''
 	if not party:
 		party = get_party()
 
@@ -182,8 +183,7 @@
 			(party.doctype.lower()): party.name
 		})
 
-		qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
-			"customer": party.name})
+		qdoc.contact_person = frappe.db.get_value("Contact", {"email_id": frappe.session.user})
 		qdoc.contact_email = frappe.session.user
 
 		qdoc.flags.ignore_permissions = True
@@ -198,8 +198,7 @@
 	party.customer_name = company_name or fullname
 	party.customer_type == "Company" if company_name else "Individual"
 
-	contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
-		"customer": party.name})
+	contact_name = frappe.db.get_value("Contact", {"email_id": frappe.session.user})
 	contact = frappe.get_doc("Contact", contact_name)
 	contact.first_name = fullname
 	contact.last_name = None
@@ -291,10 +290,14 @@
 	if not user:
 		user = frappe.session.user
 
-	party = frappe.db.get_value("Contact", {"email_id": user}, ["customer", "supplier"], as_dict=1)
-	if party:
-		party_doctype = 'Customer' if party.customer else 'Supplier'
-		party = party.customer or party.supplier
+	contact_name = frappe.db.get_value("Contact", {"email_id": user})
+	party = None
+
+	if contact_name:
+		contact = frappe.get_doc('Contact', contact_name)
+		if contact.links:
+			party_doctype = contact.links[0].link_doctype
+			party = contact.links[0].link_name
 
 	cart_settings = frappe.get_doc("Shopping Cart Settings")
 
@@ -331,10 +334,10 @@
 
 		contact = frappe.new_doc("Contact")
 		contact.update({
-			"customer": customer.name,
 			"first_name": fullname,
 			"email_id": user
 		})
+		contact.append('links', dict(link_doctype='Customer', link_name=customer.name))
 		contact.flags.ignore_mandatory = True
 		contact.insert(ignore_permissions=True)
 
@@ -366,33 +369,25 @@
 		return debtors_account_name
 
 
-def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20, party=None):
+def get_address_docs(doctype=None, txt=None, filters=None, limit_start=0, limit_page_length=20,
+	party=None):
 	if not party:
 		party = get_party()
 
 	if not party:
 		return []
 
-	address_docs = frappe.db.sql("""select * from `tabAddress`
-		where `{0}`=%s order by name limit {1}, {2}""".format(party.doctype.lower(),
-			limit_start, limit_page_length), party.name,
-		as_dict=True, update={"doctype": "Address"})
+	address_names = frappe.db.get_all('Dynamic Link', fields=('parent'),
+		filters=dict(parenttype='Address', link_doctype=party.doctype, link_name=party.name))
 
-	for address in address_docs:
-		address.display = get_address_display(address)
+	out = []
 
-	return address_docs
+	for a in address_names:
+		address = frappe.get_doc('Address', a.parent)
+		address.display = get_address_display(address.as_dict())
+		out.append(address)
 
-def set_customer_in_address(doc, method=None):
-	if doc.flags.linked:
-		return
-
-	doc.check_if_linked()
-
-	if not doc.flags.linked and (frappe.db.get_value("User", frappe.session.user, "user_type") == "Website User"):
-		# creates a customer if one does not exist
-		get_party()
-		doc.link_address()
+	return out
 
 @frappe.whitelist()
 def apply_shipping_rule(shipping_rule):
diff --git a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
index b04b427..75880ad 100644
--- a/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
+++ b/erpnext/shopping_cart/doctype/shopping_cart_settings/shopping_cart_settings.json
@@ -23,6 +23,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Enable Shopping Cart", 
    "length": 0, 
    "no_copy": 0, 
@@ -49,6 +50,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -74,6 +76,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Company", 
    "length": 0, 
    "no_copy": 0, 
@@ -94,6 +97,7 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "description": "Prices will not be shown if Price List is not set", 
    "fieldname": "price_list", 
    "fieldtype": "Link", 
    "hidden": 0, 
@@ -101,6 +105,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Price List", 
    "length": 0, 
    "no_copy": 0, 
@@ -112,7 +117,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
@@ -129,6 +134,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -155,6 +161,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Customer Group", 
    "length": 0, 
    "no_copy": 0, 
@@ -182,6 +189,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Quotation Series", 
    "length": 0, 
    "no_copy": 0, 
@@ -209,6 +217,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Checkout Settings", 
    "length": 0, 
    "no_copy": 0, 
@@ -236,6 +245,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Enable Checkout", 
    "length": 0, 
    "no_copy": 0, 
@@ -265,6 +275,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Payment Success Url", 
    "length": 0, 
    "no_copy": 0, 
@@ -293,6 +304,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -319,6 +331,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Payment Gateway Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -347,7 +360,7 @@
  "issingle": 1, 
  "istable": 0, 
  "max_attachments": 0, 
- "modified": "2016-11-03 16:10:33.956822", 
+ "modified": "2017-01-17 05:30:29.333104", 
  "modified_by": "Administrator", 
  "module": "Shopping Cart", 
  "name": "Shopping Cart Settings", 
@@ -379,5 +392,6 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "sort_order": "ASC", 
+ "track_changes": 0, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/shopping_cart/test_shopping_cart.py b/erpnext/shopping_cart/test_shopping_cart.py
index 5282231..f221a8a 100644
--- a/erpnext/shopping_cart/test_shopping_cart.py
+++ b/erpnext/shopping_cart/test_shopping_cart.py
@@ -5,6 +5,7 @@
 import unittest
 import frappe
 from erpnext.shopping_cart.cart import _get_cart_quotation, update_cart, get_party
+from erpnext.tests.utils import create_test_contact_and_address
 
 class TestShoppingCart(unittest.TestCase):
 	"""
@@ -13,6 +14,7 @@
 	"""
 	def setUp(self):
 		frappe.set_user("Administrator")
+		create_test_contact_and_address()
 		self.enable_shopping_cart()
 
 	def tearDown(self):
@@ -25,8 +27,8 @@
 		# test if lead is created and quotation with new lead is fetched
 		quotation = _get_cart_quotation()
 		self.assertEquals(quotation.quotation_to, "Customer")
-		self.assertEquals(frappe.db.get_value("Contact", {"customer": quotation.customer}, "email_id"),
-			"test_cart_user@example.com")
+		self.assertEquals(quotation.contact_person,
+			frappe.db.get_value("Contact", dict(email_id="test_cart_user@example.com")))
 		self.assertEquals(quotation.lead, None)
 		self.assertEquals(quotation.contact_email, frappe.session.user)
 
@@ -101,7 +103,7 @@
 		quotation = self.create_quotation()
 
 		from erpnext.accounts.party import set_taxes
-		
+
 		tax_rule_master = set_taxes(quotation.customer, "Customer", \
 			quotation.transaction_date, quotation.company, None, None, \
 			quotation.customer_address, quotation.shipping_address_name, 1)
diff --git a/erpnext/shopping_cart/utils.py b/erpnext/shopping_cart/utils.py
index 50ce5cf..3241234 100644
--- a/erpnext/shopping_cart/utils.py
+++ b/erpnext/shopping_cart/utils.py
@@ -31,12 +31,11 @@
 
 def check_customer_or_supplier():
 	if frappe.session.user:
-		contacts = frappe.get_all("Contact", fields=["customer", "supplier", "email_id"],
-			filters={"email_id": frappe.session.user})
+		contact_name = frappe.get_value("Contact", {"email_id": frappe.session.user})
+		if contact_name:
+			contact = frappe.get_doc('Contact', contact_name)
+			for link in contact.links:
+				if link.link_doctype in ('Customer', 'Supplier'):
+					return link.link_doctype, link.link_name
 
-		customer = [d.customer for d in contacts if d.customer] or None
-		supplier = [d.supplier for d in contacts if d.supplier] or None
-
-		if customer: return 'Customer', customer
-		if supplier : return 'Supplier', supplier
 		return 'Customer', None
\ No newline at end of file
diff --git a/erpnext/startup/notifications.py b/erpnext/startup/notifications.py
index a1b90f9..554243f 100644
--- a/erpnext/startup/notifications.py
+++ b/erpnext/startup/notifications.py
@@ -11,8 +11,6 @@
 			"Task": {"status": "Overdue"},
 			"Project": {"status": "Open"},
 			"Item": {"total_projected_qty": ("<", 0)},
-			"Customer": {"status": "Open"},
-			"Supplier": {"status": "Open"},
 			"Lead": {"status": "Open"},
 			"Contact": {"status": "Open"},
 			"Opportunity": {"status": "Open"},
@@ -23,11 +21,11 @@
 			},
 			"Journal Entry": {"docstatus": 0},
 			"Sales Invoice": {
-				"outstanding_amount": (">", 0), 
-				"docstatus": ("<", 2) 
+				"outstanding_amount": (">", 0),
+				"docstatus": ("<", 2)
 			},
 			"Purchase Invoice": {
-				"outstanding_amount": (">", 0), 
+				"outstanding_amount": (">", 0),
 				"docstatus": ("<", 2)
 			},
 			"Payment Entry": {"docstatus": 0},
diff --git a/erpnext/stock/doctype/delivery_note/delivery_note.js b/erpnext/stock/doctype/delivery_note/delivery_note.js
index 204e98a..8f87198 100644
--- a/erpnext/stock/doctype/delivery_note/delivery_note.js
+++ b/erpnext/stock/doctype/delivery_note/delivery_note.js
@@ -137,13 +137,6 @@
 // for backward compatibility: combine new and previous states
 $.extend(cur_frm.cscript, new erpnext.stock.DeliveryNoteController({frm: cur_frm}));
 
-cur_frm.cscript.new_contact = function(){
-	tn = frappe.model.make_new_doc_and_get_name('Contact');
-	locals['Contact'][tn].is_customer = 1;
-	if(doc.customer) locals['Contact'][tn].customer = doc.customer;
-	frappe.set_route('Form', 'Contact', tn);
-}
-
 
 cur_frm.cscript.update_status = function(status) {
 	frappe.ui.form.is_saving = true;
diff --git a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
index e1ac06e..1147d8d 100644
--- a/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
+++ b/erpnext/stock/doctype/delivery_note_item/delivery_note_item.json
@@ -1477,6 +1477,34 @@
    "width": "120px"
   }, 
   {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "is_sample_item", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Sample Item", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -1691,7 +1719,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-12-24 12:33:37.728117", 
+ "modified": "2017-02-07 01:22:03.047137", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Delivery Note Item", 
diff --git a/erpnext/stock/doctype/item/item.js b/erpnext/stock/doctype/item/item.js
index 8844528..03c23d2 100644
--- a/erpnext/stock/doctype/item/item.js
+++ b/erpnext/stock/doctype/item/item.js
@@ -113,6 +113,12 @@
 
 	has_variants: function(frm) {
 		erpnext.item.toggle_attributes(frm);
+	},
+
+	show_in_website: function(frm) {
+		if (frm.doc.default_warehouse && !frm.doc.website_warehouse){
+			frm.set_value("website_warehouse", frm.doc.default_warehouse);
+		}
 	}
 });
 
@@ -212,7 +218,7 @@
 			return;
 
 		frappe.require('assets/js/item-dashboard.min.js', function() {
-			var section = frm.dashboard.add_section('<h5 style="margin-top: 0px;"><a href="#stock-balance">Stock Levels</a></h5>');
+			var section = frm.dashboard.add_section('<h5 style="margin-top: 0px;"><a href="#stock-balance">' + __("Stock Levels") + '</a></h5>');
 			erpnext.item.item_dashboard = new erpnext.stock.ItemDashboard({
 				parent: section,
 				item_code: frm.doc.name
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index da3de1e..6de497f 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -25,7 +25,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "", 
    "length": 0, 
    "no_copy": 0, 
@@ -53,7 +55,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Series", 
    "length": 0, 
    "no_copy": 0, 
@@ -81,7 +85,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 1, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Item Code", 
    "length": 0, 
    "no_copy": 1, 
@@ -111,7 +117,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 1, 
    "label": "Variant Of", 
    "length": 0, 
    "no_copy": 0, 
@@ -138,8 +146,10 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 1, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Item Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -167,7 +177,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Barcode", 
    "length": 0, 
    "no_copy": 1, 
@@ -193,8 +205,10 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 1, 
    "label": "Item Group", 
    "length": 0, 
    "no_copy": 0, 
@@ -224,7 +238,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Unit of Measure", 
    "length": 0, 
    "no_copy": 0, 
@@ -253,7 +269,9 @@
    "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, 
@@ -278,7 +296,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Disabled", 
    "length": 0, 
    "no_copy": 0, 
@@ -307,7 +327,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Maintain Stock", 
    "length": 0, 
    "no_copy": 0, 
@@ -337,7 +359,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Opening Stock", 
    "length": 0, 
    "no_copy": 0, 
@@ -355,44 +379,48 @@
   }, 
   {
    "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:(doc.__islocal && doc.is_stock_item && !doc.has_serial_no && !doc.has_batch_no && doc.opening_stock)", 
-   "fieldname": "valuation_rate", 
-   "fieldtype": "Currency", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "Valuation Rate", 
-   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "depends_on": "eval:(doc.is_stock_item && !doc.has_serial_no && !doc.has_batch_no)", 
+   "fieldname": "valuation_rate", 
+   "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": "Valuation Rate", 
+   "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_on_submit": 0, 
+   "bold": 1, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "standard_rate", 
    "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": "Standard Selling Rate", 
    "length": 0, 
    "no_copy": 0, 
@@ -419,7 +447,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Is Fixed Asset", 
    "length": 0, 
    "no_copy": 0, 
@@ -447,7 +477,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Asset Category", 
    "length": 0, 
    "no_copy": 0, 
@@ -475,7 +507,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Image", 
    "length": 0, 
    "no_copy": 0, 
@@ -503,7 +537,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -530,7 +566,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Brand", 
    "length": 0, 
    "no_copy": 0, 
@@ -559,7 +597,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -589,7 +629,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Inventory", 
    "length": 0, 
    "no_copy": 0, 
@@ -619,7 +661,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -650,7 +694,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "End of Life", 
    "length": 0, 
    "no_copy": 0, 
@@ -680,7 +726,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Has Batch No", 
    "length": 0, 
    "no_copy": 0, 
@@ -711,8 +759,10 @@
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Has Serial No", 
    "length": 0, 
    "no_copy": 0, 
@@ -743,7 +793,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Serial Number Series", 
    "length": 0, 
    "no_copy": 0, 
@@ -770,7 +822,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Material Request Type", 
    "length": 0, 
    "no_copy": 0, 
@@ -799,7 +853,9 @@
    "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, 
    "oldfieldtype": "Column Break", 
@@ -828,7 +884,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Allow over delivery or receipt upto this percent", 
    "length": 0, 
    "no_copy": 0, 
@@ -857,7 +915,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Valuation Method", 
    "length": 0, 
    "no_copy": 0, 
@@ -885,7 +945,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Warranty Period (in days)", 
    "length": 0, 
    "no_copy": 0, 
@@ -915,7 +977,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Net Weight", 
    "length": 0, 
    "no_copy": 0, 
@@ -942,7 +1006,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Weight UOM", 
    "length": 0, 
    "no_copy": 0, 
@@ -971,7 +1037,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Auto re-order", 
    "length": 0, 
    "no_copy": 0, 
@@ -1000,7 +1068,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Reorder level based on Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -1028,6 +1098,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "Units of Measure", 
@@ -1058,6 +1129,7 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
    "in_standard_filter": 0, 
    "label": "UOMs", 
@@ -1090,7 +1162,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Variants", 
    "length": 0, 
    "no_copy": 0, 
@@ -1120,7 +1194,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Has Variants", 
    "length": 0, 
    "no_copy": 1, 
@@ -1149,7 +1225,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Attributes", 
    "length": 0, 
    "no_copy": 1, 
@@ -1177,7 +1255,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Purchase Details", 
    "length": 0, 
    "no_copy": 0, 
@@ -1206,7 +1286,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Is Purchase Item", 
    "length": 0, 
    "no_copy": 0, 
@@ -1236,7 +1318,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Minimum Order Qty", 
    "length": 0, 
    "no_copy": 0, 
@@ -1264,7 +1348,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Safety Stock", 
    "length": 0, 
    "no_copy": 0, 
@@ -1293,7 +1379,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Lead Time in days", 
    "length": 0, 
    "no_copy": 0, 
@@ -1323,7 +1411,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Buying Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -1354,7 +1444,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Expense Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -1384,7 +1476,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Last Purchase Rate", 
    "length": 0, 
    "no_copy": 1, 
@@ -1413,7 +1507,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Supplier Details", 
    "length": 0, 
    "no_copy": 0, 
@@ -1441,7 +1537,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Supplier", 
    "length": 0, 
    "no_copy": 0, 
@@ -1468,7 +1566,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Delivered by Supplier (Drop Ship)", 
    "length": 0, 
    "no_copy": 0, 
@@ -1496,7 +1596,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Manufacturer", 
    "length": 0, 
    "no_copy": 0, 
@@ -1524,7 +1626,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Manufacturer Part Number", 
    "length": 0, 
    "no_copy": 0, 
@@ -1551,7 +1655,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Item Code for Suppliers", 
    "length": 0, 
    "no_copy": 0, 
@@ -1580,7 +1686,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Supplier Items", 
    "length": 0, 
    "no_copy": 0, 
@@ -1607,7 +1715,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Sales Details", 
    "length": 0, 
    "no_copy": 0, 
@@ -1636,7 +1746,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Is Sales Item", 
    "length": 0, 
    "no_copy": 0, 
@@ -1665,7 +1777,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Publish in Hub", 
    "length": 0, 
    "no_copy": 0, 
@@ -1693,7 +1807,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Synced With Hub", 
    "length": 0, 
    "no_copy": 0, 
@@ -1721,7 +1837,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Income Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -1749,7 +1867,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default Selling Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -1777,7 +1897,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Customer Item Codes", 
    "length": 0, 
    "no_copy": 0, 
@@ -1807,7 +1929,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Customer Items", 
    "length": 0, 
    "no_copy": 0, 
@@ -1835,7 +1959,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Max Discount (%)", 
    "length": 0, 
    "no_copy": 0, 
@@ -1863,7 +1989,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Item Tax", 
    "length": 0, 
    "no_copy": 0, 
@@ -1892,7 +2020,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Taxes", 
    "length": 0, 
    "no_copy": 0, 
@@ -1921,7 +2051,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Inspection Criteria", 
    "length": 0, 
    "no_copy": 0, 
@@ -1950,7 +2082,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Inspection Required before Purchase", 
    "length": 0, 
    "no_copy": 0, 
@@ -1979,7 +2113,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Inspection Required before Delivery", 
    "length": 0, 
    "no_copy": 0, 
@@ -2008,7 +2144,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Quality Parameters", 
    "length": 0, 
    "no_copy": 0, 
@@ -2038,7 +2176,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Manufacturing", 
    "length": 0, 
    "no_copy": 0, 
@@ -2067,7 +2207,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Default BOM", 
    "length": 0, 
    "no_copy": 1, 
@@ -2098,7 +2240,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Supply Raw Materials for Purchase", 
    "length": 0, 
    "no_copy": 0, 
@@ -2127,7 +2271,9 @@
    "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, 
@@ -2152,8 +2298,10 @@
    "hidden": 1, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Customer Code", 
    "length": 0, 
    "no_copy": 1, 
@@ -2179,7 +2327,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website", 
    "length": 0, 
    "no_copy": 0, 
@@ -2207,7 +2357,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Show in Website", 
    "length": 0, 
    "no_copy": 0, 
@@ -2234,7 +2386,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Show in Website (Variant)", 
    "length": 0, 
    "no_copy": 0, 
@@ -2262,7 +2416,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Route", 
    "length": 0, 
    "no_copy": 0, 
@@ -2291,7 +2447,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Weightage", 
    "length": 0, 
    "no_copy": 0, 
@@ -2319,7 +2477,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Slideshow", 
    "length": 0, 
    "no_copy": 0, 
@@ -2348,7 +2508,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Image", 
    "length": 0, 
    "no_copy": 0, 
@@ -2375,7 +2537,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Thumbnail", 
    "length": 0, 
    "no_copy": 0, 
@@ -2402,7 +2566,9 @@
    "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, 
@@ -2429,7 +2595,9 @@
    "ignore_user_permissions": 1, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -2458,7 +2626,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website Item Groups", 
    "length": 0, 
    "no_copy": 0, 
@@ -2487,7 +2657,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website Specifications", 
    "length": 0, 
    "no_copy": 0, 
@@ -2514,7 +2686,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Copy From Item Group", 
    "length": 0, 
    "no_copy": 0, 
@@ -2541,7 +2715,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website Specifications", 
    "length": 0, 
    "no_copy": 0, 
@@ -2569,7 +2745,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Website Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -2595,7 +2773,9 @@
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
+   "in_global_search": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Total Projected Qty", 
    "length": 0, 
    "no_copy": 0, 
@@ -2624,7 +2804,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 1, 
- "modified": "2017-01-10 12:02:51.807965", 
+ "modified": "2017-02-14 22:49:44.664910", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item", 
@@ -2640,7 +2820,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 1, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -2661,7 +2840,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -2682,7 +2860,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 1, 
    "read": 1, 
@@ -2703,7 +2880,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2724,7 +2900,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2745,7 +2920,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2766,7 +2940,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2787,7 +2960,6 @@
    "export": 0, 
    "if_owner": 0, 
    "import": 0, 
-   "is_custom": 0, 
    "permlevel": 0, 
    "print": 0, 
    "read": 1, 
@@ -2803,8 +2975,10 @@
  "read_only": 0, 
  "read_only_onload": 0, 
  "search_fields": "item_name,description,item_group,customer_code", 
+ "show_name_in_global_search": 0, 
  "sort_field": "idx desc, modified desc", 
  "sort_order": "DESC", 
  "title_field": "item_name", 
+ "track_changes": 1, 
  "track_seen": 0
 }
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index 53faa43..d20ba49 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -451,24 +451,32 @@
 				"valuation_method", "has_batch_no", "is_fixed_asset")
 
 			vals = frappe.db.get_value("Item", self.name, to_check, as_dict=True)
+			if not vals.get('valuation_method') and self.get('valuation_method'):
+				vals['valuation_method'] = frappe.db.get_single_value("Stock Settings", "valuation_method") or "FIFO"
 
 			if vals:
 				for key in to_check:
-					if self.get(key) != vals.get(key):
-						if not self.check_if_linked_document_exists():
+					if cstr(self.get(key)) != cstr(vals.get(key)):
+						if not self.check_if_linked_document_exists(key):
 							break # no linked document, allowed
 						else:
-							frappe.throw(_("As there are existing transactions for this item, you can not change the value of {0}").format(frappe.bold(self.meta.get_label(key))))
+							frappe.throw(_("As there are existing transactions against item {0}, you can not change the value of {1}").format(self.name, frappe.bold(self.meta.get_label(key))))
 
 			if vals and not self.is_fixed_asset and self.is_fixed_asset != vals.is_fixed_asset:
 				asset = frappe.db.get_all("Asset", filters={"item_code": self.name, "docstatus": 1}, limit=1)
 				if asset:
 					frappe.throw(_('"Is Fixed Asset" cannot be unchecked, as Asset record exists against the item'))
 
-	def check_if_linked_document_exists(self):
-		for doctype in ("Sales Order Item", "Delivery Note Item", "Sales Invoice Item",
-			"Material Request Item", "Purchase Order Item", "Purchase Receipt Item",
-			"Purchase Invoice Item", "Stock Entry Detail", "Stock Reconciliation Item"):
+	def check_if_linked_document_exists(self, key):
+		linked_doctypes = ["Delivery Note Item", "Sales Invoice Item", "Purchase Receipt Item",
+			"Purchase Invoice Item", "Stock Entry Detail", "Stock Reconciliation Item"]
+			
+		# For "Is Stock Item", following doctypes is important 
+		# because reserved_qty, ordered_qty and requested_qty updated from these doctypes
+		if key == "is_stock_item":
+			linked_doctypes += ["Sales Order Item", "Purchase Order Item", "Material Request Item"]
+			
+		for doctype in linked_doctypes:
 			if frappe.db.get_value(doctype, filters={"item_code": self.name, "docstatus": 1}) or \
 				frappe.db.get_value("Production Order",
 					filters={"production_item": self.name, "docstatus": 1}):
diff --git a/erpnext/stock/doctype/item/test_records.json b/erpnext/stock/doctype/item/test_records.json
index c05c5f3..aad8ed0 100644
--- a/erpnext/stock/doctype/item/test_records.json
+++ b/erpnext/stock/doctype/item/test_records.json
@@ -15,6 +15,7 @@
   "item_group": "_Test Item Group",
   "item_name": "_Test Item",
   "apply_warehouse_wise_reorder_level": 1,
+  "valuation_rate": 100,
   "reorder_levels": [
    {
     "material_request_type": "Purchase",
@@ -61,6 +62,7 @@
   "item_code": "_Test Item Home Desktop 100",
   "item_group": "_Test Item Group Desktops",
   "item_name": "_Test Item Home Desktop 100",
+  "valuation_rate": 100,
   "taxes": [
    {
     "doctype": "Item Tax",
diff --git a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
index aacf02c..0eaf5ba 100644
--- a/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
+++ b/erpnext/stock/doctype/landed_cost_voucher/landed_cost_voucher.py
@@ -12,22 +12,23 @@
 	def get_items_from_purchase_receipts(self):
 		self.set("items", [])
 		for pr in self.get("purchase_receipts"):
-			pr_items = frappe.db.sql("""select pr_item.item_code, pr_item.description,
-				pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name
-				from `tab{doctype} Item` pr_item where parent = %s
-				and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)
-				""".format(doctype=pr.receipt_document_type), pr.receipt_document, as_dict=True)
+			if pr.receipt_document_type and pr.receipt_document:
+				pr_items = frappe.db.sql("""select pr_item.item_code, pr_item.description,
+					pr_item.qty, pr_item.base_rate, pr_item.base_amount, pr_item.name
+					from `tab{doctype} Item` pr_item where parent = %s
+					and exists(select name from tabItem where name = pr_item.item_code and is_stock_item = 1)
+					""".format(doctype=pr.receipt_document_type), pr.receipt_document, as_dict=True)
 
-			for d in pr_items:
-				item = self.append("items")
-				item.item_code = d.item_code
-				item.description = d.description
-				item.qty = d.qty
-				item.rate = d.base_rate
-				item.amount = d.base_amount
-				item.receipt_document_type = pr.receipt_document_type
-				item.receipt_document = pr.receipt_document
-				item.purchase_receipt_item = d.name
+				for d in pr_items:
+					item = self.append("items")
+					item.item_code = d.item_code
+					item.description = d.description
+					item.qty = d.qty
+					item.rate = d.base_rate
+					item.amount = d.base_amount
+					item.receipt_document_type = pr.receipt_document_type
+					item.receipt_document = pr.receipt_document
+					item.purchase_receipt_item = d.name
 
 	def validate(self):
 		self.check_mandatory()
diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
index 457a7c2..c843d7d 100644
--- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
+++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.js
@@ -26,7 +26,7 @@
 				]
 			}
 		});
-		
+
 	}
 });
 
@@ -122,26 +122,6 @@
 	})
 }
 
-cur_frm.fields_dict['supplier_address'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters: { 'supplier': doc.supplier}
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return {
-		filters: { 'supplier': doc.supplier }
-	}
-}
-
-cur_frm.cscript.new_contact = function() {
-	tn = frappe.model.make_new_doc_and_get_name('Contact');
-	locals['Contact'][tn].is_supplier = 1;
-	if(doc.supplier)
-		locals['Contact'][tn].supplier = doc.supplier;
-	frappe.set_route('Form', 'Contact', tn);
-}
-
 cur_frm.fields_dict['items'].grid.get_field('project').get_query = function(doc, cdt, cdn) {
 	return {
 		filters: [
diff --git a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
index f961cdd..7421e01 100644
--- a/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
+++ b/erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
@@ -8,6 +8,7 @@
 import frappe.defaults
 from frappe.utils import cint, flt, cstr, today
 from erpnext.stock.doctype.purchase_receipt.purchase_receipt import make_purchase_invoice
+from erpnext import set_perpetual_inventory
 
 class TestPurchaseReceipt(unittest.TestCase):
 	def test_make_purchase_invoice(self):
@@ -26,10 +27,10 @@
 
 	def test_purchase_receipt_no_gl_entry(self):
 		set_perpetual_inventory(0)
-		
+
 		existing_bin_stock_value = frappe.db.get_value("Bin", {"item_code": "_Test Item",
 			"warehouse": "_Test Warehouse - _TC"}, "stock_value")
-		
+
 		pr = make_purchase_receipt()
 
 		stock_value_difference = frappe.db.get_value("Stock Ledger Entry",
@@ -78,22 +79,22 @@
 
 	def test_subcontracting(self):
 		from erpnext.stock.doctype.stock_entry.test_stock_entry import make_stock_entry
-		
+
 		make_stock_entry(item_code="_Test Item", target="_Test Warehouse 1 - _TC", qty=100, basic_rate=100)
-		make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC", 
+		make_stock_entry(item_code="_Test Item Home Desktop 100", target="_Test Warehouse 1 - _TC",
 			qty=100, basic_rate=100)
-		
+
 		pr = make_purchase_receipt(item_code="_Test FG Item", qty=10, rate=500, is_subcontracted="Yes")
 		self.assertEquals(len(pr.get("supplied_items")), 2)
-		
+
 		rm_supp_cost = sum([d.amount for d in pr.get("supplied_items")])
 		self.assertEquals(pr.get("items")[0].rm_supp_cost, flt(rm_supp_cost, 2))
 
 	def test_serial_no_supplier(self):
 		pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
-		self.assertEquals(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"), 
+		self.assertEquals(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "supplier"),
 			pr.supplier)
-		
+
 		pr.cancel()
 		self.assertFalse(frappe.db.get_value("Serial No", pr.get("items")[0].serial_no, "warehouse"))
 
@@ -118,21 +119,21 @@
 		for serial_no in rejected_serial_nos:
 			self.assertEquals(frappe.db.get_value("Serial No", serial_no, "warehouse"),
 				pr.get("items")[0].rejected_warehouse)
-				
+
 	def test_purchase_return(self):
 		set_perpetual_inventory()
-		
+
 		pr = make_purchase_receipt()
-		
+
 		return_pr = make_purchase_receipt(is_return=1, return_against=pr.name, qty=-2)
 
 		# check sle
-		outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt", 
+		outgoing_rate = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
 			"voucher_no": return_pr.name}, "outgoing_rate")
-			
+
 		self.assertEqual(outgoing_rate, 50)
-		
-		
+
+
 		# check gl entries for return
 		gl_entries = get_gl_entries("Purchase Receipt", return_pr.name)
 
@@ -146,7 +147,7 @@
 		for gle in gl_entries:
 			self.assertEquals(expected_values[gle.account][0], gle.debit)
 			self.assertEquals(expected_values[gle.account][1], gle.credit)
-		
+
 		set_perpetual_inventory(0)
 
 	def test_purchase_return_for_rejected_qty(self):
@@ -158,7 +159,7 @@
 
 		actual_qty = frappe.db.get_value("Stock Ledger Entry", {"voucher_type": "Purchase Receipt",
 			"voucher_no": return_pr.name, 'warehouse': return_pr.items[0].rejected_warehouse}, "actual_qty")
-		
+
 		self.assertEqual(actual_qty, -2)
 
 		set_perpetual_inventory(0)
@@ -168,87 +169,82 @@
 			serial_no = frappe.get_doc("Serial No", serial_no)
 			for field, value in field_values.items():
 				self.assertEquals(cstr(serial_no.get(field)), value)
-		
+
 		from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos
-		
+
 		pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=1)
-		
+
 		serial_no = get_serial_nos(pr.get("items")[0].serial_no)[0]
-		
+
 		_check_serial_no_values(serial_no, {
 			"warehouse": "_Test Warehouse - _TC",
 			"purchase_document_no": pr.name
 		})
-		
-		return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1, 
+
+		return_pr = make_purchase_receipt(item_code="_Test Serialized Item With Series", qty=-1,
 			is_return=1, return_against=pr.name, serial_no=serial_no)
-			
+
 		_check_serial_no_values(serial_no, {
 			"warehouse": "",
 			"purchase_document_no": pr.name,
 			"delivery_document_no": return_pr.name
 		})
-	
+
 	def test_closed_purchase_receipt(self):
 		from erpnext.stock.doctype.purchase_receipt.purchase_receipt import update_purchase_receipt_status
-		
+
 		pr = make_purchase_receipt(do_not_submit=True)
 		pr.submit()
-		
+
 		update_purchase_receipt_status(pr.name, "Closed")
 		self.assertEquals(frappe.db.get_value("Purchase Receipt", pr.name, "status"), "Closed")
-		
+
 	def test_pr_billing_status(self):
 		# PO -> PR1 -> PI and PO -> PI and PO -> PR2
 		from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
 		from erpnext.buying.doctype.purchase_order.purchase_order \
 			import make_purchase_receipt, make_purchase_invoice as make_purchase_invoice_from_po
-		
+
 		po = create_purchase_order()
-		
+
 		pr1 = make_purchase_receipt(po.name)
 		pr1.posting_date = today()
 		pr1.posting_time = "10:00"
 		pr1.get("items")[0].received_qty = 2
 		pr1.get("items")[0].qty = 2
 		pr1.submit()
-		
+
 		pi1 = make_purchase_invoice(pr1.name)
 		pi1.submit()
-		
+
 		pr1.load_from_db()
 		self.assertEqual(pr1.per_billed, 100)
-		
+
 		pi2 = make_purchase_invoice_from_po(po.name)
 		pi2.get("items")[0].qty = 4
 		pi2.submit()
-		
+
 		pr2 = make_purchase_receipt(po.name)
 		pr2.posting_date = today()
 		pr2.posting_time = "08:00"
 		pr2.get("items")[0].received_qty = 5
 		pr2.get("items")[0].qty = 5
 		pr2.submit()
-		
+
 		pr1.load_from_db()
 		self.assertEqual(pr1.get("items")[0].billed_amt, 1000)
 		self.assertEqual(pr1.per_billed, 100)
 		self.assertEqual(pr1.status, "Completed")
-		
+
 		self.assertEqual(pr2.get("items")[0].billed_amt, 2000)
 		self.assertEqual(pr2.per_billed, 80)
 		self.assertEqual(pr2.status, "To Bill")
-		
+
 def get_gl_entries(voucher_type, voucher_no):
 	return frappe.db.sql("""select account, debit, credit
 		from `tabGL Entry` where voucher_type=%s and voucher_no=%s
 		order by account desc""", (voucher_type, voucher_no), as_dict=1)
 
-def set_perpetual_inventory(enable=1):
-	accounts_settings = frappe.get_doc("Accounts Settings")
-	accounts_settings.auto_accounting_for_stock = enable
-	accounts_settings.save()
-	
 def make_purchase_receipt(**args):
 	pr = frappe.new_doc("Purchase Receipt")
 	args = frappe._dict(args)
diff --git a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
index d8449f1..5903713 100755
--- a/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
+++ b/erpnext/stock/doctype/purchase_receipt_item/purchase_receipt_item.json
@@ -1575,6 +1575,34 @@
    "unique": 0
   }, 
   {
+   "allow_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
+   "fieldname": "is_sample_item", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Sample Item", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
@@ -1885,7 +1913,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-11-16 16:04:21.778869", 
+ "modified": "2017-02-07 01:21:36.348032", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Purchase Receipt Item", 
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.js b/erpnext/stock/doctype/stock_entry/stock_entry.js
index b410802..cc867a8 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.js
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.js
@@ -2,6 +2,188 @@
 
 frappe.provide("erpnext.stock");
 
+frappe.ui.form.on('Stock Entry', {
+	setup: function(frm) {
+		$.extend(frm.cscript, new erpnext.stock.StockEntry({frm: frm}));
+
+		frm.set_query('production_order', function() {
+			return {
+				filters: [
+					['Production Order', 'docstatus', '=', 1],
+					['Production Order', 'qty', '>','`tabProduction Order`.produced_qty'],
+					['Production Order', 'company', '=', frm.doc.company]
+				]
+			}
+		});
+	// },
+	// onload_post_render: function(frm) {
+
+		frm.set_query('batch_no', 'items', function(doc, cdt, cdn) {
+			var item = locals[cdt][cdn];
+			if(!item.item_code) {
+				frappe.throw(__("Please enter Item Code to get Batch Number"));
+			} else {
+				if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"], doc.purpose)) {
+					var filters = {
+						'item_code': item.item_code,
+						'posting_date': frm.doc.posting_date || nowdate()
+					}
+				} else {
+					var filters = {
+						'item_code': item.item_code
+					}
+				}
+
+				if(item.s_warehouse) filters["warehouse"] = item.s_warehouse;
+				return {
+					query : "erpnext.controllers.queries.get_batch_no",
+					filters: filters
+				}
+			}
+		});
+	},
+	refresh: function(frm) {
+		if(!frm.doc.docstatus) {
+			frm.add_custom_button(__('Make Material Request'), function() {
+				frappe.model.with_doctype('Material Request', function() {
+					var mr = frappe.model.get_new_doc('Material Request');
+					var items = frm.get_field('items').grid.get_selected_children();
+					if(!items.length) {
+						items = frm.doc.items;
+					}
+					items.forEach(function(item) {
+						var mr_item = frappe.model.add_child(mr, 'items');
+						mr_item.item_code = item.item_code;
+						mr_item.item_name = item.item_name;
+						mr_item.uom = item.uom;
+						mr_item.item_group = item.item_group;
+						mr_item.description = item.description;
+						mr_item.image = item.image;
+						mr_item.qty = item.qty;
+						mr_item.warehouse = item.s_warehouse;
+						mr_item.required_date = frappe.datetime.nowdate();
+					});
+					frappe.set_route('Form', 'Material Request', mr.name);
+				});
+			});
+		}
+	},
+	purpose: function(frm) {
+		frm.fields_dict.items.grid.refresh();
+		frm.cscript.toggle_related_fields(frm.doc);
+	},
+	company: function(frm) {
+		if(frm.doc.company) {
+			var company_doc = frappe.get_doc(":Company", frm.doc.company);
+			if(company_doc.default_letter_head) {
+				frm.set_value("letter_head", company_doc.default_letter_head);
+			}
+		}
+	},
+	set_serial_no: function(frm, cdt, cdn) {
+		var d = frappe.model.get_doc(cdt, cdn);
+		if(!d.item_code && !d.s_warehouse && !d.qty) return;
+		var	args = {
+			'item_code'	: d.item_code,
+			'warehouse'	: cstr(d.s_warehouse),
+			'qty'		: d.qty
+		};
+		frappe.call({
+			method: "erpnext.stock.get_item_details.get_serial_no",
+			args: {"args": args},
+			callback: function(r) {
+				if (!r.exe){
+					frappe.model.set_value(cdt, cdn, "serial_no", r.message);
+				}
+			}
+		});
+	},
+})
+
+frappe.ui.form.on('Stock Entry Detail', {
+	qty: function(frm, cdt, cdn) {
+		frm.events.set_serial_no(frm, cdt, cdn);
+	},
+
+	s_warehouse: function(frm, cdt, cdn) {
+		frm.events.set_serial_no(frm, cdt, cdn);
+	},
+	barcode: function(doc, cdt, cdn) {
+		var d = locals[cdt][cdn];
+		if (d.barcode) {
+			frappe.call({
+				method: "erpnext.stock.get_item_details.get_item_code",
+				args: {"barcode": d.barcode },
+				callback: function(r) {
+					if (!r.exe){
+						frappe.model.set_value(cdt, cdn, "item_code", r.message);
+					}
+				}
+			});
+		}
+	},
+	uom: function(doc, cdt, cdn) {
+		var d = locals[cdt][cdn];
+		if(d.uom && d.item_code){
+			return frappe.call({
+				method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details",
+				args: {
+					item_code: d.item_code,
+					uom: d.uom,
+					qty: d.qty
+				},
+				callback: function(r) {
+					if(r.message) {
+						frappe.model.set_value(cdt, cdn, r.message);
+					}
+				}
+			});
+		}
+	},
+	item_code: function(frm, cdt, cdn) {
+		var d = locals[cdt][cdn];
+		if(d.item_code) {
+			args = {
+				'item_code'			: d.item_code,
+				'warehouse'			: cstr(d.s_warehouse) || cstr(d.t_warehouse),
+				'transfer_qty'		: d.transfer_qty,
+				'serial_no	'		: d.serial_no,
+				'bom_no'			: d.bom_no,
+				'expense_account'	: d.expense_account,
+				'cost_center'		: d.cost_center,
+				'company'			: frm.doc.company,
+				'qty'				: d.qty
+			};
+			return frappe.call({
+				doc: frm.doc,
+				method: "get_item_details",
+				args: args,
+				callback: function(r) {
+					if(r.message) {
+						var d = locals[cdt][cdn];
+						$.each(r.message, function(k, v) {
+							d[k] = v;
+						});
+						refresh_field("items");
+					}
+				}
+			});
+		}
+	},
+	expense_account: function(frm, cdt, cdn) {
+		erpnext.utils.copy_value_in_all_row(frm.doc, cdt, cdn, "items", "expense_account");
+	},
+	cost_center: function(doc, cdt, cdn) {
+		erpnext.utils.copy_value_in_all_row(frm.doc, cdt, cdn, "items", "cost_center");
+	}
+});
+
+frappe.ui.form.on('Landed Cost Taxes and Charges', {
+	amount: function(frm) {
+		frm.events.calculate_amount();
+	}
+});
+
 erpnext.stock.StockEntry = erpnext.stock.StockController.extend({
 	setup: function() {
 		var me = this;
@@ -41,13 +223,17 @@
 				}
 			}
 		}
+
+		this.frm.set_indicator_formatter('item_code',
+			function(doc) { return (doc.qty<=doc.actual_qty) ? "green" : "orange" })
+
 	},
 
 	onload_post_render: function() {
 		var me = this;
 		this.set_default_account(function() {
 			if(me.frm.doc.__islocal && me.frm.doc.company && !me.frm.doc.amended_from) {
-				cur_frm.script_manager.trigger("company");
+				me.frm.trigger("company");
 			}
 		});
 
@@ -176,7 +362,7 @@
 				excise.voucher_type = 'Excise Entry';
 				frappe.set_route('Form', 'Journal Entry', excise.name);
 			}, __("Make"));
-			cur_frm.page.set_inner_btn_group_as_primary(__("Make"));
+			this.frm.page.set_inner_btn_group_as_primary(__("Make"));
 	},
 
 	items_add: function(doc, cdt, cdn) {
@@ -305,204 +491,32 @@
 
 		this.frm.set_value("total_additional_costs", flt(total_additional_costs, precision("total_additional_costs")));
 	},
-});
 
-cur_frm.script_manager.make(erpnext.stock.StockEntry);
+	toggle_related_fields: function(doc) {
+		this.frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt');
+		this.frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue');
 
-cur_frm.cscript.toggle_related_fields = function(doc) {
-	cur_frm.toggle_enable("from_warehouse", doc.purpose!='Material Receipt');
-	cur_frm.toggle_enable("to_warehouse", doc.purpose!='Material Issue');
+		this.frm.fields_dict["items"].grid.set_column_disp("s_warehouse", doc.purpose!='Material Receipt');
+		this.frm.fields_dict["items"].grid.set_column_disp("t_warehouse", doc.purpose!='Material Issue');
 
-	cur_frm.fields_dict["items"].grid.set_column_disp("s_warehouse", doc.purpose!='Material Receipt');
-	cur_frm.fields_dict["items"].grid.set_column_disp("t_warehouse", doc.purpose!='Material Issue');
+		this.frm.cscript.toggle_enable_bom();
 
-	cur_frm.cscript.toggle_enable_bom();
-
-	if (doc.purpose == 'Subcontract') {
-		doc.customer = doc.customer_name = doc.customer_address =
-			doc.delivery_note_no = doc.sales_invoice_no = null;
-	} else {
-		doc.customer = doc.customer_name = doc.customer_address =
-			doc.delivery_note_no = doc.sales_invoice_no = doc.supplier =
-			doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null;
-	}
-	if(doc.purpose == "Material Receipt") {
-		cur_frm.set_value("from_bom", 0);
-	}
-
-	// Addition costs based on purpose
-	cur_frm.toggle_display(["additional_costs", "total_additional_costs", "additional_costs_section"],
-		doc.purpose!='Material Issue');
-
-	cur_frm.fields_dict["items"].grid.set_column_disp("additional_cost", doc.purpose!='Material Issue');
-}
-
-cur_frm.fields_dict['production_order'].get_query = function(doc) {
-	return {
-		filters: [
-			['Production Order', 'docstatus', '=', 1],
-			['Production Order', 'qty', '>','`tabProduction Order`.produced_qty'],
-			['Production Order', 'company', '=', cur_frm.doc.company]
-		]
-	}
-}
-
-cur_frm.cscript.purpose = function(doc, cdt, cdn) {
-	cur_frm.fields_dict.items.grid.refresh();
-	cur_frm.cscript.toggle_related_fields(doc);
-}
-
-// Overloaded query for link batch_no
-cur_frm.fields_dict['items'].grid.get_field('batch_no').get_query = function(doc, cdt, cdn) {
-	var item = locals[cdt][cdn];
-	if(!item.item_code) {
-		frappe.throw(__("Please enter Item Code to get batch no"));
-	}
-	else {
-		if (in_list(["Material Transfer for Manufacture", "Manufacture", "Repack", "Subcontract"], doc.purpose)) {
-			var filters = {
-				'item_code': item.item_code,
-				'posting_date': me.frm.doc.posting_date || nowdate()
-			}
+		if (doc.purpose == 'Subcontract') {
+			doc.customer = doc.customer_name = doc.customer_address =
+				doc.delivery_note_no = doc.sales_invoice_no = null;
 		} else {
-			var filters = {
-				'item_code': item.item_code
-			}
+			doc.customer = doc.customer_name = doc.customer_address =
+				doc.delivery_note_no = doc.sales_invoice_no = doc.supplier =
+				doc.supplier_name = doc.supplier_address = doc.purchase_receipt_no = null;
+		}
+		if(doc.purpose == "Material Receipt") {
+			this.frm.set_value("from_bom", 0);
 		}
 
+		// Addition costs based on purpose
+		this.frm.toggle_display(["additional_costs", "total_additional_costs", "additional_costs_section"],
+			doc.purpose!='Material Issue');
 
-		if(item.s_warehouse) filters["warehouse"] = item.s_warehouse
-		return {
-			query : "erpnext.controllers.queries.get_batch_no",
-			filters: filters
-		}
+		this.frm.fields_dict["items"].grid.set_column_disp("additional_cost", doc.purpose!='Material Issue');
 	}
-}
-
-cur_frm.cscript.validate = function(doc, cdt, cdn) {
-	cur_frm.cscript.validate_items(doc);
-}
-
-cur_frm.cscript.validate_items = function(doc) {
-	cl = doc.items || [];
-	if (!cl.length) {
-		msgprint(__("Item table can not be blank"));
-		validated = false;
-	}
-}
-
-cur_frm.cscript.expense_account = function(doc, cdt, cdn) {
-	erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "expense_account");
-}
-
-cur_frm.cscript.cost_center = function(doc, cdt, cdn) {
-	erpnext.utils.copy_value_in_all_row(doc, cdt, cdn, "items", "cost_center");
-}
-
-
-frappe.ui.form.on('Landed Cost Taxes and Charges', {
-	amount: function(frm) {
-		frm.cscript.calculate_amount();
-	}
-})
-
-frappe.ui.form.on('Stock Entry Detail', {
-	qty: function(frm, cdt, cdn) {
-		frm.events.set_serial_no(frm, cdt, cdn);
-	},
-
-	s_warehouse: function(frm, cdt, cdn) {
-		frm.events.set_serial_no(frm, cdt, cdn);
-	},
-	barcode: function(doc, cdt, cdn) {
-		var d = locals[cdt][cdn];
-		if (d.barcode) {
-			frappe.call({
-				method: "erpnext.stock.get_item_details.get_item_code",
-				args: {"barcode": d.barcode },
-				callback: function(r) {
-					if (!r.exe){
-						frappe.model.set_value(cdt, cdn, "item_code", r.message);
-					}
-				}
-			});
-		}
-	},
-	uom: function(doc, cdt, cdn) {
-		var d = locals[cdt][cdn];
-		if(d.uom && d.item_code){
-			return frappe.call({
-				method: "erpnext.stock.doctype.stock_entry.stock_entry.get_uom_details",
-				args: {
-					item_code: d.item_code,
-					uom: d.uom,
-					qty: d.qty
-				},
-				callback: function(r) {
-					if(r.message) {
-						frappe.model.set_value(cdt, cdn, r.message);
-					}
-				}
-			});
-		}
-	},
-	item_code: function(doc, cdt, cdn) {
-		var d = locals[cdt][cdn];
-		if(d.item_code) {
-			args = {
-				'item_code'			: d.item_code,
-				'warehouse'			: cstr(d.s_warehouse) || cstr(d.t_warehouse),
-				'transfer_qty'		: d.transfer_qty,
-				'serial_no	'		: d.serial_no,
-				'bom_no'			: d.bom_no,
-				'expense_account'	: d.expense_account,
-				'cost_center'		: d.cost_center,
-				'company'			: cur_frm.doc.company,
-				'qty'				: d.qty
-			};
-			return frappe.call({
-				doc: cur_frm.doc,
-				method: "get_item_details",
-				args: args,
-				callback: function(r) {
-					if(r.message) {
-						var d = locals[cdt][cdn];
-						$.each(r.message, function(k, v) {
-							d[k] = v;
-						});
-						refresh_field("items");
-					}
-				}
-			});
-		}
-	}
-})
-
-frappe.ui.form.on('Stock Entry', {
-	company: function(doc, cdt, cdn) {
-		if(doc.company) {
-			var company_doc = frappe.get_doc(":Company", doc.company);
-			if(company_doc.default_letter_head) {
-				cur_frm.set_value("letter_head", company_doc.default_letter_head);
-			}
-		}
-	},
-	set_serial_no: function(doc, cdt, cdn) {
-		var d = frappe.model.get_doc(cdt, cdn);
-		if(!d.item_code && !d.s_warehouse && !d.qty) return;
-		var	args = {
-				'item_code'	: d.item_code,
-				'warehouse'	: cstr(d.s_warehouse),
-				'qty'		: d.qty
-			};
-			frappe.call({
-				method: "erpnext.stock.get_item_details.get_serial_no",
-				args: {"args": args},
-				callback: function(r) {
-					if (!r.exe){
-						frappe.model.set_value(cdt, cdn, "serial_no", r.message);
-					}
-				}
-			});
-		},
-})
+});
\ No newline at end of file
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 1199593..107c85c 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -219,9 +219,9 @@
 
 			# validate qty during submit
 			if d.docstatus==1 and d.s_warehouse and not allow_negative_stock and d.actual_qty < d.transfer_qty:
-				frappe.throw(_("Row {0}: Qty not available for {4} in warehouse {1} at posting time of the entry ({2} {3})".format(d.idx,
+				frappe.throw(_("Row {0}: Qty not available for {4} in warehouse {1} at posting time of the entry ({2} {3})").format(d.idx,
 					frappe.bold(d.s_warehouse), formatdate(self.posting_date),
-					format_time(self.posting_time), frappe.bold(d.item_code)))
+					format_time(self.posting_time), frappe.bold(d.item_code))
 					+ '<br><br>' + _("Available qty is {0}, you need {1}").format(frappe.bold(d.actual_qty),
 						frappe.bold(d.transfer_qty)),
 					NegativeStockError, title=_('Insufficient Stock'))
@@ -868,4 +868,4 @@
 			"basic_rate" : get_incoming_rate(args)
 		}
 
-	return ret
\ No newline at end of file
+	return ret
diff --git a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
index ed1843e..34b3c85 100644
--- a/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
+++ b/erpnext/stock/doctype/stock_entry_detail/stock_entry_detail.json
@@ -10,6 +10,7 @@
  "doctype": "DocType", 
  "document_type": "Other", 
  "editable_grid": 1, 
+ "engine": "InnoDB", 
  "fields": [
   {
    "allow_on_submit": 0, 
@@ -23,6 +24,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Barcode", 
    "length": 0, 
    "no_copy": 0, 
@@ -50,6 +52,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -76,6 +79,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Source Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -105,6 +109,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -130,6 +135,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Target Warehouse", 
    "length": 0, 
    "no_copy": 0, 
@@ -159,6 +165,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -184,6 +191,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Item Code", 
    "length": 0, 
    "no_copy": 0, 
@@ -213,6 +221,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -238,6 +247,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Item Name", 
    "length": 0, 
    "no_copy": 0, 
@@ -264,6 +274,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -291,6 +302,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Description", 
    "length": 0, 
    "no_copy": 0, 
@@ -321,6 +333,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -347,6 +360,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Image", 
    "length": 0, 
    "no_copy": 0, 
@@ -374,6 +388,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Image View", 
    "length": 0, 
    "no_copy": 0, 
@@ -402,6 +417,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Quantity and Rate", 
    "length": 0, 
    "no_copy": 0, 
@@ -420,7 +436,7 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
-   "columns": 1, 
+   "columns": 3, 
    "fieldname": "qty", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -428,6 +444,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 1, 
+   "in_standard_filter": 0, 
    "label": "Qty", 
    "length": 0, 
    "no_copy": 0, 
@@ -448,14 +465,15 @@
    "allow_on_submit": 0, 
    "bold": 1, 
    "collapsible": 0, 
-   "columns": 2, 
+   "columns": 0, 
    "fieldname": "basic_rate", 
    "fieldtype": "Currency", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Basic Rate (as per Stock UOM)", 
    "length": 0, 
    "no_copy": 0, 
@@ -485,6 +503,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Basic Amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -513,6 +532,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Additional Cost", 
    "length": 0, 
    "no_copy": 0, 
@@ -541,6 +561,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Amount", 
    "length": 0, 
    "no_copy": 0, 
@@ -570,6 +591,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Valuation Rate", 
    "length": 0, 
    "no_copy": 0, 
@@ -598,6 +620,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -623,6 +646,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "UOM", 
    "length": 0, 
    "no_copy": 0, 
@@ -652,6 +676,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Conversion Factor", 
    "length": 0, 
    "no_copy": 0, 
@@ -680,6 +705,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Stock UOM", 
    "length": 0, 
    "no_copy": 0, 
@@ -709,6 +735,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Qty as per Stock UOM", 
    "length": 0, 
    "no_copy": 0, 
@@ -737,6 +764,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Serial No / Batch", 
    "length": 0, 
    "no_copy": 0, 
@@ -763,6 +791,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Serial No", 
    "length": 0, 
    "no_copy": 1, 
@@ -791,6 +820,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -816,6 +846,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Batch No", 
    "length": 0, 
    "no_copy": 0, 
@@ -845,6 +876,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Accounting", 
    "length": 0, 
    "no_copy": 0, 
@@ -872,6 +904,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Difference Account", 
    "length": 0, 
    "no_copy": 0, 
@@ -899,6 +932,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -926,6 +960,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Cost Center", 
    "length": 0, 
    "no_copy": 0, 
@@ -953,6 +988,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "More Information", 
    "length": 0, 
    "no_copy": 0, 
@@ -972,6 +1008,34 @@
    "bold": 0, 
    "collapsible": 0, 
    "columns": 0, 
+   "fieldname": "is_sample_item", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "ignore_xss_filter": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "in_standard_filter": 0, 
+   "label": "Is Sample Item", 
+   "length": 0, 
+   "no_copy": 1, 
+   "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_on_submit": 1, 
+   "bold": 0, 
+   "collapsible": 0, 
+   "columns": 0, 
    "fieldname": "actual_qty", 
    "fieldtype": "Float", 
    "hidden": 0, 
@@ -979,6 +1043,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 1, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Actual Qty (at source/target)", 
    "length": 0, 
    "no_copy": 1, 
@@ -1008,6 +1073,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "BOM No", 
    "length": 0, 
    "no_copy": 0, 
@@ -1035,6 +1101,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "length": 0, 
    "no_copy": 0, 
    "permlevel": 0, 
@@ -1061,6 +1128,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Material Request", 
    "length": 0, 
    "no_copy": 1, 
@@ -1088,6 +1156,7 @@
    "ignore_xss_filter": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
+   "in_standard_filter": 0, 
    "label": "Material Request Item", 
    "length": 0, 
    "no_copy": 1, 
@@ -1114,7 +1183,7 @@
  "issingle": 0, 
  "istable": 1, 
  "max_attachments": 0, 
- "modified": "2016-11-27 15:19:26.597414", 
+ "modified": "2017-02-07 01:21:14.367586", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Stock Entry Detail", 
diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
index 2caabee..00e3abe 100644
--- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
+++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py
@@ -27,9 +27,6 @@
 		self.validate_and_set_fiscal_year()
 		self.block_transactions_against_group_warehouse()
 
-		from erpnext.accounts.utils import validate_fiscal_year
-		validate_fiscal_year(self.posting_date, self.fiscal_year, self.meta.get_label("posting_date"), self)
-
 	def on_submit(self):
 		self.check_stock_frozen_date()
 		self.actual_amt_check()
@@ -117,6 +114,10 @@
 	def validate_and_set_fiscal_year(self):
 		if not self.fiscal_year:
 			self.fiscal_year = get_fiscal_year(self.posting_date, company=self.company)[0]
+		else:
+			from erpnext.accounts.utils import validate_fiscal_year
+			validate_fiscal_year(self.posting_date, self.fiscal_year, self.company, 
+				self.meta.get_label("posting_date"), self)
 
 	def block_transactions_against_group_warehouse(self):
 		from erpnext.stock.utils import is_group_warehouse
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index ba303bb..a7480e8 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -117,6 +117,10 @@
 					if buying_rate:
 						row.valuation_rate = buying_rate
 
+					else:
+						# get valuation rate from Item
+						row.valuation_rate = frappe.get_value('Item', row.item_code, 'valuation_rate')
+
 		# throw all validation messages
 		if self.validation_messages:
 			for msg in self.validation_messages:
diff --git a/erpnext/stock/doctype/warehouse/test_warehouse.py b/erpnext/stock/doctype/warehouse/test_warehouse.py
index edc5400..ec64bdd 100644
--- a/erpnext/stock/doctype/warehouse/test_warehouse.py
+++ b/erpnext/stock/doctype/warehouse/test_warehouse.py
@@ -4,59 +4,64 @@
 from frappe.model.rename_doc import rename_doc
 from erpnext.stock.doctype.stock_entry.stock_entry_utils import make_stock_entry
 from frappe.utils import cint
-from erpnext.stock.doctype.purchase_receipt.test_purchase_receipt import set_perpetual_inventory
+from erpnext import set_perpetual_inventory
+from frappe.test_runner import make_test_records
 
 import frappe
 import unittest
 test_records = frappe.get_test_records('Warehouse')
 
 class TestWarehouse(unittest.TestCase):
+	def setUp(self):
+		if not frappe.get_value('Item', '_Test Item'):
+			make_test_records('Item')
+
 	def test_parent_warehouse(self):
 		parent_warehouse = frappe.get_doc("Warehouse", "_Test Warehouse Group - _TC")
 		self.assertEquals(parent_warehouse.is_group, 1)
-		
+
 	def test_warehouse_hierarchy(self):
 		p_warehouse = frappe.get_doc("Warehouse", "_Test Warehouse Group - _TC")
-		
+
 		child_warehouses =  frappe.db.sql("""select name, is_group, parent_warehouse from `tabWarehouse` wh
 			where wh.lft > %s and wh.rgt < %s""", (p_warehouse.lft, p_warehouse.rgt), as_dict=1)
-		
+
 		for child_warehouse in child_warehouses:
 			self.assertEquals(p_warehouse.name, child_warehouse.parent_warehouse)
 			self.assertEquals(child_warehouse.is_group, 0)
-	
+
 	def test_warehouse_renaming(self):
 		set_perpetual_inventory(1)
 		create_warehouse("Test Warehouse for Renaming 1")
-		
+
 		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 1 - _TC"))
-		self.assertTrue(frappe.db.get_value("Account", 
+		self.assertTrue(frappe.db.get_value("Account",
 			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))
-		
+
 		# Rename with abbr
 		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 2 - _TC"):
 			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC")
 		rename_doc("Warehouse", "Test Warehouse for Renaming 1 - _TC", "Test Warehouse for Renaming 2 - _TC")
-		
+
 		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 2 - _TC"))
-		self.assertTrue(frappe.db.get_value("Account", 
+		self.assertTrue(frappe.db.get_value("Account",
 			filters={"warehouse": "Test Warehouse for Renaming 2 - _TC"}))
-			
+		self.assertFalse(frappe.db.get_value("Account",
+			filters={"warehouse": "Test Warehouse for Renaming 1 - _TC"}))
+
 		# Rename without abbr
 		if frappe.db.exists("Warehouse", "Test Warehouse for Renaming 3 - _TC"):
 			frappe.delete_doc("Warehouse", "Test Warehouse for Renaming 3 - _TC")
-		
+
 		rename_doc("Warehouse", "Test Warehouse for Renaming 2 - _TC", "Test Warehouse for Renaming 3")
-		
+
 		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Renaming 3 - _TC"))
-		self.assertTrue(frappe.db.get_value("Account", 
+		self.assertTrue(frappe.db.get_value("Account",
 			filters={"warehouse": "Test Warehouse for Renaming 3 - _TC"}))
-			
-		set_perpetual_inventory(0)
-		
+
 	def test_warehouse_merging(self):
 		set_perpetual_inventory(1)
-		
+
 		create_warehouse("Test Warehouse for Merging 1")
 		create_warehouse("Test Warehouse for Merging 2")
 
@@ -64,31 +69,29 @@
 			qty=1, rate=100)
 		make_stock_entry(item_code="_Test Item", target="Test Warehouse for Merging 2 - _TC",
 			qty=1, rate=100)
-			
+
 		existing_bin_qty = (
-			cint(frappe.db.get_value("Bin", 
+			cint(frappe.db.get_value("Bin",
 				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 1 - _TC"}, "actual_qty"))
-			+ cint(frappe.db.get_value("Bin", 
+			+ cint(frappe.db.get_value("Bin",
 				{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty"))
 		)
 
-		rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC", 
+		rename_doc("Warehouse", "Test Warehouse for Merging 1 - _TC",
 			"Test Warehouse for Merging 2 - _TC", merge=True)
 
 		self.assertFalse(frappe.db.exists("Warehouse", "Test Warehouse for Merging 1 - _TC"))
 
 		bin_qty = frappe.db.get_value("Bin",
 			{"item_code": "_Test Item", "warehouse": "Test Warehouse for Merging 2 - _TC"}, "actual_qty")
-			
+
 		self.assertEqual(bin_qty, existing_bin_qty)
-		
+
 		self.assertFalse(frappe.db.exists("Account", "Test Warehouse for Merging 1 - _TC"))
 		self.assertTrue(frappe.db.exists("Account", "Test Warehouse for Merging 2 - _TC"))
-		self.assertTrue(frappe.db.get_value("Account", 
+		self.assertTrue(frappe.db.get_value("Account",
 			filters={"warehouse": "Test Warehouse for Merging 2 - _TC"}))
-			
-		set_perpetual_inventory(0)
-		
+
 def create_warehouse(warehouse_name):
 	if not frappe.db.exists("Warehouse", warehouse_name + " - _TC"):
 		w = frappe.new_doc("Warehouse")
@@ -96,5 +99,7 @@
 		w.parent_warehouse = "_Test Warehouse Group - _TC"
 		w.company = "_Test Company"
 		w.save()
-	
-	
\ No newline at end of file
+
+	if not frappe.get_value('Account', dict(warehouse=warehouse_name + ' - _TC')):
+		print 'Warehouse {0} not linked'.format(warehouse_name)
+
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 1d2befa..d99cdf6 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -2,7 +2,7 @@
 # License: GNU General Public License v3. See license.txt
 
 from __future__ import unicode_literals
-import frappe
+import frappe, erpnext
 from frappe.utils import cint, validate_email_add
 from frappe import throw, msgprint, _
 from frappe.utils.nestedset import NestedSet
@@ -53,6 +53,8 @@
 		self.update_nsm_model()
 
 	def create_account_head(self):
+		'''Create new account head if there is no account linked to this Warehouse'''
+		from erpnext.accounts.doctype.account.account import BalanceMismatchError
 		if cint(frappe.defaults.get_global_default("auto_accounting_for_stock")):
 			if not self.get_account():
 				if self.get("__islocal") or not frappe.db.get_value(
@@ -76,10 +78,12 @@
 						ac_doc.insert()
 						msgprint(_("Account head {0} created").format(ac_doc.name), indicator='green', alert=True)
 
-					except frappe.DuplicateEntryError, e:
-						if not (e.args and e.args[0]=='Account'):
-							# if this is not due to creation of Account
-							raise
+					except frappe.DuplicateEntryError:
+						msgprint(_("Please create an Account for this Warehouse and link it. This cannot be done automatically as an account with name {0} already exists").format(frappe.bold(self.name)),
+							indicator='orange')
+
+					except BalanceMismatchError:
+						msgprint(_("Cannot automatically create Account as there is already stock balance in the Account. You must create a matching account before you can make an entry on this warehouse"))
 
 	def validate_parent_account(self):
 		if not self.company:
@@ -111,7 +115,7 @@
 			else:
 				frappe.db.sql("delete from `tabBin` where name = %s", d['name'])
 
-		warehouse_account = self.get_account(self.name)
+		warehouse_account = self.get_account()
 		if warehouse_account:
 			frappe.delete_doc("Account", warehouse_account)
 
@@ -131,10 +135,9 @@
 		return frappe.db.sql("""select name from `tabWarehouse`
 			where parent_warehouse = %s""", self.name)
 
-	def before_rename(self, olddn, newdn, merge=False):
+	def before_rename(self, old_name, new_name, merge=False):
 		# Add company abbr if not provided
-		from erpnext.setup.doctype.company.company import get_name_with_abbr
-		new_warehouse = get_name_with_abbr(newdn, self.company)
+		new_warehouse = erpnext.encode_company_abbr(new_name, self.company)
 
 		if merge:
 			if not frappe.db.exists("Warehouse", new_warehouse):
@@ -143,64 +146,54 @@
 			if self.company != frappe.db.get_value("Warehouse", new_warehouse, "company"):
 				frappe.throw(_("Both Warehouse must belong to same Company"))
 
-		self.rename_account_for(olddn, new_warehouse, merge)
+		self.rename_account_for(old_name, new_warehouse, merge)
 
 		return new_warehouse
 
-	def rename_account_for(self, olddn, newdn, merge):
-		if self.is_group:
-			old_account = self.get_account()
-		else:
-			old_account = self.get_account(olddn)
+	def rename_account_for(self, old_name, new_name, merge):
+		old_account_name = frappe.get_value('Account', dict(warehouse=old_name))
 
-		if old_account:
-			new_account = None
+		if old_account_name:
 			if not merge:
-				if old_account == self.add_abbr_if_missing(olddn):
-					new_account = frappe.rename_doc("Account", old_account, newdn)
+				# old account name is same as old name, so rename the account too
+				if old_account_name == erpnext.encode_company_abbr(old_name, self.company):
+					frappe.rename_doc("Account", old_account_name, new_name)
 			else:
-				existing_new_account = self.get_account(newdn)
-				new_account = frappe.rename_doc("Account", old_account,
-					existing_new_account or newdn, merge=True if existing_new_account else False)
+				# merge
+				target_account = frappe.get_value('Account', dict(warehouse=new_name))
+				if target_account:
+					# target warehouse has account, merge into target account
+					frappe.rename_doc("Account", old_account_name,
+						target_account, merge=True)
+				else:
+					# target warehouse does not have account, use this account
+					frappe.rename_doc("Account", old_account_name,
+						new_name, merge=False)
 
-			frappe.db.set_value("Account", new_account or old_account, "warehouse", newdn)
+					# rename link
+					frappe.db.set_value('Account', new_name, 'warehouse', new_name)
 
-	def add_abbr_if_missing(self, dn):
-		from erpnext.setup.doctype.company.company import get_name_with_abbr
-		return get_name_with_abbr(dn, self.company)
+	def get_account(self):
+		return frappe.get_value('Account', dict(warehouse=self.name))
 
-	def get_account(self, warehouse=None):
-		filters = {
-			"account_type": "Stock",
-			"company": self.company,
-			"is_group": self.is_group
-		}
-
-		if warehouse:
-			filters.update({"warehouse": warehouse})
-		else:
-			filters.update({"account_name": self.warehouse_name})
-
-		return frappe.db.get_value("Account", filters)
-
-	def after_rename(self, olddn, newdn, merge=False):
+	def after_rename(self, old_name, new_name, merge=False):
 		if merge:
-			self.recalculate_bin_qty(newdn)
+			self.recalculate_bin_qty(new_name)
 
-	def recalculate_bin_qty(self, newdn):
+	def recalculate_bin_qty(self, new_name):
 		from erpnext.stock.stock_balance import repost_stock
 		frappe.db.auto_commit_on_many_writes = 1
 		existing_allow_negative_stock = frappe.db.get_value("Stock Settings", None, "allow_negative_stock")
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", 1)
 
 		repost_stock_for_items = frappe.db.sql_list("""select distinct item_code
-			from tabBin where warehouse=%s""", newdn)
+			from tabBin where warehouse=%s""", new_name)
 
 		# Delete all existing bins to avoid duplicate bins for the same item and warehouse
-		frappe.db.sql("delete from `tabBin` where warehouse=%s", newdn)
+		frappe.db.sql("delete from `tabBin` where warehouse=%s", new_name)
 
 		for item_code in repost_stock_for_items:
-			repost_stock(item_code, newdn)
+			repost_stock(item_code, new_name)
 
 		frappe.db.set_value("Stock Settings", None, "allow_negative_stock", existing_allow_negative_stock)
 		frappe.db.auto_commit_on_many_writes = 0
@@ -231,7 +224,7 @@
 		if self.check_if_sle_exists():
 			throw(_("Warehouses with existing transaction can not be converted to group."))
 		else:
-			account_name = self.get_account(self.name)
+			account_name = self.get_account()
 			if account_name:
 				doc = frappe.get_doc("Account", account_name)
 				doc.flags.exclude_account_type_check = True
@@ -269,26 +262,13 @@
 
 @frappe.whitelist()
 def add_node():
-	doctype = frappe.form_dict.get('doctype')
-	company = frappe.form_dict.get('company')
-	parent_field = 'parent_' + doctype.lower().replace(' ', '_')
-	name_field = doctype.lower().replace(' ', '_') + '_name'
+	from frappe.desk.treeview import make_tree_args
+	args = make_tree_args(**frappe.form_dict)
 
-	doc = frappe.new_doc(doctype)
+	if cint(args.is_root):
+		args.parent_warehouse = None
 
-	parent = frappe.form_dict['parent']
-
-	if cint(frappe.form_dict['is_root']):
-		parent = None
-
-	doc.update({
-		name_field: frappe.form_dict['warehouse_name'],
-		parent_field: parent,
-		"is_group": frappe.form_dict['is_group'],
-		"company": company
-	})
-
-	doc.save()
+	frappe.get_doc(args).insert()
 
 @frappe.whitelist()
 def convert_to_group_or_ledger():
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 68b4270..b9b11a8 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -42,9 +42,6 @@
 
 	get_party_item_code(args, item_doc, out)
 
-	if out.get("warehouse"):
-		out.update(get_bin_details(args.item_code, out.warehouse))
-
 	if frappe.db.exists("Product Bundle", args.item_code):
 		valuation_rate = 0.0
 		bundled_items = frappe.get_doc("Product Bundle", args.item_code)
@@ -65,6 +62,9 @@
 
 	if args.customer and cint(args.is_pos):
 		out.update(get_pos_profile_item_details(args.company, args))
+		
+	if out.get("warehouse"):
+		out.update(get_bin_details(args.item_code, out.warehouse))
 
 	# update args with out, if key or value not exists
 	for key, value in out.iteritems():
@@ -73,7 +73,7 @@
 
 	out.update(get_pricing_rule_for_item(args))
 
-	if args.get("doctype") in ("Sales Invoice", "Delivery Note"):
+	if args.get("doctype") in ("Sales Invoice", "Delivery Note") and out.qty > 0:
 		out.serial_no = get_serial_no(out)
 
 	if args.transaction_date and item.lead_time_days:
@@ -387,7 +387,8 @@
 def get_bin_details_and_serial_nos(item_code, warehouse, qty=None, serial_no=None):
 	bin_details_and_serial_nos = {}
 	bin_details_and_serial_nos.update(get_bin_details(item_code, warehouse))
-	bin_details_and_serial_nos.update(get_serial_no_details(item_code, warehouse, qty, serial_no))
+	if qty > 0:
+		bin_details_and_serial_nos.update(get_serial_no_details(item_code, warehouse, qty, serial_no))
 	return bin_details_and_serial_nos
 
 @frappe.whitelist()
diff --git a/erpnext/stock/report/serial_no_status/serial_no_status.json b/erpnext/stock/report/serial_no_status/serial_no_status.json
index cb4e70d..99b99f7 100644
--- a/erpnext/stock/report/serial_no_status/serial_no_status.json
+++ b/erpnext/stock/report/serial_no_status/serial_no_status.json
@@ -7,8 +7,8 @@
  "doctype": "Report", 
  "idx": 1, 
  "is_standard": "Yes", 
- "json": "{\"add_total_row\": 0, \"sort_by\": \"Serial No.name\", \"sort_order\": \"desc\", \"sort_by_next\": null, \"filters\": [], \"sort_order_next\": \"desc\", \"columns\": [[\"name\", \"Serial No\"], [\"item_code\", \"Serial No\"], [\"warehouse\", \"Serial No\"], [\"item_name\", \"Serial No\"], [\"description\", \"Serial No\"], [\"item_group\", \"Serial No\"], [\"brand\", \"Serial No\"], [\"purchase_document_no\", \"Serial No\"], [\"purchase_date\", \"Serial No\"], [\"customer\", \"Serial No\"], [\"customer_name\", \"Serial No\"], [\"purchase_rate\", \"Serial No\"], [\"delivery_document_no\", \"Serial No\"], [\"delivery_date\", \"Serial No\"], [\"supplier\", \"Serial No\"], [\"supplier_name\", \"Serial No\"]]}", 
- "modified": "2016-12-05 18:49:31.424300", 
+ "json": "{\"add_total_row\": 0, \"sort_by\": \"Serial No.name\", \"sort_order\": \"desc\", \"sort_by_next\": null, \"filters\": [], \"sort_order_next\": \"desc\", \"columns\": [[\"name\", \"Serial No\"], [\"item_code\", \"Serial No\"], [\"warehouse\", \"Serial No\"], [\"item_name\", \"Serial No\"], [\"description\", \"Serial No\"], [\"item_group\", \"Serial No\"], [\"brand\", \"Serial No\"], [\"purchase_document_type\", \"Serial No\"], [\"purchase_document_no\", \"Serial No\"], [\"purchase_date\", \"Serial No\"], [\"customer\", \"Serial No\"], [\"customer_name\", \"Serial No\"], [\"purchase_rate\", \"Serial No\"], [\"delivery_document_type\", \"Serial No\"], [\"delivery_document_no\", \"Serial No\"], [\"delivery_date\", \"Serial No\"], [\"supplier\", \"Serial No\"], [\"supplier_name\", \"Serial No\"]]}", 
+ "modified": "2017-02-14 18:50:31.424300", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Serial No Status", 
diff --git a/erpnext/stock/report/stock_balance/stock_balance.py b/erpnext/stock/report/stock_balance/stock_balance.py
index d5d6f9d..a8db4e0 100644
--- a/erpnext/stock/report/stock_balance/stock_balance.py
+++ b/erpnext/stock/report/stock_balance/stock_balance.py
@@ -102,7 +102,7 @@
 				"in_qty": 0.0, "in_val": 0.0,
 				"out_qty": 0.0, "out_val": 0.0,
 				"bal_qty": 0.0, "bal_val": 0.0,
-				"val_rate": 0.0, "uom": None
+				"val_rate": 0.0
 			})
 
 		qty_dict = iwb_map[(d.company, d.item_code, d.warehouse)]
@@ -129,6 +129,24 @@
 		qty_dict.val_rate = d.valuation_rate
 		qty_dict.bal_qty += qty_diff
 		qty_dict.bal_val += value_diff
+		
+	iwb_map = filter_items_with_no_transactions(iwb_map)
+
+	return iwb_map
+	
+def filter_items_with_no_transactions(iwb_map):
+	for (company, item, warehouse) in sorted(iwb_map):
+		qty_dict = iwb_map[(company, item, warehouse)]
+		
+		no_transactions = True
+		for key, val in qty_dict.items():
+			val = flt(val, 3)
+			qty_dict[key] = val
+			if key != "val_rate" and val:
+				no_transactions = False
+		
+		if no_transactions:
+			iwb_map.pop((company, item, warehouse))
 
 	return iwb_map
 
diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py
index a980ed0..10722cc 100644
--- a/erpnext/stock/stock_ledger.py
+++ b/erpnext/stock/stock_ledger.py
@@ -258,7 +258,14 @@
 
 			if not self.valuation_rate and actual_qty > 0:
 				self.valuation_rate = sle.incoming_rate
-
+				
+			# Get valuation rate from previous SLE or Item master, if item is not a sample item
+			if not self.valuation_rate and sle.voucher_detail_no:
+				is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no)
+				if not is_sample_item:
+					self.valuation_rate = get_valuation_rate(sle.item_code, sle.warehouse, 
+						sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
+		
 	def get_fifo_values(self, sle):
 		incoming_rate = flt(sle.incoming_rate)
 		actual_qty = flt(sle.actual_qty)
@@ -281,10 +288,14 @@
 			qty_to_pop = abs(actual_qty)
 			while qty_to_pop:
 				if not self.stock_queue:
-					if self.qty_after_transaction > 0:
-						_rate = get_valuation_rate(sle.item_code, sle.warehouse, self.allow_zero_rate)
+					# Get valuation rate from last sle if exists or from valuation rate field in item master
+					is_sample_item = self.check_if_sample_item(sle.voucher_type, sle.voucher_detail_no)
+					if not is_sample_item:
+						_rate = get_valuation_rate(sle.item_code, sle.warehouse, 
+							sle.voucher_type, sle.voucher_no, self.allow_zero_rate)
 					else:
 						_rate = 0
+						
 					self.stock_queue.append([0, _rate])
 
 				index = None
@@ -330,7 +341,11 @@
 
 		if not self.stock_queue:
 			self.stock_queue.append([0, sle.incoming_rate or sle.outgoing_rate or self.valuation_rate])
-
+			
+	def check_if_sample_item(self, voucher_type, voucher_detail_no):
+		ref_item_dt = voucher_type + (" Detail" if voucher_type == "Stock Entry" else " Item")
+		return frappe.db.get_value(ref_item_dt, voucher_detail_no, "is_sample_item")
+		
 	def get_sle_before_datetime(self):
 		"""get previous stock ledger entry before current time-bucket"""
 		return get_stock_ledger_entries(self.args, "<", "desc", "limit 1", for_update=False)
@@ -404,7 +419,8 @@
 			"order": order
 		}, previous_sle, as_dict=1, debug=debug)
 
-def get_valuation_rate(item_code, warehouse, allow_zero_rate=False):
+def get_valuation_rate(item_code, warehouse, voucher_type, voucher_no, allow_zero_rate=False):
+	# Get valuation rate from last sle for the same item and warehouse
 	last_valuation_rate = frappe.db.sql("""select valuation_rate
 		from `tabStock Ledger Entry`
 		where item_code = %s and warehouse = %s
@@ -412,6 +428,7 @@
 		order by posting_date desc, posting_time desc, name desc limit 1""", (item_code, warehouse))
 
 	if not last_valuation_rate:
+		# Get valuation rate from last sle for the item against any warehouse
 		last_valuation_rate = frappe.db.sql("""select valuation_rate
 			from `tabStock Ledger Entry`
 			where item_code = %s and valuation_rate > 0
@@ -420,9 +437,13 @@
 	valuation_rate = flt(last_valuation_rate[0][0]) if last_valuation_rate else 0
 
 	if not valuation_rate:
-		valuation_rate = frappe.db.get_value("Item Price", {"item_code": item_code, "buying": 1}, "price_list_rate")
+		# If negative stock allowed, and item delivered without any incoming entry,
+		# syste does not found any SLE, then take valuation rate from Item
+		valuation_rate = frappe.db.get_value("Item", item_code, "valuation_rate")
 
-	if not allow_zero_rate and not valuation_rate and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
-		frappe.throw(_("Purchase rate for item: {0} not found, which is required to book accounting entry (expense). Please mention item price against a buying price list.").format(item_code))
+	if not allow_zero_rate and not valuation_rate \
+			and cint(frappe.db.get_value("Accounts Settings", None, "auto_accounting_for_stock")):
+			
+		frappe.throw(_("Valuation rate not found for the Item {0}, which is required to do accounting entries for {1} {2}. If the item is transacting as a sample item in the {1}, please mention that in the {1} Item table. Otherwise, please create an incoming stock transaction for the item or mention valuation rate in the Item record, and then try submiting/cancelling this entry").format(item_code, voucher_type, voucher_no))
 
 	return valuation_rate
diff --git a/erpnext/support/doctype/issue/issue.py b/erpnext/support/doctype/issue/issue.py
index 36d0876..2798f70 100644
--- a/erpnext/support/doctype/issue/issue.py
+++ b/erpnext/support/doctype/issue/issue.py
@@ -33,11 +33,11 @@
 			if not self.lead:
 				self.lead = frappe.db.get_value("Lead", {"email_id": email_id})
 			if not self.contact:
-				values = frappe.db.get_value("Contact",
-					{"email_id": email_id}, ("name", "customer"))
+				self.contact = frappe.db.get_value("Contact", {"email_id": email_id})
 
-				if values:
-					self.contact, self.customer = values
+				if self.contact:
+					contact = frappe.get_doc('Contact', self.contact)
+					self.customer = contact.get_link_for('Customer')
 
 			if not self.company:
 				self.company = frappe.db.get_value("Lead", self.lead, "company") or \
@@ -81,9 +81,14 @@
 	st.save()
 
 def auto_close_tickets():
-	frappe.db.sql("""update `tabIssue` set status = 'Closed'
-		where status = 'Replied'
-		and date_sub(curdate(),interval 15 Day) > modified""")
+	""" auto close the replied support tickets after 7 days """
+	issues = frappe.db.sql(""" select name from tabIssue where status='Replied' and
+		modified<DATE_SUB(CURDATE(), INTERVAL 7 DAY) """, as_dict=True)
+
+	for issue in issues:
+		doc = frappe.get_doc("Issue", issue.get("name"))
+		doc.status = "Closed"
+		doc.save(ignore_permissions=True)
 
 @frappe.whitelist()
 def set_multiple_status(names, status):
diff --git a/erpnext/support/doctype/warranty_claim/warranty_claim.js b/erpnext/support/doctype/warranty_claim/warranty_claim.js
index 9fed265..2369a8a 100644
--- a/erpnext/support/doctype/warranty_claim/warranty_claim.js
+++ b/erpnext/support/doctype/warranty_claim/warranty_claim.js
@@ -4,6 +4,10 @@
 frappe.provide("erpnext.support");
 
 frappe.ui.form.on("Warranty Claim", {
+	setup: function(frm) {
+		frm.set_query('contact_person', erpnext.queries.contact_query);
+		frm.set_query('customer_address', erpnext.queries.address_query);
+	},
 	customer: function(frm) {
 		erpnext.utils.get_party_details(frm);
 	},
@@ -17,6 +21,8 @@
 
 erpnext.support.WarrantyClaim = frappe.ui.form.Controller.extend({
 	refresh: function() {
+		frappe.dynamic_link = {doc: this.frm.doc, fieldname: 'customer', doctype: 'Customer'}
+
 		if(!cur_frm.doc.__islocal &&
 			(cur_frm.doc.status=='Open' || cur_frm.doc.status == 'Work In Progress')) {
 			cur_frm.add_custom_button(__('Maintenance Visit'),
@@ -40,18 +46,6 @@
 		set_multiple(cdt,cdn,{status:'Open'});
 }
 
-cur_frm.fields_dict['customer_address'].get_query = function(doc, cdt, cdn) {
-	return{
-		filters:{ 'customer': doc.customer}
-	}
-}
-
-cur_frm.fields_dict['contact_person'].get_query = function(doc, cdt, cdn) {
-	return{
-		filters:{ 'customer': doc.customer}
-	}
-}
-
 cur_frm.fields_dict['serial_no'].get_query = function(doc, cdt, cdn) {
 	var cond = [];
 	var filter = [
diff --git a/erpnext/templates/generators/job_opening.html b/erpnext/templates/generators/job_opening.html
index 5998e3f..f92e72e 100644
--- a/erpnext/templates/generators/job_opening.html
+++ b/erpnext/templates/generators/job_opening.html
@@ -15,7 +15,7 @@
 {% endif %}
 <p style='margin-top: 30px'>
 	<a class='btn btn-primary'
-	href='/job_application?job_title={{ doc.name }}'>
+	href='/job_application?new=1&job_title={{ doc.name }}'>
 	{{ _("Apply Now") }}</a>
 </p>
 
diff --git a/erpnext/templates/pages/announcements.html b/erpnext/templates/pages/announcements.html
deleted file mode 100644
index d6e0d73..0000000
--- a/erpnext/templates/pages/announcements.html
+++ /dev/null
@@ -1,20 +0,0 @@
-{% extends "templates/web.html" %}
-
-{% block header %}
-	<h1> {{doc.subject}} </h1>
-{% endblock %}
-
-{% block page_content %}
-
-<p class="post-description"> {{doc.description}} </p>
-<p class="post-by text-muted small">
-	{% for file in attached_files%}
-		<a href="{{file.file_url}}" target="_new">{{file.file_name}}</a>
-		<br>
-	{% endfor %}
-	<br>
-	<i>{{ doc.posted_by }}</i>
-	<i class="blog-dot"></i> {{ frappe.format_date(doc.modified) }}
-</p>
-
-{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/announcements.py b/erpnext/templates/pages/announcements.py
deleted file mode 100644
index 4a61fc8..0000000
--- a/erpnext/templates/pages/announcements.py
+++ /dev/null
@@ -1,18 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-
-def get_context(context):
-	announcement = frappe.get_doc('Announcement', frappe.form_dict.announcement)
-	context.no_cache = 1
-	context.show_sidebar = True
-	announcement.has_permission('read')
-	context.doc = announcement
-	attachments = frappe.db.sql("""select file_url, file_name from tabFile as file
-								where file.attached_to_name=%s """,(announcement.name), as_dict = True)
-
-	context.attached_files = attachments
-
-
diff --git a/erpnext/templates/pages/courses.py b/erpnext/templates/pages/courses.py
index 5b1410e..c80d8e7 100644
--- a/erpnext/templates/pages/courses.py
+++ b/erpnext/templates/pages/courses.py
@@ -15,14 +15,6 @@
 	course = frappe.get_doc('Course', frappe.form_dict.course)
 	course.has_permission('read')
 	context.doc = course
-	portal_items = [{'reference_doctype': u'Topic', 'route': u"/topic?course=" + str(course.name), 'show_always': 0L, 'title': u'Topics'},
-				{'reference_doctype': u'Discussion', 'route': u"/discussion?course=" + str(course.name), 'show_always': 0L, 'title': u'Discussions'},
-
-	]
-
-	context.sidebar_items = portal_items
-
 	context.sidebar_title = sidebar_title
-
 	context.intro = course.course_intro
 
diff --git a/erpnext/templates/pages/discussions.html b/erpnext/templates/pages/discussions.html
deleted file mode 100644
index 28eb01f..0000000
--- a/erpnext/templates/pages/discussions.html
+++ /dev/null
@@ -1,15 +0,0 @@
-{% extends "templates/web.html" %}
-
-{% block header %}
-	<h2> {{doc.subject}} </h2>
-	<p> {{doc.description}} </p>
-	<p class="text-muted small">Started by: {{doc.owner}} </p>
-{% endblock %}
-
-{% block page_content %}
-
-<div>
-	{% include 'templates/includes/comments/comments.html' %}
-</div>
-
-{% endblock %}
diff --git a/erpnext/templates/pages/discussions.py b/erpnext/templates/pages/discussions.py
deleted file mode 100644
index 22a1bef..0000000
--- a/erpnext/templates/pages/discussions.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.website.utils import get_comment_list
-
-def get_context(context):
-	context.doc = frappe.get_doc('Discussion', frappe.form_dict.discussion)
-	portal_items = [{'reference_doctype': u'Topic', 'route': u"/topic?course=" + str(context.doc.course), 'show_always': 0L, 'title': u'Topics'},
-				{'reference_doctype': u'Discussion', 'route': u"/discussion?course=" + str(context.doc.course), 'show_always': 0L, 'title': u'Discussions'},
-
-	]
-	context.show_sidebar = True
-	context.sidebar_items = portal_items
-	context.no_cache = 1
-	context.doc.has_permission('read')
-	context.sidebar_title = context.doc.course
-	context.reference_doctype = "Discussion"
-	context.reference_name = context.doc.name
-	context.comment_list = get_comment_list(context.doc.doctype,context.doc.name)
\ No newline at end of file
diff --git a/erpnext/templates/pages/projects.html b/erpnext/templates/pages/projects.html
index aeee602..765e43f 100644
--- a/erpnext/templates/pages/projects.html
+++ b/erpnext/templates/pages/projects.html
@@ -24,7 +24,7 @@
 
 <div class="clearfix">
   <h4 style="float: left;">{{ _("Tasks") }}</h4>
-  <a class="btn btn-secondary btn-default btn-sm" style="float: right; position: relative; top: 10px;" href='/tasks?new=1&project={{ doc.project_name }}'>New task</a>
+  <a class="btn btn-secondary btn-default btn-sm" style="float: right; position: relative; top: 10px;" href='/tasks?new=1&project={{ doc.project_name }}'>{{ _("New task") }}</a>
 </div>
 
 <p>
@@ -39,7 +39,7 @@
 		<p><a id= 'more-task' style='display: none;' class='more-tasks small underline'>{{ _("More") }}</a><p>
 	</div>
 {% else %}
-	<p class="text-muted">No tasks</p>
+	<p class="text-muted">{{ _("No tasks") }}</p>
 {% endif %}
 
 
@@ -55,7 +55,7 @@
 		<p><a class='more-timelogs small underline'>{{ _("More") }}</a><p>
 	{% endif %}
 {% else %}
-	<p class="text-muted">No time sheets</p>
+	<p class="text-muted">{{ _("No time sheets") }}</p>
 {% endif %}
 </div>
 
diff --git a/erpnext/templates/pages/task_info.html b/erpnext/templates/pages/task_info.html
index 7cc5594..f386ce8 100644
--- a/erpnext/templates/pages/task_info.html
+++ b/erpnext/templates/pages/task_info.html
@@ -86,7 +86,8 @@
 	<h3>Comments</h3>
 	<div class="no-comment">
 		{% for comment in comments %}
-			<p class="text-muted">{{comment.sender_full_name}} : {{comment.subject}} on 									   									{{comment.communication_date.strftime('%Y-%m-%d')}}</p>
+			<p class="text-muted">{{comment.sender_full_name}}:
+				{{comment.subject}} on 									   				{{comment.creation.strftime('%Y-%m-%d')}}</p>
 		{% endfor %}
 	</div>
 	<div class="comment-form-wrapper">
diff --git a/erpnext/templates/pages/topics.html b/erpnext/templates/pages/topics.html
deleted file mode 100644
index 94d7a17..0000000
--- a/erpnext/templates/pages/topics.html
+++ /dev/null
@@ -1,12 +0,0 @@
-{% extends "templates/web.html" %}
-
-
-{% block header %}
-	<h2> {{ doc.introduction }} </h1>
-{% endblock %}
-
-{% block page_content %}
-
-<p class="post-description"> {{ doc.content }} </p>
-
-{% endblock %}
\ No newline at end of file
diff --git a/erpnext/templates/pages/topics.py b/erpnext/templates/pages/topics.py
deleted file mode 100644
index 8a55b64..0000000
--- a/erpnext/templates/pages/topics.py
+++ /dev/null
@@ -1,15 +0,0 @@
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-
-
-def get_context(context):
-	topic = frappe.get_doc('Topic', frappe.form_dict.topic)
-	context.no_cache = 1
-	context.show_sidebar = True
-	context.doc = topic
-	attachments = frappe.db.sql("""select file_url, file_name from tabFile as file
-								where file.attached_to_name=%s """,(topic.name), as_dict = True)
-
-	context.attached_files = attachments
diff --git a/erpnext/templates/utils.py b/erpnext/templates/utils.py
index 94f9242..c1405c3 100644
--- a/erpnext/templates/utils.py
+++ b/erpnext/templates/utils.py
@@ -34,6 +34,8 @@
 
 	if customer:
 		opportunity.customer = customer
+	elif lead:
+		opportunity.lead = lead
 	else:
 		opportunity.lead = new_lead.name
 
diff --git a/erpnext/tests/utils.py b/erpnext/tests/utils.py
new file mode 100644
index 0000000..7024b0d
--- /dev/null
+++ b/erpnext/tests/utils.py
@@ -0,0 +1,36 @@
+# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+
+import frappe
+
+def create_test_contact_and_address():
+	frappe.db.sql('delete from tabContact')
+	frappe.db.sql('delete from tabAddress')
+	frappe.db.sql('delete from `tabDynamic Link`')
+
+	frappe.get_doc(dict(
+		doctype='Address',
+		address_title='_Test Address for Customer',
+		address_type='Office',
+		address_line1='Station Road',
+		city='_Test City',
+		state='Test State',
+		country='India',
+		links = [dict(
+			link_doctype='Customer',
+			link_name='_Test Customer'
+		)]
+	)).insert()
+
+	frappe.get_doc(dict(
+		doctype='Contact',
+		email_id='test_contact_customer@example.com',
+		phone='+91 0000000000',
+		first_name='_Test Contact for _Test Customer',
+		links = [dict(
+			link_doctype='Customer',
+			link_name='_Test Customer'
+		)]
+	)).insert()
diff --git a/erpnext/utilities/__init__.py b/erpnext/utilities/__init__.py
index bba21e6..b94061c 100644
--- a/erpnext/utilities/__init__.py
+++ b/erpnext/utilities/__init__.py
@@ -1,6 +1,7 @@
 ## temp utility
 
 import frappe
+from erpnext.utilities.activation import get_level
 
 def update_doctypes():
 	for d in frappe.db.sql("""select df.parent, df.fieldname
@@ -29,5 +30,6 @@
 
 	return {
 		'company': company,
-		'domain': domain
+		'domain': domain,
+		'activation': get_level()
 	}
diff --git a/erpnext/utilities/activation.py b/erpnext/utilities/activation.py
new file mode 100644
index 0000000..563f71e
--- /dev/null
+++ b/erpnext/utilities/activation.py
@@ -0,0 +1,36 @@
+import frappe
+
+def get_level():
+	activation_level = 0
+	if frappe.db.get_single_value('System Settings', 'setup_complete'):
+		activation_level = 1
+
+	if frappe.db.count('Item') > 5:
+		activation_level += 1
+
+	if frappe.db.count('Customer') > 5:
+		activation_level += 1
+
+	if frappe.db.count('Sales Order') > 2:
+		activation_level += 1
+
+	if frappe.db.count('Purchase Order') > 2:
+		activation_level += 1
+
+	if frappe.db.count('Employee') > 3:
+		activation_level += 1
+
+	if frappe.db.count('Payment Entry') > 2:
+		activation_level += 1
+
+	if frappe.db.count('Communication', dict(communication_medium='Email')) > 10:
+		activation_level += 1
+
+	if frappe.db.count('User') > 5:
+		activation_level += 1
+
+	# recent login
+	if frappe.db.sql('select name from tabUser where last_login > date_sub(now(), interval 2 day) limit 1'):
+		activation_level += 1
+
+	return activation_level
\ No newline at end of file
diff --git a/erpnext/utilities/address_and_contact.py b/erpnext/utilities/address_and_contact.py
deleted file mode 100644
index 36879d2..0000000
--- a/erpnext/utilities/address_and_contact.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-
-def load_address_and_contact(doc, key):
-	"""Loads address list and contact list in `__onload`"""
-	from erpnext.utilities.doctype.address.address import get_address_display
-
-	doc.get("__onload")["addr_list"] = [a.update({"display": get_address_display(a)}) \
-		for a in frappe.get_all("Address",
-			fields="*", filters={key: doc.name},
-			order_by="is_primary_address desc, modified desc")]
-
-	if doc.doctype != "Lead":
-		doc.get("__onload")["contact_list"] = frappe.get_all("Contact",
-			fields="*", filters={key: doc.name},
-			order_by="is_primary_contact desc, modified desc")
-
-def has_permission(doc, ptype, user):
-	links = get_permitted_and_not_permitted_links(doc.doctype)
-	if not links.get("not_permitted_links"):
-		# optimization: don't determine permissions based on link fields
-		return True
-
-	# True if any one is True or all are empty
-	names = []
-	for df in (links.get("permitted_links") + links.get("not_permitted_links")):
-		doctype = df.options
-		name = doc.get(df.fieldname)
-		names.append(name)
-
-		if name and frappe.has_permission(doctype, ptype, doc=name):
-			return True
-
-	if not any(names):
-		return True
-	return False
-
-def get_permission_query_conditions_for_contact(user):
-	return get_permission_query_conditions("Contact")
-
-def get_permission_query_conditions_for_address(user):
-	return get_permission_query_conditions("Address")
-
-def get_permission_query_conditions(doctype):
-	links = get_permitted_and_not_permitted_links(doctype)
-
-	if not links.get("not_permitted_links"):
-		# when everything is permitted, don't add additional condition
-		return ""
-		
-	elif not links.get("permitted_links"):
-		conditions = []
-		
-		# when everything is not permitted
-		for df in links.get("not_permitted_links"):
-			# like ifnull(customer, '')='' and ifnull(supplier, '')=''
-			conditions.append("ifnull(`tab{doctype}`.`{fieldname}`, '')=''".format(doctype=doctype, fieldname=df.fieldname))
-			
-		return "( " + " and ".join(conditions) + " )"
-
-	else:
-		conditions = []
-
-		for df in links.get("permitted_links"):
-			# like ifnull(customer, '')!='' or ifnull(supplier, '')!=''
-			conditions.append("ifnull(`tab{doctype}`.`{fieldname}`, '')!=''".format(doctype=doctype, fieldname=df.fieldname))			
-
-		return "( " + " or ".join(conditions) + " )"
-
-def get_permitted_and_not_permitted_links(doctype):
-	permitted_links = []
-	not_permitted_links = []
-
-	meta = frappe.get_meta(doctype)
-
-	for df in meta.get_link_fields():
-		if df.options not in ("Customer", "Supplier", "Company", "Sales Partner"):
-			continue
-
-		if frappe.has_permission(df.options):
-			permitted_links.append(df)
-		else:
-			not_permitted_links.append(df)
-
-	return {
-		"permitted_links": permitted_links,
-		"not_permitted_links": not_permitted_links
-	}
diff --git a/erpnext/utilities/doctype/address/README.md b/erpnext/utilities/doctype/address/README.md
deleted file mode 100644
index a4efda6..0000000
--- a/erpnext/utilities/doctype/address/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Address belonging to a Customer or Supplier.
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/address/__init__.py b/erpnext/utilities/doctype/address/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/erpnext/utilities/doctype/address/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/erpnext/utilities/doctype/address/address.js b/erpnext/utilities/doctype/address/address.js
deleted file mode 100644
index 1e874c3..0000000
--- a/erpnext/utilities/doctype/address/address.js
+++ /dev/null
@@ -1,13 +0,0 @@
-// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-// License: GNU General Public License v3. See license.txt
-
-{% include 'erpnext/controllers/js/contact_address_common.js' %};
-
-frappe.ui.form.on("Address", "validate", function(frm) {
-	// clear linked customer / supplier / sales partner on saving...
-	$.each(["Customer", "Supplier", "Sales Partner", "Lead"], function(i, doctype) {
-		var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
-		if(name && locals[doctype] && locals[doctype][name])
-			frappe.model.remove_from_locals(doctype, name);
-	});
-});
diff --git a/erpnext/utilities/doctype/address/address.json b/erpnext/utilities/doctype/address/address.json
deleted file mode 100644
index 329e05f..0000000
--- a/erpnext/utilities/doctype/address/address.json
+++ /dev/null
@@ -1,851 +0,0 @@
-{
- "allow_copy": 0, 
- "allow_import": 1, 
- "allow_rename": 1, 
- "beta": 0, 
- "creation": "2013-01-10 16:34:32", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Setup", 
- "editable_grid": 0, 
- "fields": [
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "address_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-map-marker", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "Name of person or organization that this address belongs to.", 
-   "fieldname": "address_title", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Address Title", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "address_type", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Address Type", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Billing\nShipping\nOffice\nPersonal\nPlant\nPostal\nShop\nSubsidiary\nWarehouse\nOther", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "address_line1", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Address Line 1", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "address_line2", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Address Line 2", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "city", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "City/Town", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "county", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "County", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "state", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "State", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "country", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 1, 
-   "label": "Country", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Country", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "pincode", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Postal Code", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break0", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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, 
-   "width": "50%"
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "email_id", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Email Address", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "phone", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Phone", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "fax", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Fax", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "description": "", 
-   "fieldname": "is_primary_address", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Preferred Billing Address", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "description": "", 
-   "fieldname": "is_shipping_address", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Preferred Shipping Address", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "linked_with", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Reference", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-pushpin", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "fieldname": "is_your_company_address", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Your Company Address", 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:doc.is_your_company_address", 
-   "fieldname": "company", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Company", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Company", 
-   "permlevel": 0, 
-   "precision": "", 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 1, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.is_your_company_address", 
-   "fieldname": "customer", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Customer", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Customer", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.is_your_company_address", 
-   "fieldname": "customer_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Customer Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.is_your_company_address", 
-   "fieldname": "supplier", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.is_your_company_address", 
-   "fieldname": "supplier_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 1, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval: !doc.is_your_company_address", 
-   "fieldname": "sales_partner", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Sales Partner", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Sales Partner", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.supplier && !doc.sales_partner && !doc.is_your_company_address", 
-   "fieldname": "lead", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Lead", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Lead", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "eval:!doc.supplier && !doc.sales_partner && !doc.is_your_company_address", 
-   "fieldname": "lead_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Lead Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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
-  }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "icon": "fa fa-map-marker", 
- "idx": 5, 
- "image_view": 0, 
- "in_create": 0, 
- "in_dialog": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2016-11-07 05:47:06.911933", 
- "modified_by": "Administrator", 
- "module": "Utilities", 
- "name": "Address", 
- "owner": "Administrator", 
- "permissions": [
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Sales User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Maintenance User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Accounts User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }
- ], 
- "quick_entry": 0, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "search_fields": "customer, supplier, sales_partner, country, state", 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "track_seen": 0
-}
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/address/address.py b/erpnext/utilities/doctype/address/address.py
deleted file mode 100644
index 2952531..0000000
--- a/erpnext/utilities/doctype/address/address.py
+++ /dev/null
@@ -1,181 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-
-from frappe import throw, _
-from frappe.utils import cstr
-
-from frappe.model.document import Document
-from jinja2 import TemplateSyntaxError
-from frappe.utils.user import is_website_user
-from frappe.model.naming import make_autoname
-
-class Address(Document):
-	def __setup__(self):
-		self.flags.linked = False
-
-	def autoname(self):
-		if not self.address_title:
-			self.address_title = self.customer \
-				or self.supplier or self.sales_partner or self.lead
-
-		if self.address_title:
-			self.name = (cstr(self.address_title).strip() + "-" + cstr(self.address_type).strip())
-			if frappe.db.exists("Address", self.name):
-				self.name = make_autoname(cstr(self.address_title).strip() + "-" + 
-					cstr(self.address_type).strip() + "-.#")
-		else:
-			throw(_("Address Title is mandatory."))
-
-	def validate(self):
-		self.link_fields = ("customer", "supplier", "sales_partner", "lead")
-		self.link_address()
-		self.validate_primary_address()
-		self.validate_shipping_address()
-		self.validate_reference()
-
-	def validate_primary_address(self):
-		"""Validate that there can only be one primary address for particular customer, supplier"""
-		if self.is_primary_address == 1:
-			self._unset_other("is_primary_address")
-
-		elif self.is_shipping_address != 1:
-			for fieldname in self.link_fields:
-				if self.get(fieldname):
-					if not frappe.db.sql("""select name from `tabAddress` where is_primary_address=1
-						and `%s`=%s and name!=%s""" % (frappe.db.escape(fieldname), "%s", "%s"),
-						(self.get(fieldname), self.name)):
-							self.is_primary_address = 1
-					break
-
-	def link_address(self):
-		"""Link address based on owner"""
-		if not self.flags.linked:
-			self.check_if_linked()
-
-		if not self.flags.linked and not self.is_your_company_address:
-			contact = frappe.db.get_value("Contact", {"email_id": self.owner},
-				("name", "customer", "supplier"), as_dict = True)
-			if contact:
-				self.customer = contact.customer
-				self.supplier = contact.supplier
-
-			self.lead = frappe.db.get_value("Lead", {"email_id": self.owner})
-
-	def check_if_linked(self):
-		for fieldname in self.link_fields:
-			if self.get(fieldname):
-				self.flags.linked = True
-				break
-
-	def validate_shipping_address(self):
-		"""Validate that there can only be one shipping address for particular customer, supplier"""
-		if self.is_shipping_address == 1:
-			self._unset_other("is_shipping_address")
-			
-	def validate_reference(self):
-		if self.is_your_company_address:
-			if not self.company:
-				frappe.throw(_("Company is mandatory, as it is your company address"))
-			if self.customer or self.supplier or self.sales_partner or self.lead:
-				frappe.throw(_("Remove reference of customer, supplier, sales partner and lead, as it is your company address"))
-
-	def _unset_other(self, is_address_type):
-		for fieldname in ["customer", "supplier", "sales_partner", "lead"]:
-			if self.get(fieldname):
-				frappe.db.sql("""update `tabAddress` set `%s`=0 where `%s`=%s and name!=%s""" %
-					(is_address_type, fieldname, "%s", "%s"), (self.get(fieldname), self.name))
-				break
-
-	def get_display(self):
-		return get_address_display(self.as_dict())
-
-@frappe.whitelist()
-def get_address_display(address_dict):
-	if not address_dict:
-		return
-		
-	if not isinstance(address_dict, dict):
-		address_dict = frappe.db.get_value("Address", address_dict, "*", as_dict=True) or {}
-
-	name, template = get_address_templates(address_dict)
-	
-	try:
-		return frappe.render_template(template, address_dict)
-	except TemplateSyntaxError:
-		frappe.throw(_("There is an error in your Address Template {0}").format(name))
-
-
-def get_territory_from_address(address):
-	"""Tries to match city, state and country of address to existing territory"""
-	if not address:
-		return
-
-	if isinstance(address, basestring):
-		address = frappe.get_doc("Address", address)
-
-	territory = None
-	for fieldname in ("city", "state", "country"):
-		territory = frappe.db.get_value("Territory", address.get(fieldname))
-		if territory:
-			break
-
-	return territory
-
-def get_list_context(context=None):
-	from erpnext.shopping_cart.cart import get_address_docs
-	return {
-		"title": _("Addresses"),
-		"get_list": get_address_list,
-		"row_template": "templates/includes/address_row.html",
-		'no_breadcrumbs': True,
-	}
-	
-def get_address_list(doctype, txt, filters, limit_start, limit_page_length=20):
-	from frappe.www.list import get_list
-	user = frappe.session.user
-	ignore_permissions = False
-	if is_website_user():
-		if not filters: filters = []
-		filters.append(("Address", "owner", "=", user))
-		ignore_permissions = True
-
-	return get_list(doctype, txt, filters, limit_start, limit_page_length, ignore_permissions=ignore_permissions)
-	
-def has_website_permission(doc, ptype, user, verbose=False):
-	"""Returns true if customer or lead matches with user"""
-	customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user}, "customer")
-	if customer:
-		return doc.customer == customer
-	else:
-		lead = frappe.db.get_value("Lead", {"email_id": frappe.session.user})
-		if lead:
-			return doc.lead == lead
-
-	return False
-
-def get_address_templates(address):
-	result = frappe.db.get_value("Address Template", \
-		{"country": address.get("country")}, ["name", "template"])
-		
-	if not result:
-		result = frappe.db.get_value("Address Template", \
-			{"is_default": 1}, ["name", "template"])
-
-	if not result:
-		frappe.throw(_("No default Address Template found. Please create a new one from Setup > Printing and Branding > Address Template."))
-	else:
-		return result
-
-@frappe.whitelist()
-def get_shipping_address(company):
-	filters = {"company": company, "is_your_company_address":1}
-	fieldname = ["name", "address_line1", "address_line2", "city", "state", "country"]
-
-	address_as_dict = frappe.db.get_value("Address", filters=filters, fieldname=fieldname, as_dict=True)
-
-	if address_as_dict:
-		name, address_template = get_address_templates(address_as_dict)
-		return address_as_dict.get("name"), frappe.render_template(address_template, address_as_dict)
diff --git a/erpnext/utilities/doctype/address/test_address.py b/erpnext/utilities/doctype/address/test_address.py
deleted file mode 100644
index 36f2535..0000000
--- a/erpnext/utilities/doctype/address/test_address.py
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-
-import frappe
-test_records = frappe.get_test_records('Address')
-
-import unittest
-import frappe
-
-from erpnext.utilities.doctype.address.address import get_address_display
-
-class TestAddress(unittest.TestCase):
-	def test_template_works(self):
-		address = frappe.get_list("Address")[0].name
-		display = get_address_display(frappe.get_doc("Address", address).as_dict())
-		self.assertTrue(display)
-
-
-test_dependencies = ["Address Template"]
diff --git a/erpnext/utilities/doctype/address/test_records.json b/erpnext/utilities/doctype/address/test_records.json
deleted file mode 100644
index a7bde9a..0000000
--- a/erpnext/utilities/doctype/address/test_records.json
+++ /dev/null
@@ -1,15 +0,0 @@
-[
- {
-  "address_line1": "_Test Address Line 1", 
-  "address_title": "_Test Address", 
-  "address_type": "Office", 
-  "city": "_Test City",
-  "state": "Test State",
-  "country": "India", 
-  "customer": "_Test Customer", 
-  "customer_name": "_Test Customer", 
-  "doctype": "Address", 
-  "is_primary_address": 1, 
-  "phone": "+91 0000000000"
- }
-]
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/address_template/__init__.py b/erpnext/utilities/doctype/address_template/__init__.py
deleted file mode 100644
index e69de29..0000000
--- a/erpnext/utilities/doctype/address_template/__init__.py
+++ /dev/null
diff --git a/erpnext/utilities/doctype/address_template/address_template.js b/erpnext/utilities/doctype/address_template/address_template.js
deleted file mode 100644
index c055bca..0000000
--- a/erpnext/utilities/doctype/address_template/address_template.js
+++ /dev/null
@@ -1,16 +0,0 @@
-// Copyright (c) 2016, Frappe Technologies Pvt. Ltd. and contributors
-// For license information, please see license.txt
-
-frappe.ui.form.on('Address Template', {
-	refresh: function(frm) {
-		if(frm.is_new() && !frm.doc.template) {
-			// set default template via js so that it is translated
-			frappe.call({
-				method: 'erpnext.utilities.doctype.address_template.address_template.get_default_address_template',
-				callback: function(r) {
-					frm.set_value('template', r.message);
-				}
-			});
-		}
-	}
-});
diff --git a/erpnext/utilities/doctype/address_template/address_template.json b/erpnext/utilities/doctype/address_template/address_template.json
deleted file mode 100644
index 6ff93d9..0000000
--- a/erpnext/utilities/doctype/address_template/address_template.json
+++ /dev/null
@@ -1,147 +0,0 @@
-{
- "allow_copy": 0, 
- "allow_import": 0, 
- "allow_rename": 1, 
- "autoname": "field:country", 
- "beta": 0, 
- "creation": "2014-06-05 02:22:36.029850", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Setup", 
- "editable_grid": 0, 
- "engine": "InnoDB", 
- "fields": [
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "country", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Country", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Country", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "This format is used if country specific format is not found", 
-   "fieldname": "is_default", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 0, 
-   "label": "Is Default", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "", 
-   "description": "<h4>Default Template</h4>\n<p>Uses <a href=\"http://jinja.pocoo.org/docs/templates/\">Jinja Templating</a> and all the fields of Address (including Custom Fields if any) will be available</p>\n<pre><code>{{ address_line1 }}&lt;br&gt;\n{% if address_line2 %}{{ address_line2 }}&lt;br&gt;{% endif -%}\n{{ city }}&lt;br&gt;\n{% if state %}{{ state }}&lt;br&gt;{% endif -%}\n{% if pincode %} PIN:  {{ pincode }}&lt;br&gt;{% endif -%}\n{{ country }}&lt;br&gt;\n{% if phone %}Phone: {{ phone }}&lt;br&gt;{% endif -%}\n{% if fax %}Fax: {{ fax }}&lt;br&gt;{% endif -%}\n{% if email_id %}Email: {{ email_id }}&lt;br&gt;{% endif -%}\n</code></pre>", 
-   "fieldname": "template", 
-   "fieldtype": "Code", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Template", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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
-  }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "icon": "fa fa-map-marker", 
- "idx": 0, 
- "image_view": 0, 
- "in_create": 0, 
- "in_dialog": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2016-11-07 05:47:11.633848", 
- "modified_by": "Administrator", 
- "module": "Utilities", 
- "name": "Address Template", 
- "name_case": "", 
- "owner": "Administrator", 
- "permissions": [
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 0, 
-   "export": 1, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "System Manager", 
-   "set_user_permissions": 1, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }
- ], 
- "quick_entry": 1, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "sort_field": "modified", 
- "sort_order": "DESC", 
- "track_seen": 0
-}
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/address_template/address_template.py b/erpnext/utilities/doctype/address_template/address_template.py
deleted file mode 100644
index 64aaa45..0000000
--- a/erpnext/utilities/doctype/address_template/address_template.py
+++ /dev/null
@@ -1,42 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# For license information, please see license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.model.document import Document
-from frappe.utils.jinja import validate_template
-from frappe import _
-
-class AddressTemplate(Document):
-	def validate(self):
-		if not self.template:
-			self.template = get_default_address_template()
-
-		self.defaults = frappe.db.get_values("Address Template", {"is_default":1, "name":("!=", self.name)})
-		if not self.is_default:
-			if not self.defaults:
-				self.is_default = 1
-				frappe.msgprint(_("Setting this Address Template as default as there is no other default"))
-
-		validate_template(self.template)
-
-	def on_update(self):
-		if self.is_default and self.defaults:
-			for d in self.defaults:
-				frappe.db.set_value("Address Template", d[0], "is_default", 0)
-
-	def on_trash(self):
-		if self.is_default:
-			frappe.throw(_("Default Address Template cannot be deleted"))
-
-@frappe.whitelist()
-def get_default_address_template():
-	'''Get default address template (translated)'''
-	return '''{{ address_line1 }}<br>{% if address_line2 %}{{ address_line2 }}<br>{% endif -%}\
-{{ city }}<br>
-{% if state %}{{ state }}<br>{% endif -%}
-{% if pincode %}{{ pincode }}<br>{% endif -%}
-{{ country }}<br>
-{% if phone %}'''+_('Phone')+''': {{ phone }}<br>{% endif -%}
-{% if fax %}'''+_('Fax')+''': {{ fax }}<br>{% endif -%}
-{% if email_id %}'''+_('Email')+''': {{ email_id }}<br>{% endif -%}'''
diff --git a/erpnext/utilities/doctype/address_template/test_address_template.py b/erpnext/utilities/doctype/address_template/test_address_template.py
deleted file mode 100644
index 9490005..0000000
--- a/erpnext/utilities/doctype/address_template/test_address_template.py
+++ /dev/null
@@ -1,27 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: See license.txt
-
-from __future__ import unicode_literals
-
-import frappe
-test_records = frappe.get_test_records('Address Template')
-
-import unittest
-import frappe
-
-class TestAddressTemplate(unittest.TestCase):
-	def test_default_is_unset(self):
-		a = frappe.get_doc("Address Template", "India")
-		a.is_default = 1
-		a.save()
-
-		b = frappe.get_doc("Address Template", "Brazil")
-		b.is_default = 1
-		b.save()
-
-		self.assertEqual(frappe.db.get_value("Address Template", "India", "is_default"), 0)
-
-	def tearDown(self):
-		a = frappe.get_doc("Address Template", "India")
-		a.is_default = 1
-		a.save()
diff --git a/erpnext/utilities/doctype/address_template/test_records.json b/erpnext/utilities/doctype/address_template/test_records.json
deleted file mode 100644
index 412c9e7..0000000
--- a/erpnext/utilities/doctype/address_template/test_records.json
+++ /dev/null
@@ -1,13 +0,0 @@
-[
- {
-  "country": "India",
-  "is_default": 1,
-  "template": "{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif %}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif %}\n{% if pincode %} PIN / ZIP:  {{ pincode }}<br>{% endif %}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif %}\n{% if fax %}Fax: {{ fax }}<br>{% endif %}\n{% if email_id %}Email: {{ email_id }}<br>{% endif %}\n"
- },
- {
-  "country": "Brazil",
-  "is_default": 0,
-  "template": "{{ address_title }}<br>\n{{ address_line1 }}<br>\n{% if address_line2 %}{{ address_line2 }}<br>{% endif %}\n{{ city }}<br>\n{% if state %}{{ state }}<br>{% endif %}\n{% if pincode %} PIN / ZIP:  {{ pincode }}<br>{% endif %}\n{{ country }}<br>\n{% if phone %}Phone: {{ phone }}<br>{% endif %}\n{% if fax %}Fax: {{ fax }}<br>{% endif %}\n{% if email_id %}Email: {{ email_id }}<br>{% endif %}\n"
- }
-]
-
diff --git a/erpnext/utilities/doctype/contact/README.md b/erpnext/utilities/doctype/contact/README.md
deleted file mode 100644
index 484522c..0000000
--- a/erpnext/utilities/doctype/contact/README.md
+++ /dev/null
@@ -1 +0,0 @@
-Contact representing a Customer or Supplier.
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/contact/__init__.py b/erpnext/utilities/doctype/contact/__init__.py
deleted file mode 100644
index baffc48..0000000
--- a/erpnext/utilities/doctype/contact/__init__.py
+++ /dev/null
@@ -1 +0,0 @@
-from __future__ import unicode_literals
diff --git a/erpnext/utilities/doctype/contact/contact.js b/erpnext/utilities/doctype/contact/contact.js
deleted file mode 100644
index 07d9d6f..0000000
--- a/erpnext/utilities/doctype/contact/contact.js
+++ /dev/null
@@ -1,31 +0,0 @@
-// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-// License: GNU General Public License v3. See license.txt
-
-{% include 'erpnext/controllers/js/contact_address_common.js' %};
-
-cur_frm.email_field = "email_id";
-frappe.ui.form.on("Contact", {
-	refresh: function(frm) {
-		if(!frm.doc.user && !frm.is_new() && frm.perm[0].write) {
-			frm.add_custom_button(__("Invite as User"), function() {
-				frappe.call({
-					method: "erpnext.utilities.doctype.contact.contact.invite_user",
-					args: {
-						contact: frm.doc.name
-					},
-					callback: function(r) {
-						frm.set_value("user", r.message);
-					}
-				});
-			});
-		}
-	},
-	validate: function(frm) {
-		// clear linked customer / supplier / sales partner on saving...
-		$.each(["Customer", "Supplier", "Sales Partner"], function(i, doctype) {
-			var name = frm.doc[doctype.toLowerCase().replace(/ /g, "_")];
-			if(name && locals[doctype] && locals[doctype][name])
-				frappe.model.remove_from_locals(doctype, name);
-		});
-	}
-});
diff --git a/erpnext/utilities/doctype/contact/contact.json b/erpnext/utilities/doctype/contact/contact.json
deleted file mode 100644
index 98061da..0000000
--- a/erpnext/utilities/doctype/contact/contact.json
+++ /dev/null
@@ -1,921 +0,0 @@
-{
- "allow_copy": 0, 
- "allow_import": 1, 
- "allow_rename": 1, 
- "beta": 0, 
- "creation": "2013-01-10 16:34:32", 
- "custom": 0, 
- "docstatus": 0, 
- "doctype": "DocType", 
- "document_type": "Setup", 
- "editable_grid": 0, 
- "engine": "InnoDB", 
- "fields": [
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "contact_section", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-user", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "first_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "First Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "first_name", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 1, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "last_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Last Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "last_name", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "email_id", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Email Address", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "email_id", 
-   "oldfieldtype": "Data", 
-   "options": "Email", 
-   "permlevel": 0, 
-   "print_hide": 0, 
-   "print_hide_if_no_value": 0, 
-   "read_only": 0, 
-   "remember_last_selected_value": 0, 
-   "report_hide": 0, 
-   "reqd": 0, 
-   "search_index": 1, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "cb00", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "Passive", 
-   "fieldname": "status", 
-   "fieldtype": "Select", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 1, 
-   "in_standard_filter": 1, 
-   "label": "Status", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Passive\nOpen\nReplied", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "phone", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Phone", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "contact_no", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "image", 
-   "fieldtype": "Attach Image", 
-   "hidden": 1, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Image", 
-   "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": 0, 
-   "reqd": 0, 
-   "search_index": 0, 
-   "set_only_once": 0, 
-   "unique": 0
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "contact_details", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Reference", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-pushpin", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "user", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "User Id", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "User", 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "customer", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Customer", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "customer", 
-   "oldfieldtype": "Link", 
-   "options": "Customer", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "customer_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Customer Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "column_break1", 
-   "fieldtype": "Column Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldtype": "Column Break", 
-   "permlevel": 0, 
-   "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, 
-   "width": "50%"
-  }, 
-  {
-   "allow_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "supplier", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Supplier", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 1, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "supplier_name", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Supplier Name", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "depends_on": "", 
-   "fieldname": "sales_partner", 
-   "fieldtype": "Link", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Sales Partner", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "Sales Partner", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "default": "0", 
-   "depends_on": "eval:(doc.customer || doc.supplier || doc.sales_partner)", 
-   "fieldname": "is_primary_contact", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Is Primary Contact", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "is_primary_contact", 
-   "oldfieldtype": "Select", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "more_info", 
-   "fieldtype": "Section Break", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "More Information", 
-   "length": 0, 
-   "no_copy": 0, 
-   "options": "fa fa-file-text", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "mobile_no", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Mobile No", 
-   "length": 0, 
-   "no_copy": 0, 
-   "oldfieldname": "mobile_no", 
-   "oldfieldtype": "Data", 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "Enter department to which this Contact belongs", 
-   "fieldname": "department", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Department", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "description": "Enter designation of this Contact", 
-   "fieldname": "designation", 
-   "fieldtype": "Data", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Designation", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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_on_submit": 0, 
-   "bold": 0, 
-   "collapsible": 0, 
-   "columns": 0, 
-   "fieldname": "unsubscribed", 
-   "fieldtype": "Check", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "ignore_xss_filter": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "in_standard_filter": 0, 
-   "label": "Unsubscribed", 
-   "length": 0, 
-   "no_copy": 0, 
-   "permlevel": 0, 
-   "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
-  }
- ], 
- "hide_heading": 0, 
- "hide_toolbar": 0, 
- "icon": "fa fa-user", 
- "idx": 1, 
- "image_field": "image", 
- "image_view": 0, 
- "in_create": 0, 
- "in_dialog": 0, 
- "is_submittable": 0, 
- "issingle": 0, 
- "istable": 0, 
- "max_attachments": 0, 
- "modified": "2016-11-07 05:30:56.576752", 
- "modified_by": "Administrator", 
- "module": "Utilities", 
- "name": "Contact", 
- "owner": "Administrator", 
- "permissions": [
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "System Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Sales Master Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 1, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase Master Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Sales Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Maintenance Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Accounts Manager", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Sales User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Purchase User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Maintenance User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 1, 
-   "delete": 0, 
-   "email": 1, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "permlevel": 0, 
-   "print": 1, 
-   "read": 1, 
-   "report": 1, 
-   "role": "Accounts User", 
-   "set_user_permissions": 0, 
-   "share": 1, 
-   "submit": 0, 
-   "write": 1
-  }, 
-  {
-   "amend": 0, 
-   "apply_user_permissions": 0, 
-   "cancel": 0, 
-   "create": 0, 
-   "delete": 0, 
-   "email": 0, 
-   "export": 0, 
-   "if_owner": 0, 
-   "import": 0, 
-   "is_custom": 0, 
-   "match": "", 
-   "permlevel": 1, 
-   "print": 0, 
-   "read": 1, 
-   "report": 1, 
-   "role": "All", 
-   "set_user_permissions": 0, 
-   "share": 0, 
-   "submit": 0, 
-   "write": 0
-  }
- ], 
- "quick_entry": 0, 
- "read_only": 0, 
- "read_only_onload": 0, 
- "sort_order": "ASC", 
- "track_seen": 0
-}
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/contact/contact.py b/erpnext/utilities/doctype/contact/contact.py
deleted file mode 100644
index be0f985..0000000
--- a/erpnext/utilities/doctype/contact/contact.py
+++ /dev/null
@@ -1,107 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-
-from __future__ import unicode_literals
-import frappe
-from frappe.utils import cstr, has_gravatar
-from frappe import _
-
-from erpnext.controllers.status_updater import StatusUpdater
-
-class Contact(StatusUpdater):
-	def autoname(self):
-		# concat first and last name
-		self.name = " ".join(filter(None,
-			[cstr(self.get(f)).strip() for f in ["first_name", "last_name"]]))
-
-		# concat party name if reqd
-		for fieldname in ("customer", "supplier", "sales_partner"):
-			if self.get(fieldname):
-				self.name = self.name + "-" + cstr(self.get(fieldname)).strip()
-				break
-
-	def validate(self):
-		self.set_status()
-		self.validate_primary_contact()
-		self.set_user()
-		if self.email_id:
-			self.image = has_gravatar(self.email_id)
-
-	def set_user(self):
-		if not self.user and self.email_id:
-			self.user = frappe.db.get_value("User", {"email": self.email_id})
-
-	def validate_primary_contact(self):
-		if self.is_primary_contact == 1:
-			if self.customer:
-				frappe.db.sql("update tabContact set is_primary_contact=0 where customer = %s",
-					(self.customer))
-			elif self.supplier:
-				frappe.db.sql("update tabContact set is_primary_contact=0 where supplier = %s",
-					 (self.supplier))
-			elif self.sales_partner:
-				frappe.db.sql("""update tabContact set is_primary_contact=0
-					where sales_partner = %s""", (self.sales_partner))
-		else:
-			if self.customer:
-				if not frappe.db.sql("select name from tabContact \
-						where is_primary_contact=1 and customer = %s", (self.customer)):
-					self.is_primary_contact = 1
-			elif self.supplier:
-				if not frappe.db.sql("select name from tabContact \
-						where is_primary_contact=1 and supplier = %s", (self.supplier)):
-					self.is_primary_contact = 1
-			elif self.sales_partner:
-				if not frappe.db.sql("select name from tabContact \
-						where is_primary_contact=1 and sales_partner = %s",
-						self.sales_partner):
-					self.is_primary_contact = 1
-
-	def on_trash(self):
-		frappe.db.sql("""update `tabIssue` set contact='' where contact=%s""",
-			self.name)
-
-@frappe.whitelist()
-def invite_user(contact):
-	contact = frappe.get_doc("Contact", contact)
-
-	if not contact.email_id:
-		frappe.throw(_("Please set Email Address"))
-
-	if contact.has_permission("write"):
-		user = frappe.get_doc({
-			"doctype": "User",
-			"first_name": contact.first_name,
-			"last_name": contact.last_name,
-			"email": contact.email_id,
-			"user_type": "Website User",
-			"send_welcome_email": 1
-		}).insert(ignore_permissions = True)
-
-		return user.name
-
-@frappe.whitelist()
-def get_contact_details(contact):
-	contact = frappe.get_doc("Contact", contact)
-	out = {
-		"contact_person": contact.get("name"),
-		"contact_display": " ".join(filter(None,
-			[contact.get("first_name"), contact.get("last_name")])),
-		"contact_email": contact.get("email_id"),
-		"contact_mobile": contact.get("mobile_no"),
-		"contact_phone": contact.get("phone"),
-		"contact_designation": contact.get("designation"),
-		"contact_department": contact.get("department")
-	}
-	return out
-
-def update_contact(doc, method):
-	'''Update contact when user is updated, if contact is found. Called via hooks'''
-	contact_name = frappe.db.get_value("Contact", {"email_id": doc.name})
-	if contact_name:
-		contact = frappe.get_doc("Contact", contact_name)
-		for key in ("first_name", "last_name", "phone"):
-			if doc.get(key):
-				contact.set(key, doc.get(key))
-		contact.flags.ignore_mandatory = True
-		contact.save(ignore_permissions=True)
diff --git a/erpnext/utilities/doctype/contact/test_contact.py b/erpnext/utilities/doctype/contact/test_contact.py
deleted file mode 100644
index 964c8d7..0000000
--- a/erpnext/utilities/doctype/contact/test_contact.py
+++ /dev/null
@@ -1,7 +0,0 @@
-# Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
-# License: GNU General Public License v3. See license.txt
-from __future__ import unicode_literals
-
-
-import frappe
-test_records = frappe.get_test_records('Contact')
\ No newline at end of file
diff --git a/erpnext/utilities/doctype/contact/test_records.json b/erpnext/utilities/doctype/contact/test_records.json
deleted file mode 100644
index 133a7b6..0000000
--- a/erpnext/utilities/doctype/contact/test_records.json
+++ /dev/null
@@ -1,22 +0,0 @@
-[
- {
-  "customer": "_Test Customer", 
-  "customer_name": "_Test Customer", 
-  "doctype": "Contact", 
-  "email_id": "test_contact_customer@example.com", 
-  "first_name": "_Test Contact For _Test Customer", 
-  "is_primary_contact": 1, 
-  "phone": "+91 0000000000", 
-  "status": "Open"
- }, 
- {
-  "doctype": "Contact", 
-  "email_id": "test_contact_supplier@example.com", 
-  "first_name": "_Test Contact For _Test Supplier", 
-  "is_primary_contact": 1, 
-  "phone": "+91 0000000000", 
-  "status": "Open", 
-  "supplier": "_Test Supplier", 
-  "supplier_name": "_Test Supplier"
- }
-]
\ No newline at end of file