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
|
|
|
|
|
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def get_product_list(args=None):
|
|
|
|
"""
|
|
|
|
args = {
|
|
|
|
'limit_start': 0,
|
|
|
|
'limit_page_length': 20,
|
|
|
|
'search': '',
|
|
|
|
'product_group': '',
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
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
|
|
|
|
|
|
|
|
# base query
|
|
|
|
query = """\
|
|
|
|
select name, item_name, page_name, website_image,
|
|
|
|
description, web_short_description
|
|
|
|
from `tabItem`
|
|
|
|
where is_sales_item = 'Yes'
|
|
|
|
and docstatus = 0
|
|
|
|
and show_in_website = 1"""
|
|
|
|
|
|
|
|
# search term condition
|
|
|
|
if args.get('search'):
|
|
|
|
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 += """
|
|
|
|
and item_group = %(product_group)s"""
|
|
|
|
|
|
|
|
# order by
|
|
|
|
query += """
|
|
|
|
order by item_name asc, name asc"""
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
from webnotes.widgets.query_builder import add_limit_to_query
|
|
|
|
query, args = add_limit_to_query(query, args)
|
|
|
|
|
|
|
|
return webnotes.conn.sql(query, args, as_dict=1)
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
@webnotes.whitelist(allow_guest=True)
|
2012-07-11 13:10:57 +00:00
|
|
|
def get_product_category_list(args=None):
|
|
|
|
"""
|
|
|
|
args = {
|
|
|
|
'limit_start': 0,
|
|
|
|
'limit_page_length': 5,
|
|
|
|
}
|
|
|
|
"""
|
2012-07-09 10:26:12 +00:00
|
|
|
import webnotes
|
|
|
|
|
2012-07-11 13:10:57 +00:00
|
|
|
if not args: args = webnotes.form_dict
|
|
|
|
|
|
|
|
query = """\
|
2012-07-09 10:26:12 +00:00
|
|
|
select count(name) as items, item_group
|
|
|
|
from `tabItem`
|
|
|
|
where is_sales_item = 'Yes'
|
|
|
|
and docstatus = 0
|
|
|
|
and show_in_website = 1
|
|
|
|
group by item_group
|
2012-07-11 13:10:57 +00:00
|
|
|
order by items desc"""
|
|
|
|
|
|
|
|
from webnotes.widgets.query_builder import add_limit_to_query
|
|
|
|
query, args = add_limit_to_query(query, args)
|
|
|
|
|
|
|
|
|
|
|
|
result = webnotes.conn.sql(query, args, as_dict=1)
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
# add All Products link
|
|
|
|
total_count = sum((r.get('items') or 0 for r in result))
|
|
|
|
result = [{'items': total_count, 'item_group': 'All Products'}] + (result or [])
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
@webnotes.whitelist(allow_guest=True)
|
|
|
|
def get_similar_product_list(args=None):
|
2012-07-11 13:10:57 +00:00
|
|
|
"""
|
|
|
|
args = {
|
|
|
|
'limit_start': 0,
|
|
|
|
'limit_page_length': 5,
|
|
|
|
'product_name': '',
|
|
|
|
'product_group': '',
|
|
|
|
}
|
|
|
|
"""
|
2012-07-09 10:26:12 +00:00
|
|
|
import webnotes
|
|
|
|
|
|
|
|
if not args: args = webnotes.form_dict
|
2012-07-11 13:10:57 +00:00
|
|
|
|
|
|
|
query = """\
|
2012-07-09 10:26:12 +00:00
|
|
|
select name, item_name, page_name, website_image,
|
|
|
|
description, web_short_description
|
|
|
|
from `tabItem`
|
|
|
|
where is_sales_item = 'Yes'
|
|
|
|
and docstatus = 0
|
|
|
|
and show_in_website = 1
|
|
|
|
and name != %(product_name)s
|
|
|
|
and item_group = %(product_group)s
|
2012-07-11 13:10:57 +00:00
|
|
|
order by item_name"""
|
|
|
|
|
|
|
|
from webnotes.widgets.query_builder import add_limit_to_query
|
|
|
|
query, args = add_limit_to_query(query, args)
|
|
|
|
|
|
|
|
result = webnotes.conn.sql(query, args, as_dict=1)
|
2012-07-09 10:26:12 +00:00
|
|
|
|
|
|
|
return result
|