blob: 0d75a9a544ff386cdcf75657bb04bd804baca517 [file] [log] [blame]
Rushabh Mehta621283c2016-04-21 19:00:34 +05301from __future__ import unicode_literals
2
3import frappe
4
5@frappe.whitelist()
Rushabh Mehta057db062016-11-08 12:40:04 +05306def 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 Mehta621283c2016-04-21 19:00:34 +053011 if item_code:
Rushabh Mehta057db062016-11-08 12:40:04 +053012 conditions.append('b.item_code=%s')
13 values.append(item_code)
Rushabh Mehta621283c2016-04-21 19:00:34 +053014 if warehouse:
Rushabh Mehta057db062016-11-08 12:40:04 +053015 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
KanchanChauhanc849f642017-06-14 15:37:47 +053034 and
35 (b.projected_qty != 0 or b.reserved_qty != 0 or b.reserved_qty_for_production != 0 or b.actual_qty != 0)
Rushabh Mehta057db062016-11-08 12:40:04 +053036 {conditions}
37 order by
38 {sort_by} {sort_order}
39 limit
40 {start}, 21
41 '''.format(conditions=conditions, sort_by=sort_by, sort_order=sort_order,
42 start=start), values, as_dict=True)