From 6d69ca6bac94e2fa97d6cbd3d42dae11584fba5c Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Thu, 29 Oct 2015 11:35:16 +0530 Subject: [PATCH] [fix] don't show expired items in website item list. Fixes #4210. --- erpnext/setup/doctype/item_group/item_group.py | 10 ++++++---- erpnext/stock/doctype/item/item.py | 2 +- erpnext/templates/generators/item.html | 2 +- erpnext/templates/pages/product_search.py | 8 ++++++-- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/erpnext/setup/doctype/item_group/item_group.py b/erpnext/setup/doctype/item_group/item_group.py index 97367013d7..bc2d48f4b2 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 @@ def get_product_list_for_group(product_group=None, start=0, limit=10): 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 c62195767b..db7b50ae9c 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -245,7 +245,7 @@ class Item(WebsiteGenerator): # 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 acbcedfd82..500a11853e 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") }}

- {{ _("Item Code") }}: {{ name }}

+ {{ _("Item Code") }}: {{ variant and variant.name or name }}


{% if has_variants %} diff --git a/erpnext/templates/pages/product_search.py b/erpnext/templates/pages/product_search.py index 897a199ec9..9a6e8d3117 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 @@ def get_product_list(search=None, start=0, limit=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 @@ def get_product_list(search=None, start=0, limit=10): data = frappe.db.sql(query, { "search": search, + "today": nowdate() }, as_dict=1) for d in data: