Rushabh Mehta | 621283c | 2016-04-21 19:00:34 +0530 | [diff] [blame] | 1 | from __future__ import unicode_literals |
| 2 | |
| 3 | import frappe |
| 4 | |
| 5 | @frappe.whitelist() |
Rushabh Mehta | 057db06 | 2016-11-08 12:40:04 +0530 | [diff] [blame] | 6 | def get_data(item_code=None, warehouse=None, item_group=None, |
| 7 | start=0, sort_by='actual_qty', sort_order='desc'): |
| 8 | '''Return data to render the item dashboard''' |
| 9 | conditions = [] |
| 10 | values = [] |
Rushabh Mehta | 621283c | 2016-04-21 19:00:34 +0530 | [diff] [blame] | 11 | if item_code: |
Rushabh Mehta | 057db06 | 2016-11-08 12:40:04 +0530 | [diff] [blame] | 12 | conditions.append('b.item_code=%s') |
| 13 | values.append(item_code) |
Rushabh Mehta | 621283c | 2016-04-21 19:00:34 +0530 | [diff] [blame] | 14 | if warehouse: |
Rushabh Mehta | 057db06 | 2016-11-08 12:40:04 +0530 | [diff] [blame] | 15 | conditions.append('b.warehouse=%s') |
| 16 | values.append(warehouse) |
| 17 | if item_group: |
| 18 | conditions.append('i.item_group=%s') |
| 19 | values.append(item_group) |
| 20 | |
| 21 | if conditions: |
| 22 | conditions = ' and ' + ' and '.join(conditions) |
| 23 | else: |
| 24 | conditions = '' |
| 25 | |
| 26 | return frappe.db.sql(''' |
| 27 | select |
| 28 | b.item_code, b.warehouse, b.projected_qty, b.reserved_qty, |
| 29 | b.reserved_qty_for_production, b.actual_qty, b.valuation_rate, i.item_name |
| 30 | from |
| 31 | tabBin b, tabItem i |
| 32 | where |
| 33 | b.item_code = i.name |
| 34 | {conditions} |
| 35 | order by |
| 36 | {sort_by} {sort_order} |
| 37 | limit |
| 38 | {start}, 21 |
| 39 | '''.format(conditions=conditions, sort_by=sort_by, sort_order=sort_order, |
| 40 | start=start), values, as_dict=True) |