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 | |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 7 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 8 | @webnotes.whitelist(allow_guest=True) |
Rushabh Mehta | ee472b0 | 2012-12-18 11:47:13 +0530 | [diff] [blame] | 9 | def get_product_info(item_code): |
| 10 | """get product price / stock info""" |
| 11 | price_list = webnotes.conn.get_value("Item", item_code, "website_price_list") |
| 12 | warehouse = webnotes.conn.get_value("Item", item_code, "website_warehouse") |
| 13 | if warehouse: |
| 14 | in_stock = webnotes.conn.sql("""select actual_qty from tabBin where |
| 15 | item_code=%s and warehouse=%s""", (item_code, warehouse)) |
| 16 | if in_stock: |
| 17 | in_stock = in_stock[0][0] > 0 and 1 or 0 |
| 18 | else: |
| 19 | in_stock = -1 |
| 20 | return { |
| 21 | "price": price_list and webnotes.conn.sql("""select ref_rate, ref_currency from |
| 22 | `tabItem Price` where parent=%s and price_list_name=%s""", |
| 23 | (item_code, price_list), as_dict=1) or [], |
| 24 | "stock": in_stock |
| 25 | } |
| 26 | |
| 27 | @webnotes.whitelist(allow_guest=True) |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 28 | def get_product_list(search=None, product_group=None, start=0): |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 29 | import webnotes |
Anand Doshi | 0fd99e7 | 2012-11-30 16:38:04 +0530 | [diff] [blame] | 30 | from webnotes.utils import cstr |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 31 | |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 32 | # base query |
| 33 | query = """\ |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 34 | select name, item_name, page_name, website_image, item_group, |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 35 | web_long_description as website_description |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 36 | from `tabItem` |
Rushabh Mehta | 647e0d1 | 2012-12-18 14:47:54 +0530 | [diff] [blame] | 37 | where docstatus = 0 |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 38 | and show_in_website = 1 """ |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 39 | |
| 40 | # search term condition |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 41 | if search: |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 42 | query += """ |
| 43 | and ( |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 44 | web_long_description like %(search)s or |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 45 | item_name like %(search)s or |
| 46 | name like %(search)s |
| 47 | )""" |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 48 | search = "%" + cstr(search) + "%" |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 49 | |
| 50 | # product group condition |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 51 | if product_group: |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 52 | query += """ |
Rushabh Mehta | e109fa4 | 2012-12-19 10:14:59 +0530 | [diff] [blame] | 53 | and item_group = %(product_group)s """ |
Anand Doshi | e47def8 | 2012-07-09 15:56:12 +0530 | [diff] [blame] | 54 | |
| 55 | # order by |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 56 | query += """order by item_name asc, name asc limit %s, 10""" % start |
Anand Doshi | 8c7e76b | 2012-07-11 18:40:57 +0530 | [diff] [blame] | 57 | |
Rushabh Mehta | fc19f25 | 2012-12-20 17:11:51 +0530 | [diff] [blame] | 58 | return webnotes.conn.sql(query, { |
| 59 | "search": search, |
| 60 | "product_group": product_group |
| 61 | }, as_dict=1) |