mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
refactor adjust_for_expired_items and others as per code review
use get_all instead of get_list rename `adjust_for_expired_items` to `adjust_qty_for_expired_items`
This commit is contained in:
@@ -106,12 +106,12 @@ def get_product_list_for_group(product_group=None, start=0, limit=10, search=Non
|
|||||||
|
|
||||||
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
|
data = frappe.db.sql(query, {"product_group": product_group,"search": search, "today": nowdate()}, as_dict=1)
|
||||||
|
|
||||||
data = adjust_for_expired_items(data)
|
data = adjust_qty_for_expired_items(data)
|
||||||
|
|
||||||
return [get_item_for_list_in_html(r) for r in data]
|
return [get_item_for_list_in_html(r) for r in data]
|
||||||
|
|
||||||
|
|
||||||
def adjust_for_expired_items(data):
|
def adjust_qty_for_expired_items(data):
|
||||||
adjusted_data = []
|
adjusted_data = []
|
||||||
|
|
||||||
for item in data:
|
for item in data:
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ def get_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
|
|||||||
item_code=%s and warehouse=%s""", (item_code, warehouse))
|
item_code=%s and warehouse=%s""", (item_code, warehouse))
|
||||||
|
|
||||||
if stock_qty[0][0]:
|
if stock_qty[0][0]:
|
||||||
stock_qty = adjust_for_expired_items(item_code, stock_qty, warehouse)
|
stock_qty = adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
|
||||||
|
|
||||||
if stock_qty[0][0]:
|
if stock_qty[0][0]:
|
||||||
in_stock = stock_qty[0][0] > 0 and 1 or 0
|
in_stock = stock_qty[0][0] > 0 and 1 or 0
|
||||||
@@ -34,20 +34,20 @@ def get_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
|
|||||||
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item})
|
return frappe._dict({"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item})
|
||||||
|
|
||||||
|
|
||||||
def adjust_for_expired_items(item_code, stock_qty, warehouse):
|
def adjust_qty_for_expired_items(item_code, stock_qty, warehouse):
|
||||||
batches = frappe.get_list('Batch', filters=[{'item': item_code}], fields=['expiry_date', 'name'])
|
batches = frappe.get_all('Batch', filters=[{'item': item_code}], fields=['expiry_date', 'name'])
|
||||||
expired_batches = get_expired_batches(batches)
|
expired_batches = get_expired_batches(batches)
|
||||||
stock_qty = [list(item) for item in stock_qty]
|
stock_qty = [list(item) for item in stock_qty]
|
||||||
|
|
||||||
if expired_batches:
|
for batch in expired_batches:
|
||||||
for batch in expired_batches:
|
if warehouse:
|
||||||
if warehouse:
|
stock_qty[0][0] = max(0, stock_qty[0][0] - get_batch_qty(batch, warehouse))
|
||||||
stock_qty[0][0] = max(0, stock_qty[0][0] - get_batch_qty(batch, warehouse))
|
else:
|
||||||
else:
|
stock_qty[0][0] = max(0, stock_qty[0][0] - qty_from_all_warehouses(get_batch_qty(batch)))
|
||||||
stock_qty[0][0] = max(0, stock_qty[0][0] - qty_from_all_warehouses(get_batch_qty(batch)))
|
|
||||||
|
if not stock_qty[0][0]:
|
||||||
|
break
|
||||||
|
|
||||||
if not stock_qty[0][0]:
|
|
||||||
break
|
|
||||||
return stock_qty
|
return stock_qty
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user