2012-12-07 07:14:45 +00:00
|
|
|
# Copyright (c) 2012 Web Notes Technologies Pvt Ltd.
|
|
|
|
# License: GNU General Public License (v3). For more information see license.txt
|
|
|
|
|
2012-07-19 08:10:31 +00:00
|
|
|
from __future__ import unicode_literals
|
2012-07-09 10:26:12 +00:00
|
|
|
import webnotes
|
|
|
|
|
2012-12-18 06:17:13 +00:00
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def get_product_info(item_code):
|
|
|
|
"""get product price / stock info"""
|
|
|
|
price_list = webnotes.conn.get_value("Item", item_code, "website_price_list")
|
|
|
|
warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse")
|
|
|
|
if warehouse:
|
|
|
|
in_stock = webnotes.conn.sql("""select actual_qty from tabBin where
|
|
|
|
item_code=%s and warehouse=%s""", (item_code, warehouse))
|
|
|
|
if in_stock:
|
|
|
|
in_stock = in_stock[0][0] > 0 and 1 or 0
|
|
|
|
else:
|
|
|
|
in_stock = -1
|
|
|
|
return {
|
|
|
|
"price": price_list and webnotes.conn.sql("""select ref_rate, ref_currency from
|
|
|
|
`tabItem Price` where parent=%s and price_list_name=%s""",
|
|
|
|
(item_code, price_list), as_dict=1) or [],
|
|
|
|
"stock": in_stock
|
|
|
|
}
|
|
|
|
|
2012-07-09 10:26:12 +00:00
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def get_product_list(args=None):
|
|
|
|
import webnotes
|
2012-11-30 11:08:04 +00:00
|
|
|
from webnotes.utils import cstr
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
if not args: args = webnotes.form_dict
|
2012-12-19 04:44:59 +00:00
|
|
|
if not args.search: args.search = ""
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
# base query
|
|
|
|
query = """\
|
2012-12-18 09:17:54 +00:00
|
|
|
select name, item_name, page_name, website_image, item_group,
|
|
|
|
if(ifnull(web_short_description,'')='', web_long_description,
|
|
|
|
web_short_description) as web_short_description
|
2012-07-09 10:26:12 +00:00
|
|
|
from `tabItem`
|
2012-12-18 09:17:54 +00:00
|
|
|
where docstatus = 0
|
2012-12-19 04:44:59 +00:00
|
|
|
and show_in_website = 1 """
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
# search term condition
|
2012-12-19 04:44:59 +00:00
|
|
|
if args.search:
|
2012-07-09 10:26:12 +00:00
|
|
|
query += """
|
|
|
|
and (
|
|
|
|
web_short_description like %(search)s or
|
|
|
|
web_long_description like %(search)s or
|
|
|
|
description like %(search)s or
|
|
|
|
item_name like %(search)s or
|
|
|
|
name like %(search)s
|
|
|
|
)"""
|
2012-07-11 13:10:57 +00:00
|
|
|
args['search'] = "%" + cstr(args.get('search')) + "%"
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
# product group condition
|
|
|
|
if args.get('product_group') and args.get('product_group') != 'All Products':
|
|
|
|
query += """
|
2012-12-19 04:44:59 +00:00
|
|
|
and item_group = %(product_group)s """
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
# order by
|
2012-12-18 09:17:54 +00:00
|
|
|
query += """order by item_name asc, name asc limit %s, 10""" % args.start
|
2012-07-11 13:10:57 +00:00
|
|
|
|
2012-12-18 09:17:54 +00:00
|
|
|
return webnotes.conn.sql(query, args, as_dict=1)
|