Merge pull request #4249 from nabinhait/cc_fix

[fix] Default cost center as per company
diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py
index 9736701..bc2d48f 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,15 @@
 			concat(parent_website_route, "/", page_name) as route
 		from `tabItem`
 		where show_in_website = 1
+			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/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py
index c621957..db7b50a 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])
 
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..9a6e8d3 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,10 @@
 	# 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 (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 +32,7 @@
 
 	data = frappe.db.sql(query, {
 		"search": search,
+		"today": nowdate()
 	}, as_dict=1)
 
 	for d in data: