Merge pull request #4252 from anandpdoshi/edge-case-website-variant-selection

[fix] Edge case in variant selection in website - when variant has less number of attributes than template
diff --git a/erpnext/__version__.py b/erpnext/__version__.py
index 58e8a30..cb277f6 100644
--- a/erpnext/__version__.py
+++ b/erpnext/__version__.py
@@ -1,2 +1,2 @@
 from __future__ import unicode_literals
-__version__ = '6.6.6'
+__version__ = '6.6.7'
diff --git a/erpnext/accounts/doctype/journal_entry/journal_entry.py b/erpnext/accounts/doctype/journal_entry/journal_entry.py
index 0826521..a0bf081 100644
--- a/erpnext/accounts/doctype/journal_entry/journal_entry.py
+++ b/erpnext/accounts/doctype/journal_entry/journal_entry.py
@@ -699,13 +699,15 @@
 
 def get_payment_entry(doc):
 	bank_account = get_default_bank_cash_account(doc.company, "Bank Entry")
+	cost_center = frappe.db.get_value("Company", doc.company, "cost_center")
 
 	jv = frappe.new_doc('Journal Entry')
 	jv.voucher_type = 'Bank Entry'
 	jv.company = doc.company
 	jv.fiscal_year = doc.fiscal_year
 
-	jv.append("accounts")
+	d1 = jv.append("accounts")
+	d1.cost_center = cost_center
 	d2 = jv.append("accounts")
 
 	if bank_account:
@@ -715,6 +717,7 @@
 		d2.account_type = bank_account["account_type"]
 		d2.exchange_rate = get_exchange_rate(bank_account["account"],
 			bank_account["account_currency"], doc.company)
+		d2.cost_center = cost_center
 
 	return jv
 
diff --git a/erpnext/buying/doctype/purchase_common/purchase_common.py b/erpnext/buying/doctype/purchase_common/purchase_common.py
index 28ea23c..030d6a2 100644
--- a/erpnext/buying/doctype/purchase_common/purchase_common.py
+++ b/erpnext/buying/doctype/purchase_common/purchase_common.py
@@ -42,6 +42,8 @@
 		items = []
 		for d in obj.get("items"):
 			if not d.qty:
+				if obj.doctype == "Purchase Receipt" and d.rejected_qty:
+					continue
 				frappe.throw(_("Please enter quantity for Item {0}").format(d.item_code))
 
 			# udpate with latest quantities
@@ -56,11 +58,11 @@
 					d.set(x, f_lst[x])
 
 			item = frappe.db.sql("""select is_stock_item, is_purchase_item,
-				is_sub_contracted_item, end_of_life from `tabItem` where name=%s""",
+				is_sub_contracted_item, end_of_life, disabled from `tabItem` where name=%s""",
 				d.item_code, as_dict=1)[0]
 
 			from erpnext.stock.doctype.item.item import validate_end_of_life
-			validate_end_of_life(d.item_code, item.end_of_life)
+			validate_end_of_life(d.item_code, item.end_of_life, item.disabled)
 
 			# validate stock item
 			if item.is_stock_item==1 and d.qty and not d.warehouse:
@@ -72,6 +74,7 @@
 					frappe.throw(_("{0} must be a Purchased or Sub-Contracted Item in row {1}").format(d.item_code, d.idx))
 
 			items.append(cstr(d.item_code))
+
 		if items and len(items) != len(set(items)) and \
 			not cint(frappe.db.get_single_value("Buying Settings", "allow_multiple_items") or 0):
 			frappe.msgprint(_("Warning: Same item has been entered multiple times."))
diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py
index e2de6c3..ffc682f 100644
--- a/erpnext/controllers/queries.py
+++ b/erpnext/controllers/queries.py
@@ -166,6 +166,7 @@
 		from tabItem
 		where tabItem.docstatus < 2
 			and ifnull(tabItem.has_variants, 0)=0
+			and tabItem.disabled=0
 			and (tabItem.end_of_life > %(today)s or ifnull(tabItem.end_of_life, '0000-00-00')='0000-00-00')
 			and (tabItem.`{key}` LIKE %(txt)s
 				or tabItem.item_name LIKE %(txt)s
@@ -303,10 +304,10 @@
 	# Hence the first condition is an "OR"
 	if not filters: filters = {}
 
-	condition = ""	
+	condition = ""
 	if filters.get("company"):
 		condition += "and tabAccount.company = %(company)s"
-	
+
 	return frappe.db.sql("""select tabAccount.name from `tabAccount`
 			where (tabAccount.report_type = "Profit and Loss"
 					or tabAccount.account_type in ("Income Account", "Temporary"))
@@ -314,6 +315,6 @@
 				and tabAccount.`{key}` LIKE %(txt)s
 				{condition} {match_condition}"""
 			.format(condition=condition, match_condition=get_match_cond(doctype), key=searchfield), {
-				'txt': "%%%s%%" % frappe.db.escape(txt), 
+				'txt': "%%%s%%" % frappe.db.escape(txt),
 				'company': filters.get("company", "")
-			})
\ No newline at end of file
+			})
diff --git a/erpnext/hooks.py b/erpnext/hooks.py
index 569572b..471b692 100644
--- a/erpnext/hooks.py
+++ b/erpnext/hooks.py
@@ -29,7 +29,7 @@
 """
 app_icon = "icon-th"
 app_color = "#e74c3c"
-app_version = "6.6.6"
+app_version = "6.6.7"
 github_link = "https://github.com/frappe/erpnext"
 
 error_report_email = "support@erpnext.com"
diff --git a/erpnext/hr/doctype/leave_allocation/leave_allocation.json b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
index 19e8001..070e518 100644
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.json
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.json
@@ -147,20 +147,18 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "default": "Today", 
-   "fieldname": "posting_date", 
+   "fieldname": "from_date", 
    "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
    "in_filter": 0, 
-   "in_list_view": 1, 
-   "label": "Posting Date", 
-   "no_copy": 1, 
-   "oldfieldname": "date", 
-   "oldfieldtype": "Date", 
+   "in_list_view": 0, 
+   "label": "From Date", 
+   "no_copy": 0, 
    "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
-   "read_only": 1, 
+   "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
    "search_index": 0, 
@@ -171,23 +169,21 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "fiscal_year", 
-   "fieldtype": "Link", 
+   "fieldname": "to_date", 
+   "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Fiscal Year", 
+   "label": "To Date", 
    "no_copy": 0, 
-   "oldfieldname": "fiscal_year", 
-   "oldfieldtype": "Data", 
-   "options": "Fiscal Year", 
    "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
    "read_only": 0, 
    "report_hide": 0, 
    "reqd": 1, 
-   "search_index": 1, 
+   "search_index": 0, 
    "set_only_once": 0, 
    "unique": 0
   }, 
@@ -310,7 +306,7 @@
  "is_submittable": 1, 
  "issingle": 0, 
  "istable": 0, 
- "modified": "2015-10-02 07:38:55.314632", 
+ "modified": "2015-10-28 18:18:29.137427", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Allocation", 
@@ -359,7 +355,7 @@
  ], 
  "read_only": 0, 
  "read_only_onload": 0, 
- "search_fields": "employee,employee_name,leave_type,total_leaves_allocated,fiscal_year", 
+ "search_fields": "employee,employee_name,leave_type,total_leaves_allocated", 
  "sort_field": "modified", 
  "sort_order": "DESC"
 }
\ 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 4e74b28..146c3fa 100755
--- a/erpnext/hr/doctype/leave_allocation/leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/leave_allocation.py
@@ -3,13 +3,14 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import cint, flt
+from frappe.utils import cint, flt, date_diff
 from frappe import _
 from frappe.model.document import Document
 from erpnext.hr.utils import set_employee_name
 
 class LeaveAllocation(Document):
 	def validate(self):
+		self.validate_period()
 		self.validate_new_leaves_allocated_value()
 		self.check_existing_leave_allocation()
 		if not self.total_leaves_allocated:
@@ -22,7 +23,11 @@
 
 	def on_update(self):
 		self.get_total_allocated_leaves()
-
+	
+	def validate_period(self):
+		if date_diff(self.to_date, self.from_date) <= 0:
+			frappe.throw(_("Invalid period"))
+	
 	def validate_new_leaves_allocated_value(self):
 		"""validate that leave allocation is in multiples of 0.5"""
 		if flt(self.new_leaves_allocated) % 0.5:
@@ -30,29 +35,30 @@
 
 	def check_existing_leave_allocation(self):
 		"""check whether leave for same type is already allocated or not"""
-		leave_allocation = frappe.db.sql("""select name from `tabLeave Allocation`
-			where employee=%s and leave_type=%s and fiscal_year=%s and docstatus=1""",
-			(self.employee, self.leave_type, self.fiscal_year))
+		leave_allocation = frappe.db.sql("""select name from `tabLeave Allocation` 
+			where employee='%s' and leave_type='%s' and to_date >= '%s' and from_date <= '%s' and docstatus=1
+		"""%(self.employee, self.leave_type, self.from_date, self.to_date))
+
 		if leave_allocation:
-			frappe.msgprint(_("Leaves for type {0} already allocated for Employee {1} for Fiscal Year {0}").format(self.leave_type,
-				self.employee, self.fiscal_year))
+			frappe.msgprint(_("Leaves for type {0} already allocated for Employee {1} for period {2} - {3}").format(self.leave_type,
+				self.employee, self.from_date, self.to_date))
 			frappe.throw('<a href="#Form/Leave Allocation/{0}">{0}</a>'.format(leave_allocation[0][0]))
 
-	def get_leave_bal(self, prev_fyear):
-		return self.get_leaves_allocated(prev_fyear) - self.get_leaves_applied(prev_fyear)
+	def get_leave_bal(self):
+		return self.get_leaves_allocated() - self.get_leaves_applied()
 
-	def get_leaves_applied(self, fiscal_year):
+	def get_leaves_applied(self):
 		leaves_applied = frappe.db.sql("""select SUM(ifnull(total_leave_days, 0))
 			from `tabLeave Application` where employee=%s and leave_type=%s
-			and fiscal_year=%s and docstatus=1""",
-			(self.employee, self.leave_type, fiscal_year))
+			and to_date<=%s and docstatus=1""",
+			(self.employee, self.leave_type, self.from_date))
 		return leaves_applied and flt(leaves_applied[0][0]) or 0
 
-	def get_leaves_allocated(self, fiscal_year):
+	def get_leaves_allocated(self):
 		leaves_allocated = frappe.db.sql("""select SUM(ifnull(total_leaves_allocated, 0))
 			from `tabLeave Allocation` where employee=%s and leave_type=%s
-			and fiscal_year=%s and docstatus=1 and name!=%s""",
-			(self.employee, self.leave_type, fiscal_year, self.name))
+			and to_date<=%s and docstatus=1 and name!=%s""",
+			(self.employee, self.leave_type, self.from_date, self.name))
 		return leaves_allocated and flt(leaves_allocated[0][0]) or 0
 
 	def allow_carry_forward(self):
@@ -67,14 +73,11 @@
 	def get_carry_forwarded_leaves(self):
 		if self.carry_forward:
 			self.allow_carry_forward()
-		prev_fiscal_year = frappe.db.sql("""select name from `tabFiscal Year`
-			where year_start_date = (select date_add(year_start_date, interval -1 year)
-				from `tabFiscal Year` where name=%s)
-			order by name desc limit 1""", self.fiscal_year)
-		prev_fiscal_year = prev_fiscal_year and prev_fiscal_year[0][0] or ''
+			
 		prev_bal = 0
-		if prev_fiscal_year and cint(self.carry_forward) == 1:
-			prev_bal = self.get_leave_bal(prev_fiscal_year)
+		if cint(self.carry_forward) == 1:
+			prev_bal = self.get_leave_bal()
+		
 		ret = {
 			'carry_forwarded_leaves': prev_bal,
 			'total_leaves_allocated': flt(prev_bal) + flt(self.new_leaves_allocated)
@@ -83,6 +86,11 @@
 
 	def get_total_allocated_leaves(self):
 		leave_det = self.get_carry_forwarded_leaves()
+		self.validate_total_leaves_allocated(leave_det)
 		frappe.db.set(self,'carry_forwarded_leaves',flt(leave_det['carry_forwarded_leaves']))
 		frappe.db.set(self,'total_leaves_allocated',flt(leave_det['total_leaves_allocated']))
 
+	def validate_total_leaves_allocated(self, leave_det):
+		if date_diff(self.to_date, self.from_date) <= leave_det['total_leaves_allocated']:
+			frappe.throw(_("Total allocated leaves are more than period"))
+		
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
index fe4f01b..d36fb2c 100644
--- a/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
+++ b/erpnext/hr/doctype/leave_allocation/test_leave_allocation.py
@@ -1,4 +1,69 @@
 from __future__ import unicode_literals
 import frappe
+import unittest
+from frappe.utils import getdate
 
-test_records = frappe.get_test_records('Leave Allocation')
+class TestLeaveAllocation(unittest.TestCase):
+	def test_overlapping_allocation(self):		
+		employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
+		leaves = [
+			{
+				"doctype": "Leave Allocation",
+				"__islocal": 1,
+				"employee": employee.name,
+				"employee_name": employee.employee_name,
+				"leave_type": "_Test Leave Type",
+				"from_date": getdate("2015-10-1"),
+				"to_date": getdate("2015-10-31"),
+				"new_leaves_allocated": 5,
+				"docstatus": 1			
+			},
+			{
+				"doctype": "Leave Allocation",
+				"__islocal": 1,
+				"employee": employee.name,
+				"employee_name": employee.employee_name,
+				"leave_type": "_Test Leave Type",
+				"from_date": getdate("2015-09-1"),
+				"to_date": getdate("2015-11-30"),
+				"new_leaves_allocated": 5			
+			}
+		]
+
+		frappe.get_doc(leaves[0]).save()
+		self.assertRaises(frappe.ValidationError, frappe.get_doc(leaves[1]).save)
+		
+	def test_invalid_period(self):		
+		employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
+		
+		d = frappe.get_doc({
+			"doctype": "Leave Allocation",
+			"__islocal": 1,
+			"employee": employee.name,
+			"employee_name": employee.employee_name,
+			"leave_type": "_Test Leave Type",
+			"from_date": getdate("2015-09-30"),
+			"to_date": getdate("2015-09-1"),
+			"new_leaves_allocated": 5			
+		})
+		
+		#invalid period
+		self.assertRaises(frappe.ValidationError, d.save)
+	
+	def test_allocated_leave_days_over_period(self):
+		employee = frappe.get_doc("Employee", frappe.db.sql_list("select name from tabEmployee limit 1")[0])
+		d = frappe.get_doc({
+			"doctype": "Leave Allocation",
+			"__islocal": 1,
+			"employee": employee.name,
+			"employee_name": employee.employee_name,
+			"leave_type": "_Test Leave Type",
+			"from_date": getdate("2015-09-1"),
+			"to_date": getdate("2015-09-30"),
+			"new_leaves_allocated": 35			
+		})
+		
+		#allocated leave more than period 
+		self.assertRaises(frappe.ValidationError, d.save)
+		
+test_dependencies = ["Employee", "Leave Type"]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_allocation/test_records.json b/erpnext/hr/doctype/leave_allocation/test_records.json
index 036dc49..106ed0e 100644
--- a/erpnext/hr/doctype/leave_allocation/test_records.json
+++ b/erpnext/hr/doctype/leave_allocation/test_records.json
@@ -1,18 +1,20 @@
 [
- {
-  "docstatus": 1,
-  "doctype": "Leave Allocation",
-  "employee": "_T-Employee-0001",
-  "fiscal_year": "_Test Fiscal Year 2013",
-  "leave_type": "_Test Leave Type",
-  "new_leaves_allocated": 15
- },
- {
-  "docstatus": 1,
-  "doctype": "Leave Allocation",
-  "employee": "_T-Employee-0002",
-  "fiscal_year": "_Test Fiscal Year 2013",
-  "leave_type": "_Test Leave Type",
-  "new_leaves_allocated": 15
- }
-]
+	{
+		"docstatus": 1,
+		"doctype": "Leave Allocation",
+		"employee": "_T-Employee-0001",
+		"from_date": "2013-01-01",
+		"to_date": "2013-12-31",
+		"leave_type": "_Test Leave Type",
+		"new_leaves_allocated": 15
+	},
+	{
+		"docstatus": 1,
+		"doctype": "Leave Allocation",
+		"employee": "_T-Employee-0002",
+		"from_date": "2013-01-01",
+		"to_date": "2013-12-31",
+		"leave_type": "_Test Leave Type",
+		"new_leaves_allocated": 15
+	}
+]
\ No newline at end of file
diff --git a/erpnext/hr/doctype/leave_application/leave_application.js b/erpnext/hr/doctype/leave_application/leave_application.js
index 5b5bf8f..c8bd753 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.js
+++ b/erpnext/hr/doctype/leave_application/leave_application.js
@@ -53,10 +53,6 @@
 		frm.trigger("get_leave_balance");
 	},
 
-	fiscal_year: function(frm) {
-		frm.trigger("get_leave_balance");
-	},
-
 	leave_type: function(frm) {
 		frm.trigger("get_leave_balance");
 	},
@@ -85,12 +81,13 @@
 	},
 
 	get_leave_balance: function(frm) {
-		if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.fiscal_year) {
+		if(frm.doc.docstatus==0 && frm.doc.employee && frm.doc.leave_type && frm.doc.from_date && frm.doc.to_date) {
 			return frm.call({
 				method: "get_leave_balance",
 				args: {
 					employee: frm.doc.employee,
-					fiscal_year: frm.doc.fiscal_year,
+					from_date: frm.doc.from_date,
+					to_date: frm.doc.to_date,
 					leave_type: frm.doc.leave_type
 				}
 			});
@@ -109,6 +106,7 @@
 					callback: function(response) {
 						if (response && response.message) {
 							frm.set_value('total_leave_days', response.message.total_leave_days);
+							frm.trigger("get_leave_balance");
 						}
 					}
 				});
diff --git a/erpnext/hr/doctype/leave_application/leave_application.json b/erpnext/hr/doctype/leave_application/leave_application.json
index f51c220..62e4cd8 100644
--- a/erpnext/hr/doctype/leave_application/leave_application.json
+++ b/erpnext/hr/doctype/leave_application/leave_application.json
@@ -21,7 +21,7 @@
    "ignore_user_permissions": 0, 
    "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Status",  
+   "label": "Status", 
    "no_copy": 1, 
    "options": "Open\nApproved\nRejected", 
    "permlevel": 1, 
@@ -559,7 +559,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 3, 
- "modified": "2015-10-02 07:38:55.471712", 
+ "modified": "2015-10-28 16:14:25.640730", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Application", 
diff --git a/erpnext/hr/doctype/leave_application/leave_application.py b/erpnext/hr/doctype/leave_application/leave_application.py
index 054117b..8c91173 100755
--- a/erpnext/hr/doctype/leave_application/leave_application.py
+++ b/erpnext/hr/doctype/leave_application/leave_application.py
@@ -100,7 +100,7 @@
 
 			if not is_lwp(self.leave_type):
 				self.leave_balance = get_leave_balance(self.employee,
-					self.leave_type, self.fiscal_year)["leave_balance"]
+					self.leave_type, self.from_date, self.to_date)["leave_balance"]
 
 				if self.status != "Rejected" \
 						and self.leave_balance - self.total_leave_days < 0:
@@ -122,9 +122,8 @@
 			employee = %(employee)s
 			and docstatus < 2
 			and status in ("Open", "Approved")
-			and (from_date between %(from_date)s and %(to_date)s
-				or to_date between %(from_date)s and %(to_date)s
-				or %(from_date)s between from_date and to_date)
+			and to_date >= %(from_date)s 
+			and from_date <= %(to_date)s
 			and name != %(name)s""", {
 				"employee": self.employee,
 				"from_date": self.from_date,
@@ -251,18 +250,18 @@
 	return ret
 
 @frappe.whitelist()
-def get_leave_balance(employee, leave_type, fiscal_year):
+def get_leave_balance(employee, leave_type, from_date, to_date):
 	leave_all = frappe.db.sql("""select total_leaves_allocated
 		from `tabLeave Allocation` where employee = %s and leave_type = %s
-		and fiscal_year = %s and docstatus = 1""", (employee,
-			leave_type, fiscal_year))
+		and from_date<=%s and to_date>=%s and docstatus = 1""", (employee,
+			leave_type, from_date, to_date))
 
 	leave_all = leave_all and flt(leave_all[0][0]) or 0
 
 	leave_app = frappe.db.sql("""select SUM(total_leave_days)
 		from `tabLeave Application`
-		where employee = %s and leave_type = %s and fiscal_year = %s
-		and status="Approved" and docstatus = 1""", (employee, leave_type, fiscal_year))
+		where employee = %s and leave_type = %s and to_date>=%s and from_date<=%s
+		and status="Approved" and docstatus = 1""", (employee, leave_type, from_date, to_date))
 	leave_app = leave_app and flt(leave_app[0][0]) or 0
 
 	ret = {'leave_balance': leave_all - leave_app}
diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
index 0db0410..c92fbb8 100644
--- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
+++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.json
@@ -145,16 +145,38 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "fieldname": "fiscal_year", 
-   "fieldtype": "Link", 
+   "fieldname": "from_date", 
+   "fieldtype": "Date", 
    "hidden": 0, 
    "ignore_user_permissions": 0, 
-   "in_filter": 1, 
+   "in_filter": 0, 
    "in_list_view": 0, 
-   "label": "Fiscal Year", 
+   "label": "From Date", 
    "no_copy": 0, 
-   "options": "Fiscal Year", 
    "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 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": "to_date", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "To Date", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
    "print_hide": 0, 
    "read_only": 0, 
    "report_hide": 0, 
@@ -260,7 +282,7 @@
  "is_submittable": 0, 
  "issingle": 1, 
  "istable": 0, 
- "modified": "2015-06-05 11:38:19.994852", 
+ "modified": "2015-10-28 16:23:57.733900", 
  "modified_by": "Administrator", 
  "module": "HR", 
  "name": "Leave Control Panel", 
diff --git a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
index 706f995..77c7ad9 100644
--- a/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
+++ b/erpnext/hr/doctype/leave_control_panel/leave_control_panel.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 
-from frappe.utils import cint, cstr, flt, nowdate, comma_and
+from frappe.utils import cint, cstr, flt, nowdate, comma_and, date_diff
 from frappe import msgprint, _
 from frappe.model.document import Document
 
@@ -27,9 +27,13 @@
 		return e
 
 	def validate_values(self):
-		for f in ["fiscal_year", "leave_type", "no_of_days"]:
+		for f in ["from_date", "to_date", "leave_type", "no_of_days"]:
 			if not self.get(f):
 				frappe.throw(_("{0} is required").format(self.meta.get_label(f)))
+	
+	def to_date_validation(self):
+		if date_diff(self.to_date, self.from_date) <= 0:
+			return "Invalid period"
 
 	def allocate_leave(self):
 		self.validate_values()
@@ -45,8 +49,8 @@
 				la.employee = cstr(d[0])
 				la.employee_name = frappe.db.get_value('Employee',cstr(d[0]),'employee_name')
 				la.leave_type = self.leave_type
-				la.fiscal_year = self.fiscal_year
-				la.posting_date = nowdate()
+				la.from_date = self.from_date
+				la.to_date = self.to_date
 				la.carry_forward = cint(self.carry_forward)
 				la.new_leaves_allocated = flt(self.no_of_days)
 				la.docstatus = 1
diff --git a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js
index 4f97c43..41b1421 100644
--- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js
+++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.js
@@ -4,11 +4,16 @@
 frappe.query_reports["Employee Leave Balance"] = {
 	"filters": [
 		{
-			"fieldname":"fiscal_year",
-			"label": __("Fiscal Year"),
-			"fieldtype": "Link",
-			"options": "Fiscal Year",
-			"default": frappe.defaults.get_user_default("fiscal_year")
+			"fieldname":"from_date",
+			"label": __("From Date"),
+			"fieldtype": "Date",
+			"default": frappe.datetime.year_start()
+		},
+		{
+			"fieldname":"to_date",
+			"label": __("To Date"),
+			"fieldtype": "Date",
+			"default": frappe.datetime.year_end()
 		},
 		{
 			"fieldname":"company",
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 d6f865b..0aa88a8 100644
--- a/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
+++ b/erpnext/hr/report/employee_leave_balance/employee_leave_balance.py
@@ -24,52 +24,47 @@
 
 	leave_types = frappe.db.sql_list("select name from `tabLeave Type`")
 
-	if filters.get("fiscal_year"):
-		fiscal_years = [filters["fiscal_year"]]
-	else:
-		fiscal_years = frappe.db.sql_list("select name from `tabFiscal Year` order by name desc")
-
 	employee_names = [d.name for d in employees]
 
-	allocations = frappe.db.sql("""select employee, fiscal_year, leave_type, total_leaves_allocated
+	allocations = frappe.db.sql("""select employee, leave_type, sum(new_leaves_allocated) as leaves_allocated
 	 	from `tabLeave Allocation`
-		where docstatus=1 and employee in (%s)""" %
-		','.join(['%s']*len(employee_names)), employee_names, as_dict=True)
-
-	applications = frappe.db.sql("""select employee, fiscal_year, leave_type,
+		where docstatus=1 and employee in (%s) and from_date >= '%s' and to_date <= '%s'""" %
+		(','.join(['%s']*len(employee_names)), filters.get("from_date"),
+		 filters.get("to_date")), employee_names, as_dict=True)
+		
+	applications = frappe.db.sql("""select employee, leave_type,
 			SUM(total_leave_days) as leaves
 		from `tabLeave Application`
 		where status="Approved" and docstatus = 1 and employee in (%s)
-		group by employee, fiscal_year, leave_type""" %
-			','.join(['%s']*len(employee_names)), employee_names, as_dict=True)
+		and from_date >= '%s' and to_date <= '%s'
+		group by employee, leave_type""" %
+		(','.join(['%s']*len(employee_names)), filters.get("from_date"),
+		 filters.get("to_date")), employee_names, as_dict=True)
 
 	columns = [
-		_("Fiscal Year"), _("Employee") + ":Link/Employee:150", _("Employee Name") + "::200", _("Department") +"::150"
+		_("Employee") + ":Link/Employee:150", _("Employee Name") + "::200", _("Department") +"::150"
 	]
 
 	for leave_type in leave_types:
-		columns.append(_(leave_type) + " " + _("Allocated") + ":Float")
+		columns.append(_(leave_type) + " " + _("Opening") + ":Float")
 		columns.append(_(leave_type) + " " + _("Taken") + ":Float")
 		columns.append(_(leave_type) + " " + _("Balance") + ":Float")
 
 	data = {}
 	for d in allocations:
-		data.setdefault((d.fiscal_year, d.employee,
-			d.leave_type), frappe._dict()).allocation = d.total_leaves_allocated
+		data.setdefault((d.employee,d.leave_type), frappe._dict()).allocation = d.leaves_allocated
 
 	for d in applications:
-		data.setdefault((d.fiscal_year, d.employee,
-			d.leave_type), frappe._dict()).leaves = d.leaves
+		data.setdefault((d.employee, d.leave_type), frappe._dict()).leaves = d.leaves
 
 	result = []
-	for fiscal_year in fiscal_years:
-		for employee in employees:
-			row = [fiscal_year, employee.name, employee.employee_name, employee.department]
-			result.append(row)
-			for leave_type in leave_types:
-				tmp = data.get((fiscal_year, employee.name, leave_type), frappe._dict())
-				row.append(tmp.allocation or 0)
-				row.append(tmp.leaves or 0)
-				row.append((tmp.allocation or 0) - (tmp.leaves or 0))
+	for employee in employees:
+		row = [employee.name, employee.employee_name, employee.department]
+		result.append(row)
+		for leave_type in leave_types:
+			tmp = data.get((employee.name, leave_type), frappe._dict())
+			row.append(tmp.allocation or 0)
+			row.append(tmp.leaves or 0)
+			row.append((tmp.allocation or 0) - (tmp.leaves or 0))
 
 	return columns, result
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.js b/erpnext/manufacturing/doctype/production_order/production_order.js
index 00eac9a..7c92f2d 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.js
+++ b/erpnext/manufacturing/doctype/production_order/production_order.js
@@ -140,7 +140,7 @@
 			} else msgprint(__("Please enter Production Item first"));
 		});
 	},
-	
+
 	set_default_warehouse: function(frm) {
 		frappe.call({
 			method: "erpnext.manufacturing.doctype.production_order.production_order.get_default_warehouse",
diff --git a/erpnext/manufacturing/doctype/production_order/production_order.py b/erpnext/manufacturing/doctype/production_order/production_order.py
index e5e0a96..dbd3250 100644
--- a/erpnext/manufacturing/doctype/production_order/production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/production_order.py
@@ -4,7 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 
-from frappe.utils import flt, get_datetime, getdate, date_diff, cint
+from frappe.utils import flt, get_datetime, getdate, date_diff, cint, nowdate
 from frappe import _
 from frappe.model.document import Document
 from erpnext.manufacturing.doctype.bom.bom import validate_bom_no
@@ -159,22 +159,22 @@
 
 	def on_cancel(self):
 		self.validate_cancel()
-		
+
 		frappe.db.set(self,'status', 'Cancelled')
 		self.update_planned_qty()
 		self.delete_time_logs()
-		
+
 	def validate_cancel(self):
 		if self.status == "Stopped":
 			frappe.throw(_("Stopped Production Order cannot be cancelled, Unstop it first to cancel"))
-		
+
 		# Check whether any stock entry exists against this Production Order
 		stock_entry = frappe.db.sql("""select name from `tabStock Entry`
 			where production_order = %s and docstatus = 1""", self.name)
 		if stock_entry:
 			frappe.throw(_("Cannot cancel because submitted Stock Entry {0} exists").format(stock_entry[0][0]))
 
-	def update_planned_qty(self):		
+	def update_planned_qty(self):
 		update_bin_qty(self.production_item, self.fg_warehouse, {
 			"planned_qty": get_planned_qty(self.production_item, self.fg_warehouse)
 		})
@@ -342,8 +342,8 @@
 @frappe.whitelist()
 def get_item_details(item):
 	res = frappe.db.sql("""select stock_uom, description
-		from `tabItem` where (ifnull(end_of_life, "0000-00-00")="0000-00-00" or end_of_life > now())
-		and name=%s""", item, as_dict=1)
+		from `tabItem` where disabled=0 and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)
+		and name=%s""", (nowdate(), item), as_dict=1)
 	if not res:
 		return {}
 
diff --git a/erpnext/manufacturing/doctype/production_order/test_production_order.py b/erpnext/manufacturing/doctype/production_order/test_production_order.py
index eb26d29..cfea4e5 100644
--- a/erpnext/manufacturing/doctype/production_order/test_production_order.py
+++ b/erpnext/manufacturing/doctype/production_order/test_production_order.py
@@ -86,7 +86,7 @@
 		self.assertEqual(prod_order.name, time_log.production_order)
 		self.assertEqual((prod_order.qty - d.completed_qty), time_log.completed_qty)
 		self.assertEqual(time_diff_in_hours(d.planned_end_time, d.planned_start_time),time_log.hours)
-		
+
 		manufacturing_settings = frappe.get_doc({
 			"doctype": "Manufacturing Settings",
 			"allow_production_on_holidays": 0
@@ -136,6 +136,11 @@
 		self.assertRaises(frappe.ValidationError, prod_order.save)
 
 		frappe.db.set_value("Item", "_Test FG Item", "end_of_life", None)
+		frappe.db.set_value("Item", "_Test FG Item", "disabled", 1)
+
+		self.assertRaises(frappe.ValidationError, prod_order.save)
+
+		frappe.db.set_value("Item", "_Test FG Item", "disabled", 0)
 
 		prod_order = make_prod_order_test_record(item="_Test Variant Item", qty=1, do_not_save=True)
 		self.assertRaises(ItemHasVariantError, prod_order.save)
diff --git a/erpnext/patches/v6_6/remove_fiscal_year_from_leave_allocation.py b/erpnext/patches/v6_6/remove_fiscal_year_from_leave_allocation.py
new file mode 100644
index 0000000..1b24841
--- /dev/null
+++ b/erpnext/patches/v6_6/remove_fiscal_year_from_leave_allocation.py
@@ -0,0 +1,15 @@
+from __future__ import unicode_literals
+import frappe
+
+def execute():
+	for leave_allocation in frappe.db.sql("select name, fiscal_year from `tabLeave Allocation`", as_dict=True):
+		year_start_date, year_end_date = frappe.db.get_value("Fiscal Year", leave_allocation["fiscal_year"],
+			["year_start_date", "year_end_date"])
+		
+		frappe.db.sql("""update `tabLeave Allocation` 
+			set from_date=%s, to_date=%s where name=%s""", 
+			(year_start_date, year_end_date, leave_allocation["name"]))
+			
+		frappe.db.commit()
+			
+		
\ No newline at end of file
diff --git a/erpnext/public/images/YouTube-icon-full_color.png b/erpnext/public/images/YouTube-icon-full_color.png
new file mode 100644
index 0000000..5322e65
--- /dev/null
+++ b/erpnext/public/images/YouTube-icon-full_color.png
Binary files differ
diff --git a/erpnext/public/images/erpnext-video-placeholder.jpg b/erpnext/public/images/erpnext-video-placeholder.jpg
new file mode 100644
index 0000000..7a0f843
--- /dev/null
+++ b/erpnext/public/images/erpnext-video-placeholder.jpg
Binary files differ
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 9736701..9a4497b 100644
--- a/erpnext/setup/doctype/item_group/item_group.py
+++ b/erpnext/setup/doctype/item_group/item_group.py
@@ -4,6 +4,7 @@
 from __future__ import unicode_literals
 import frappe
 import urllib
+from frappe.utils import nowdate
 from frappe.utils.nestedset import NestedSet
 from frappe.website.website_generator import WebsiteGenerator
 from frappe.website.render import clear_cache
@@ -71,14 +72,16 @@
 			concat(parent_website_route, "/", page_name) as route
 		from `tabItem`
 		where show_in_website = 1
+			and disabled=0
+			and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
 			and (variant_of = '' or variant_of is null)
-			and (item_group in (%s)
-			or name in (select parent from `tabWebsite Item Group` where item_group in (%s)))
-			""" % (child_groups, child_groups)
+			and (item_group in ({child_groups})
+			or name in (select parent from `tabWebsite Item Group` where item_group in ({child_groups})))
+			""".format(child_groups=child_groups)
 
 	query += """order by weightage desc, modified desc limit %s, %s""" % (start, limit)
 
-	data = frappe.db.sql(query, {"product_group": product_group}, as_dict=1)
+	data = frappe.db.sql(query, {"product_group": product_group, "today": nowdate()}, as_dict=1)
 
 	return [get_item_for_list_in_html(r) for r in data]
 
diff --git a/erpnext/setup/page/setup_wizard/setup_wizard.js b/erpnext/setup/page/setup_wizard/setup_wizard.js
index c588e74..998131f 100644
--- a/erpnext/setup/page/setup_wizard/setup_wizard.js
+++ b/erpnext/setup/page/setup_wizard/setup_wizard.js
@@ -658,7 +658,7 @@
 		return frappe.render_template("setup_wizard_message", {
 			image: "/assets/frappe/images/ui/bubble-tea-happy.svg",
 			title: __('Setup Complete'),
-			message: __('Your setup is complete. Refreshing.') + ".."
+			message: ""
 		});
 	},
 
@@ -670,6 +670,7 @@
 			args: values,
 			callback: function(r) {
 				wiz.show_complete();
+				localStorage.setItem("session_last_route", "#welcome-to-erpnext");
 				setTimeout(function() {
 					window.location = "/desk";
 				}, 2000);
diff --git a/erpnext/setup/page/welcome_to_erpnext/__init__.py b/erpnext/setup/page/welcome_to_erpnext/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/erpnext/setup/page/welcome_to_erpnext/__init__.py
diff --git a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.css b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.css
new file mode 100644
index 0000000..1fbb459
--- /dev/null
+++ b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.css
@@ -0,0 +1,13 @@
+#page-welcome-to-erpnext ul li {
+	margin: 7px 0px;
+}
+
+#page-welcome-to-erpnext .video-placeholder-image {
+	width: 100%;
+	cursor: pointer;
+}
+
+#page-welcome-to-erpnext .youtube-icon {
+	width: 10%;
+	cursor: pointer;
+}
diff --git a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.html b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.html
new file mode 100644
index 0000000..032eab9
--- /dev/null
+++ b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.html
@@ -0,0 +1,31 @@
+<div class="container welcome-to-erpnext text-center" style="padding: 30px 0px;">
+	<div class="row">
+		<div class="col-md-8 col-md-push-2 col-sm-12">
+			<h1>{%= __("Welcome to ERPNext") %}</h1>
+			<p class="text-muted">
+				{%= __("To get the best out of ERPNext, we recommend that you take some time and watch these help videos.") %}
+				<br><br>
+			</p>
+
+			<div class="embed-responsive embed-responsive-16by9">
+				<div class="video-placeholder embed-responsive-item">
+					<img class="video-placeholder-image"
+						src="/assets/erpnext/images/erpnext-video-placeholder.jpg">
+					<img class="centered youtube-icon"
+						src="/assets/erpnext/images/YouTube-icon-full_color.png">
+				</div>
+			</div>
+
+			<br>
+			<hr>
+			<h3>Next Steps</h3>
+			<ul class="list-unstyled">
+				<li><a class="text-muted" href="#">{%= __("Go to the Desktop and start using ERPNext") %}</a></li>
+				<li><a class="text-muted" href="#Module/Learn">{%= __("View a list of all the help videos") %}</a></li>
+				<li><a class="text-muted" href="https://manual.erpnext.com" target="_blank">{%= __("Read the ERPNext Manual") %}</a></li>
+				<li><a class="text-muted" href="https://discuss.erpnext.com" target="_blank">{%= __("Community Forum") %}</a></li>
+			</ul>
+
+		</div>
+	</div>
+</div>
diff --git a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js
new file mode 100644
index 0000000..f072b8d
--- /dev/null
+++ b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.js
@@ -0,0 +1,20 @@
+frappe.pages['welcome-to-erpnext'].on_page_load = function(wrapper) {
+	var parent = $('<div class="welcome-to-erpnext"></div>').appendTo(wrapper);
+
+	parent.html(frappe.render_template("welcome_to_erpnext", {}));
+
+	parent.find(".video-placeholder").on("click", function() {
+		window.erpnext_welcome_video_started = true;
+		parent.find(".video-placeholder").addClass("hidden");
+		parent.find(".embed-responsive").append('<iframe class="embed-responsive-item video-playlist" src="https://www.youtube.com/embed/videoseries?list=PL3lFfCEoMxvxDHtYyQFJeUYkWzQpXwFM9&color=white&autoplay=1&enablejsapi=1" allowfullscreen></iframe>')
+	});
+
+	// pause video on page change
+	$(document).on("page-change", function() {
+		if (window.erpnext_welcome_video_started && parent) {
+			parent.find(".video-playlist").each(function() {
+				this.contentWindow.postMessage('{"event":"command","func":"' + 'pauseVideo' + '","args":""}', '*');
+			});
+		}
+	});
+}
diff --git a/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.json b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.json
new file mode 100644
index 0000000..0f532aa
--- /dev/null
+++ b/erpnext/setup/page/welcome_to_erpnext/welcome_to_erpnext.json
@@ -0,0 +1,17 @@
+{
+ "content": null, 
+ "creation": "2015-10-28 16:27:02.197707", 
+ "docstatus": 0, 
+ "doctype": "Page", 
+ "modified": "2015-10-28 16:27:02.197707", 
+ "modified_by": "Administrator", 
+ "module": "Setup", 
+ "name": "welcome-to-erpnext", 
+ "owner": "Administrator", 
+ "page_name": "welcome-to-erpnext", 
+ "roles": [], 
+ "script": null, 
+ "standard": "Yes", 
+ "style": null, 
+ "title": "Welcome to ERPNext"
+}
\ No newline at end of file
diff --git a/erpnext/stock/doctype/item/item.json b/erpnext/stock/doctype/item/item.json
index b36e34c..bef4e25 100644
--- a/erpnext/stock/doctype/item/item.json
+++ b/erpnext/stock/doctype/item/item.json
@@ -182,31 +182,6 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
-   "default": "2099-12-31", 
-   "depends_on": "is_stock_item", 
-   "fieldname": "end_of_life", 
-   "fieldtype": "Date", 
-   "hidden": 0, 
-   "ignore_user_permissions": 0, 
-   "in_filter": 0, 
-   "in_list_view": 0, 
-   "label": "End of Life", 
-   "no_copy": 0, 
-   "oldfieldname": "end_of_life", 
-   "oldfieldtype": "Date", 
-   "permlevel": 0, 
-   "print_hide": 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_break0", 
    "fieldtype": "Column Break", 
    "hidden": 0, 
@@ -253,6 +228,28 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "fieldname": "disabled", 
+   "fieldtype": "Check", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "Disabled", 
+   "no_copy": 0, 
+   "permlevel": 0, 
+   "precision": "", 
+   "print_hide": 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": "image", 
    "fieldtype": "Attach", 
    "hidden": 0, 
@@ -440,6 +437,31 @@
    "allow_on_submit": 0, 
    "bold": 0, 
    "collapsible": 0, 
+   "default": "2099-12-31", 
+   "depends_on": "is_stock_item", 
+   "fieldname": "end_of_life", 
+   "fieldtype": "Date", 
+   "hidden": 0, 
+   "ignore_user_permissions": 0, 
+   "in_filter": 0, 
+   "in_list_view": 0, 
+   "label": "End of Life", 
+   "no_copy": 0, 
+   "oldfieldname": "end_of_life", 
+   "oldfieldtype": "Date", 
+   "permlevel": 0, 
+   "print_hide": 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, 
    "default": "", 
    "depends_on": "eval:doc.is_stock_item", 
    "fieldname": "has_batch_no", 
@@ -2113,7 +2135,7 @@
  "issingle": 0, 
  "istable": 0, 
  "max_attachments": 1, 
- "modified": "2015-10-20 12:14:43.315827", 
+ "modified": "2015-10-29 02:25:26.256373", 
  "modified_by": "Administrator", 
  "module": "Stock", 
  "name": "Item", 
diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index c621957..1d81845 100644
--- a/erpnext/stock/doctype/item/item.py
+++ b/erpnext/stock/doctype/item/item.py
@@ -245,7 +245,7 @@
 
 			# loop through previous attributes
 			for prev_attr in self.attributes[:i]:
-				combination_source.append([context.selected_attributes[prev_attr.attribute]])
+				combination_source.append([context.selected_attributes.get(prev_attr.attribute)])
 
 			combination_source.append(context.attribute_values[attr.attribute])
 
@@ -524,14 +524,17 @@
 				if variant and self.get("__islocal"):
 					frappe.throw(_("Item variant {0} exists with same attributes").format(variant), ItemVariantExistsError)
 
-def validate_end_of_life(item_code, end_of_life=None, verbose=1):
-	if not end_of_life:
-		end_of_life = frappe.db.get_value("Item", item_code, "end_of_life")
+def validate_end_of_life(item_code, end_of_life=None, disabled=None, verbose=1):
+	if (not end_of_life) or (disabled is None):
+		end_of_life, disabled = frappe.db.get_value("Item", item_code, ["end_of_life", "disabled"])
 
 	if end_of_life and end_of_life!="0000-00-00" and getdate(end_of_life) <= now_datetime().date():
 		msg = _("Item {0} has reached its end of life on {1}").format(item_code, formatdate(end_of_life))
 		_msgprint(msg, verbose)
 
+	if disabled:
+		_msgprint(_("Item {0} is disabled").format(item_code), verbose)
+
 def validate_is_stock_item(item_code, is_stock_item=None, verbose=1):
 	if not is_stock_item:
 		is_stock_item = frappe.db.get_value("Item", item_code, "is_stock_item")
diff --git a/erpnext/stock/doctype/item/item_list.js b/erpnext/stock/doctype/item/item_list.js
index 46a22ea..1074bd0 100644
--- a/erpnext/stock/doctype/item/item_list.js
+++ b/erpnext/stock/doctype/item/item_list.js
@@ -1,16 +1,18 @@
 frappe.listview_settings['Item'] = {
 	add_fields: ["item_name", "stock_uom", "item_group", "image", "variant_of",
-		"has_variants", "end_of_life", "is_sales_item"],
+		"has_variants", "end_of_life", "disabled", "is_sales_item"],
 
 	get_indicator: function(doc) {
-		if(doc.end_of_life && doc.end_of_life < frappe.datetime.get_today()) {
-			return [__("Expired"), "grey", "end_of_life,<,Today"]
-		} else if(doc.has_variants) {
-			return [__("Template"), "blue", "has_variants,=,Yes"]
-		} else if(doc.variant_of) {
-			return [__("Variant"), "green", "variant_of,=," + doc.variant_of]
+		if (doc.disabled) {
+			return [__("Disabled"), "grey", "disabled,=,Yes"];
+		} else if (doc.end_of_life && doc.end_of_life < frappe.datetime.get_today()) {
+			return [__("Expired"), "grey", "end_of_life,<,Today"];
+		} else if (doc.has_variants) {
+			return [__("Template"), "blue", "has_variants,=,Yes"];
+		} else if (doc.variant_of) {
+			return [__("Variant"), "green", "variant_of,=," + doc.variant_of];
 		} else {
-			return [__("Active"), "blue", "end_of_life,>=,Today"]
+			return [__("Active"), "blue", "end_of_life,>=,Today"];
 		}
 	}
 };
diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py
index 868053e..79cd8de 100644
--- a/erpnext/stock/doctype/stock_entry/stock_entry.py
+++ b/erpnext/stock/doctype/stock_entry/stock_entry.py
@@ -5,7 +5,7 @@
 import frappe
 import frappe.defaults
 from frappe import _
-from frappe.utils import cstr, cint, flt, comma_or, getdate
+from frappe.utils import cstr, cint, flt, comma_or, getdate, nowdate
 from erpnext.stock.utils import get_incoming_rate
 from erpnext.stock.stock_ledger import get_previous_sle, NegativeStockError
 from erpnext.stock.get_item_details import get_available_qty, get_default_cost_center, get_conversion_factor
@@ -359,7 +359,7 @@
 
 	def update_stock_ledger(self):
 		sl_entries = []
-		
+
 		# make sl entries for source warehouse first, then do for target warehouse
 		for d in self.get('items'):
 			if cstr(d.s_warehouse):
@@ -368,7 +368,7 @@
 					"actual_qty": -flt(d.transfer_qty),
 					"incoming_rate": 0
 				}))
-				
+
 		for d in self.get('items'):
 			if cstr(d.t_warehouse):
 				sl_entries.append(self.get_sl_entries(d, {
@@ -438,8 +438,10 @@
 	def get_item_details(self, args=None, for_update=False):
 		item = frappe.db.sql("""select stock_uom, description, image, item_name,
 			expense_account, buying_cost_center, item_group from `tabItem`
-			where name = %s and (ifnull(end_of_life,'0000-00-00')='0000-00-00' or end_of_life > now())""",
-			(args.get('item_code')), as_dict = 1)
+			where name = %s
+				and disabled=0
+				and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %s)""",
+			(args.get('item_code'), nowdate()), as_dict = 1)
 		if not item:
 			frappe.throw(_("Item {0} is not active or end of life has been reached").format(args.get("item_code")))
 
diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
index a275de5..cff0041 100644
--- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
+++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
@@ -130,7 +130,7 @@
 			item = frappe.get_doc("Item", item_code)
 
 			# end of life and stock item
-			validate_end_of_life(item_code, item.end_of_life, verbose=0)
+			validate_end_of_life(item_code, item.end_of_life, item.disabled, verbose=0)
 			validate_is_stock_item(item_code, item.is_stock_item, verbose=0)
 
 			# item should not be serialized
diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py
index 3fa3ea9..1f0b637 100644
--- a/erpnext/stock/get_item_details.py
+++ b/erpnext/stock/get_item_details.py
@@ -113,7 +113,7 @@
 		throw(_("Please specify Company"))
 
 	from erpnext.stock.doctype.item.item import validate_end_of_life
-	validate_end_of_life(item.name, item.end_of_life)
+	validate_end_of_life(item.name, item.end_of_life, item.disabled)
 
 	if args.transaction_type == "selling":
 		# validate if sales item or service item
diff --git a/erpnext/stock/reorder_item.py b/erpnext/stock/reorder_item.py
index d4b0a20..bf06396 100644
--- a/erpnext/stock/reorder_item.py
+++ b/erpnext/stock/reorder_item.py
@@ -23,6 +23,7 @@
 	items_to_consider = frappe.db.sql_list("""select name from `tabItem` item
 		where is_stock_item=1 and has_variants=0
 			and (is_purchase_item=1 or is_sub_contracted_item=1)
+			and disabled=0
 			and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
 			and ((re_order_level is not null and re_order_level > 0)
 				or exists (select name from `tabItem Reorder` ir where ir.parent=item.name)
diff --git a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
index 51e3836..7d3a2ee 100644
--- a/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
+++ b/erpnext/stock/report/stock_projected_qty/stock_projected_qty.py
@@ -79,6 +79,7 @@
 
 	items = frappe.db.sql("""select * from `tabItem` item
 		where is_stock_item = 1
+		and disabled=0
 		{condition}
 		and (end_of_life > %(today)s or end_of_life is null or end_of_life='0000-00-00')
 		and exists (select name from `tabBin` bin where bin.item_code=item.name)"""\
diff --git a/erpnext/templates/generators/item.html b/erpnext/templates/generators/item.html
index acbcedf..500a118 100644
--- a/erpnext/templates/generators/item.html
+++ b/erpnext/templates/generators/item.html
@@ -24,7 +24,7 @@
 				{{ web_long_description or description or _("No description given") }}
 				</div>
 				<p class="text-muted">
-					{{ _("Item Code") }}: <span itemprop="productID">{{ name }}</span></p>
+					{{ _("Item Code") }}: <span itemprop="productID">{{ variant and variant.name or name }}</span></p>
 				<br>
 				<div class="item-attribute-selectors">
                     {% if has_variants %}
diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py
index 897a199..dc2099d 100644
--- a/erpnext/templates/pages/product_search.py
+++ b/erpnext/templates/pages/product_search.py
@@ -3,7 +3,7 @@
 
 from __future__ import unicode_literals
 import frappe
-from frappe.utils import cstr
+from frappe.utils import cstr, nowdate
 from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
 
 no_cache = 1
@@ -14,7 +14,11 @@
 	# base query
 	query = """select name, item_name, page_name, website_image, thumbnail, item_group,
 			web_long_description as website_description, parent_website_route
-		from `tabItem` where show_in_website = 1 and (variant_of is null or variant_of = '')"""
+		from `tabItem`
+		where show_in_website = 1
+			and disabled=0
+			and (end_of_life is null or end_of_life='0000-00-00' or end_of_life > %(today)s)
+			and (variant_of is null or variant_of = '')"""
 
 	# search term condition
 	if search:
@@ -29,6 +33,7 @@
 
 	data = frappe.db.sql(query, {
 		"search": search,
+		"today": nowdate()
 	}, as_dict=1)
 
 	for d in data:
diff --git a/setup.py b/setup.py
index 888e3de..77cd04f 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = "6.6.6"
+version = "6.6.7"
 
 with open("requirements.txt", "r") as f:
 	install_requires = f.readlines()