Skip to content

Commit

Permalink
revert: Reverting changes done on 33495 (frappe#33662)
Browse files Browse the repository at this point in the history
'ordered_qty' will not be fetched from `tabBin`

(cherry picked from commit be38205)
  • Loading branch information
ruthra-kumar authored and developmentforpeople committed Jan 26, 2023
1 parent 3719283 commit 03c3118
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
1 change: 0 additions & 1 deletion erpnext/stock/doctype/item/test_item.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ def test_get_item_details(self):
"conversion_factor": 1.0,
"reserved_qty": 1,
"actual_qty": 5,
"ordered_qty": 10,
"projected_qty": 14,
}

Expand Down
29 changes: 21 additions & 8 deletions erpnext/stock/get_item_details.py
Original file line number Diff line number Diff line change
Expand Up @@ -1160,14 +1160,27 @@ def get_projected_qty(item_code, warehouse):


@frappe.whitelist()
def get_bin_details(item_code, warehouse, company=None):
bin_details = frappe.db.get_value(
"Bin",
{"item_code": item_code, "warehouse": warehouse},
["projected_qty", "actual_qty", "reserved_qty", "ordered_qty"],
as_dict=True,
cache=True,
) or {"projected_qty": 0, "actual_qty": 0, "reserved_qty": 0, "ordered_qty": 0}
def get_bin_details(item_code, warehouse, company=None, include_child_warehouses=False):
bin_details = {"projected_qty": 0, "actual_qty": 0, "reserved_qty": 0}

if warehouse:
from frappe.query_builder.functions import Coalesce, Sum

from erpnext.stock.doctype.warehouse.warehouse import get_child_warehouses

warehouses = get_child_warehouses(warehouse) if include_child_warehouses else [warehouse]

bin = frappe.qb.DocType("Bin")
bin_details = (
frappe.qb.from_(bin)
.select(
Coalesce(Sum(bin.projected_qty), 0).as_("projected_qty"),
Coalesce(Sum(bin.actual_qty), 0).as_("actual_qty"),
Coalesce(Sum(bin.reserved_qty), 0).as_("reserved_qty"),
)
.where((bin.item_code == item_code) & (bin.warehouse.isin(warehouses)))
).run(as_dict=True)[0]

if company:
bin_details["company_total_stock"] = get_company_total_stock(item_code, company)
return bin_details
Expand Down

0 comments on commit 03c3118

Please sign in to comment.