brotherton-erpnext/erpnext/templates/pages/product_search.py

45 lines
1.4 KiB
Python
Raw Normal View History

# 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, nowdate, cint
2014-06-18 12:03:01 +00:00
from erpnext.setup.doctype.item_group.item_group import get_item_for_list_in_html
no_cache = 1
no_sitemap = 1
2016-06-27 09:24:46 +00:00
def get_context(context):
context.show_search = True
@frappe.whitelist(allow_guest=True)
def get_product_list(search=None, start=0, limit=12):
# limit = 12 because we show 12 items in the grid view
# base query
2016-06-23 12:55:50 +00:00
query = """select name, item_name, item_code, route, website_image, thumbnail, item_group,
description, web_long_description as website_description
from `tabItem`
where (show_in_website = 1 or show_variant_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)"""
# search term condition
if search:
2014-08-25 13:08:08 +00:00
query += """ and (web_long_description like %(search)s
2014-08-20 06:13:18 +00:00
or description like %(search)s
or item_name like %(search)s
or name like %(search)s)"""
search = "%" + cstr(search) + "%"
# order by
query += """ order by weightage desc, idx desc, modified desc limit %s, %s""" % (cint(start), cint(limit))
data = frappe.db.sql(query, {
"search": search,
"today": nowdate()
}, as_dict=1)
return [get_item_for_list_in_html(r) for r in data]