refactor: rewrite Item Shortage Report
queries in QB
This commit is contained in:
parent
377576f131
commit
f0a78aa559
@ -8,8 +8,7 @@ from frappe import _
|
|||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
conditions = get_conditions(filters)
|
data = get_data(filters)
|
||||||
data = get_data(conditions, filters)
|
|
||||||
|
|
||||||
if not data:
|
if not data:
|
||||||
return [], [], None, []
|
return [], [], None, []
|
||||||
@ -19,21 +18,16 @@ def execute(filters=None):
|
|||||||
return columns, data, None, chart_data
|
return columns, data, None, chart_data
|
||||||
|
|
||||||
|
|
||||||
def get_conditions(filters):
|
def get_data(filters):
|
||||||
conditions = ""
|
bin = frappe.qb.DocType("Bin")
|
||||||
|
wh = frappe.qb.DocType("Warehouse")
|
||||||
|
item = frappe.qb.DocType("Item")
|
||||||
|
|
||||||
if filters.get("warehouse"):
|
query = (
|
||||||
conditions += "AND warehouse in %(warehouse)s"
|
frappe.qb.from_(bin)
|
||||||
if filters.get("company"):
|
.from_(wh)
|
||||||
conditions += "AND company = %(company)s"
|
.from_(item)
|
||||||
|
.select(
|
||||||
return conditions
|
|
||||||
|
|
||||||
|
|
||||||
def get_data(conditions, filters):
|
|
||||||
data = frappe.db.sql(
|
|
||||||
"""
|
|
||||||
SELECT
|
|
||||||
bin.warehouse,
|
bin.warehouse,
|
||||||
bin.item_code,
|
bin.item_code,
|
||||||
bin.actual_qty,
|
bin.actual_qty,
|
||||||
@ -42,26 +36,21 @@ def get_data(conditions, filters):
|
|||||||
bin.reserved_qty,
|
bin.reserved_qty,
|
||||||
bin.reserved_qty_for_production,
|
bin.reserved_qty_for_production,
|
||||||
bin.projected_qty,
|
bin.projected_qty,
|
||||||
warehouse.company,
|
wh.company,
|
||||||
item.item_name,
|
item.item_name,
|
||||||
item.description
|
item.description,
|
||||||
FROM
|
)
|
||||||
`tabBin` bin,
|
.where((bin.projected_qty < 0) & (wh.name == bin.warehouse) & (bin.item_code == item.name))
|
||||||
`tabWarehouse` warehouse,
|
.orderby(bin.projected_qty)
|
||||||
`tabItem` item
|
|
||||||
WHERE
|
|
||||||
bin.projected_qty<0
|
|
||||||
AND warehouse.name = bin.warehouse
|
|
||||||
AND bin.item_code=item.name
|
|
||||||
{0}
|
|
||||||
ORDER BY bin.projected_qty;""".format(
|
|
||||||
conditions
|
|
||||||
),
|
|
||||||
filters,
|
|
||||||
as_dict=1,
|
|
||||||
)
|
)
|
||||||
|
|
||||||
return data
|
if filters.get("warehouse"):
|
||||||
|
query = query.where(bin.warehouse.isin(filters.get("warehouse")))
|
||||||
|
|
||||||
|
if filters.get("company"):
|
||||||
|
query = query.where(wh.company == filters.get("company"))
|
||||||
|
|
||||||
|
return query.run(as_dict=True)
|
||||||
|
|
||||||
|
|
||||||
def get_chart_data(data):
|
def get_chart_data(data):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user