Skip to content

Commit

Permalink
Merge pull request #40848 from rohitwaghchaure/fixed-12763
Browse files Browse the repository at this point in the history
fix: group warehouse added in the stock reconciliation
  • Loading branch information
rohitwaghchaure committed Apr 4, 2024
2 parents ea1b669 + 8f53bc0 commit 1816f1d
Showing 1 changed file with 20 additions and 4 deletions.
24 changes: 20 additions & 4 deletions erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,9 @@ def get_batch_qty_for_stock_reco(item_code, warehouse, batch_no, posting_date, p
@frappe.whitelist()
def get_items(warehouse, posting_date, posting_time, company, item_code=None, ignore_empty_stock=False):
ignore_empty_stock = cint(ignore_empty_stock)
items = [frappe._dict({"item_code": item_code, "warehouse": warehouse})]
items = []
if item_code and warehouse:
items = get_item_and_warehouses(item_code, warehouse)

if not item_code:
items = get_items_for_stock_reco(warehouse, company)
Expand Down Expand Up @@ -1066,6 +1068,20 @@ def get_items(warehouse, posting_date, posting_time, company, item_code=None, ig
return res


def get_item_and_warehouses(item_code, warehouse):
from frappe.utils.nestedset import get_descendants_of

items = []
if frappe.get_cached_value("Warehouse", warehouse, "is_group"):
childrens = get_descendants_of("Warehouse", warehouse, ignore_permissions=True, order_by="lft")
for ch_warehouse in childrens:
items.append(frappe._dict({"item_code": item_code, "warehouse": ch_warehouse}))
else:
items = [frappe._dict({"item_code": item_code, "warehouse": warehouse})]

return items


def get_items_for_stock_reco(warehouse, company):
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
items = frappe.db.sql(
Expand All @@ -1080,7 +1096,7 @@ def get_items_for_stock_reco(warehouse, company):
and i.is_stock_item = 1
and i.has_variants = 0
and exists(
select name from `tabWarehouse` where lft >= {lft} and rgt <= {rgt} and name = bin.warehouse
select name from `tabWarehouse` where lft >= {lft} and rgt <= {rgt} and name = bin.warehouse and is_group = 0
)
""",
as_dict=1,
Expand All @@ -1095,7 +1111,7 @@ def get_items_for_stock_reco(warehouse, company):
where
i.name = id.parent
and exists(
select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse
select name from `tabWarehouse` where lft >= %s and rgt <= %s and name=id.default_warehouse and is_group = 0
)
and i.is_stock_item = 1
and i.has_variants = 0
Expand Down Expand Up @@ -1157,7 +1173,7 @@ def get_itemwise_batch(warehouse, posting_date, company, item_code=None):
frappe._dict(
{
"item_code": row[0],
"warehouse": warehouse,
"warehouse": row[3],
"qty": row[8],
"item_name": row[1],
"batch_no": row[4],
Expand Down

0 comments on commit 1816f1d

Please sign in to comment.