Rushabh Mehta | a494b88 | 2012-12-07 12:44:45 +0530 | [diff] [blame] | 1 | # Copyright (c) 2012 Web Notes Technologies Pvt Ltd. |
| 2 | # License: GNU General Public License (v3). For more information see license.txt |
| 3 | |
Anand Doshi | 486f9df | 2012-07-19 13:40:31 +0530 | [diff] [blame] | 4 | from __future__ import unicode_literals |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 5 | import webnotes |
| 6 | |
| 7 | @webnotes.whitelist(allow_guest=True) |
Rushabh Mehta | ee472b0 | 2012-12-18 11:47:13 +0530 | [diff] [blame] | 8 | def get_product_info(item_code): |
| 9 | """get product price / stock info""" |
| 10 | price_list = webnotes.conn.get_value("Item", item_code, "website_price_list") |
| 11 | warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse") |
| 12 | if warehouse: |
| 13 | in_stock = webnotes.conn.sql("""select actual_qty from tabBin where |
| 14 | item_code=%s and warehouse=%s""", (item_code, warehouse)) |
| 15 | if in_stock: |
| 16 | in_stock = in_stock[0][0] > 0 and 1 or 0 |
| 17 | else: |
| 18 | in_stock = -1 |
| 19 | return { |
| 20 | "price": price_list and webnotes.conn.sql("""select ref_rate, ref_currency from |
| 21 | `tabItem Price` where parent=%s and price_list_name=%s""", |
| 22 | (item_code, price_list), as_dict=1) or [], |
| 23 | "stock": in_stock |
| 24 | } |
| 25 | |
| 26 | @webnotes.whitelist(allow_guest=True) |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 27 | def get_product_list(args=None): |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 28 | import webnotes |
Anand Doshi | 0fd99e7 | 2012-11-30 16:38:04 +0530 | [diff] [blame] | 29 | from webnotes.utils import cstr |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 30 | |
| 31 | if not args: args = webnotes.form_dict |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 32 | if not args.search: args.search = "" |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 33 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 34 | # base query |
| 35 | query = """\ |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 36 | select name, item_name, page_name, website_image, item_group, |
| 37 | if(ifnull(web_short_description,'')='', web_long_description, |
| 38 | web_short_description) as web_short_description |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 39 | from `tabItem` |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 40 | where docstatus = 0 |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 41 | and show_in_website = 1 """ |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 42 | |
| 43 | # search term condition |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 44 | if args.search: |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 45 | query += """ |
| 46 | and ( |
| 47 | web_short_description like %(search)s or |
| 48 | web_long_description like %(search)s or |
| 49 | description like %(search)s or |
| 50 | item_name like %(search)s or |
| 51 | name like %(search)s |
| 52 | )""" |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 53 | args['search'] = "%" + cstr(args.get('search')) + "%" |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 54 | |
| 55 | # product group condition |
| 56 | if args.get('product_group') and args.get('product_group') != 'All Products': |
| 57 | query += """ |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 58 | and item_group = %(product_group)s """ |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 59 | |
| 60 | # order by |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 61 | query += """order by item_name asc, name asc limit %s, 10""" % args.start |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 62 | |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 63 | return webnotes.conn.sql(query, args, as_dict=1) |