fix: allow to select parent warehouse in the website item (#37047)

This commit is contained in:
rohitwaghchaure
2023-09-20 17:27:35 +05:30
committed by GitHub
parent bf01f3227f
commit e6199dc802
10 changed files with 75 additions and 44 deletions

View File

@@ -6,6 +6,7 @@ from frappe.utils import cint, flt, fmt_money, getdate, nowdate
from erpnext.accounts.doctype.pricing_rule.pricing_rule import get_pricing_rule_for_item
from erpnext.stock.doctype.batch.batch import get_batch_qty
from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses
def get_web_item_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
@@ -22,23 +23,31 @@ def get_web_item_qty_in_stock(item_code, item_warehouse_field, warehouse=None):
"Website Item", {"item_code": template_item_code}, item_warehouse_field
)
if warehouse:
stock_qty = frappe.db.sql(
"""
select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
from tabBin S
inner join `tabItem` I on S.item_code = I.Item_code
left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
where S.item_code=%s and S.warehouse=%s""",
(item_code, warehouse),
)
if warehouse and frappe.get_cached_value("Warehouse", warehouse, "is_group") == 1:
warehouses = get_child_warehouses(warehouse)
else:
warehouses = [warehouse] if warehouse else []
if stock_qty:
stock_qty = adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
in_stock = stock_qty[0][0] > 0 and 1 or 0
total_stock = 0.0
if warehouses:
for warehouse in warehouses:
stock_qty = frappe.db.sql(
"""
select GREATEST(S.actual_qty - S.reserved_qty - S.reserved_qty_for_production - S.reserved_qty_for_sub_contract, 0) / IFNULL(C.conversion_factor, 1)
from tabBin S
inner join `tabItem` I on S.item_code = I.Item_code
left join `tabUOM Conversion Detail` C on I.sales_uom = C.uom and C.parent = I.Item_code
where S.item_code=%s and S.warehouse=%s""",
(item_code, warehouse),
)
if stock_qty:
total_stock += adjust_qty_for_expired_items(item_code, stock_qty, warehouse)
in_stock = total_stock > 0 and 1 or 0
return frappe._dict(
{"in_stock": in_stock, "stock_qty": stock_qty, "is_stock_item": is_stock_item}
{"in_stock": in_stock, "stock_qty": total_stock, "is_stock_item": is_stock_item}
)
@@ -56,7 +65,7 @@ def adjust_qty_for_expired_items(item_code, stock_qty, warehouse):
if not stock_qty[0][0]:
break
return stock_qty
return stock_qty[0][0] if stock_qty else 0
def get_expired_batches(batches):