2016-04-21 13:30:34 +00:00
|
|
|
from __future__ import unicode_literals
|
|
|
|
|
|
|
|
import frappe
|
|
|
|
|
|
|
|
@frappe.whitelist()
|
2016-11-08 07:10:04 +00:00
|
|
|
def get_data(item_code=None, warehouse=None, item_group=None,
|
|
|
|
start=0, sort_by='actual_qty', sort_order='desc'):
|
|
|
|
'''Return data to render the item dashboard'''
|
|
|
|
conditions = []
|
|
|
|
values = []
|
2016-04-21 13:30:34 +00:00
|
|
|
if item_code:
|
2016-11-08 07:10:04 +00:00
|
|
|
conditions.append('b.item_code=%s')
|
|
|
|
values.append(item_code)
|
2016-04-21 13:30:34 +00:00
|
|
|
if warehouse:
|
2016-11-08 07:10:04 +00:00
|
|
|
conditions.append('b.warehouse=%s')
|
|
|
|
values.append(warehouse)
|
|
|
|
if item_group:
|
|
|
|
conditions.append('i.item_group=%s')
|
|
|
|
values.append(item_group)
|
|
|
|
|
|
|
|
if conditions:
|
|
|
|
conditions = ' and ' + ' and '.join(conditions)
|
|
|
|
else:
|
|
|
|
conditions = ''
|
|
|
|
|
|
|
|
return frappe.db.sql('''
|
|
|
|
select
|
|
|
|
b.item_code, b.warehouse, b.projected_qty, b.reserved_qty,
|
2018-03-12 08:42:12 +00:00
|
|
|
b.reserved_qty_for_production, b.reserved_qty_for_sub_contract, b.actual_qty, b.valuation_rate, i.item_name
|
2016-11-08 07:10:04 +00:00
|
|
|
from
|
|
|
|
tabBin b, tabItem i
|
|
|
|
where
|
|
|
|
b.item_code = i.name
|
2017-06-14 10:07:47 +00:00
|
|
|
and
|
2018-03-12 08:42:12 +00:00
|
|
|
(b.projected_qty != 0 or b.reserved_qty != 0 or b.reserved_qty_for_production != 0
|
|
|
|
or b.reserved_qty_for_sub_contract != 0 or b.actual_qty != 0)
|
2016-11-08 07:10:04 +00:00
|
|
|
{conditions}
|
|
|
|
order by
|
|
|
|
{sort_by} {sort_order}
|
|
|
|
limit
|
|
|
|
{start}, 21
|
|
|
|
'''.format(conditions=conditions, sort_by=sort_by, sort_order=sort_order,
|
|
|
|
start=start), values, as_dict=True)
|