fix(stock): check warehouse user permission in get_valuation_rate

(cherry picked from commit d959a81394)

# Conflicts:
#	erpnext/stock/get_item_details.py
This commit is contained in:
Mihir Kandoi
2026-10-22 15:55:00 +00:00
committed by Mergify
parent 3ff83243a7
commit 0cc977faf6
+20 -7
View File
@@ -1736,27 +1736,40 @@ def get_valuation_rate(item_code, company, warehouse=None):
frappe.has_permission("Item", doc=item_code, throw=True)
frappe.has_permission("Company", doc=company, ptype="select", throw=True)
warehouse = warehouse or get_default_warehouse(item_code, company)
if warehouse:
erpnext.require_user_permission("Warehouse", warehouse)
return _get_valuation_rate(item_code, company, warehouse)
<<<<<<< HEAD
def _get_valuation_rate(item_code, company, warehouse=None):
=======
def get_default_warehouse(item_code: str, company: str) -> str | None:
return (
get_item_defaults(item_code, company).get("default_warehouse")
or get_item_group_defaults(item_code, company).get("default_warehouse")
or get_brand_defaults(item_code, company).get("default_warehouse")
)
def _get_valuation_rate(item_code: str, company: str, warehouse: str | None = None):
>>>>>>> d959a81 (fix(stock): check warehouse user permission in get_valuation_rate)
# no guard here: set_valuation_rate calls this for the item AND for every Product Bundle
# component, and a caller entitled to the bundle is not necessarily entitled to each component
if frappe.get_cached_value("Warehouse", warehouse, "is_group"):
return {"valuation_rate": 0.0}
item = get_item_defaults(item_code, company)
<<<<<<< HEAD
item_group = get_item_group_defaults(item_code, company)
brand = get_brand_defaults(item_code, company)
# item = frappe.get_doc("Item", item_code)
=======
>>>>>>> d959a81 (fix(stock): check warehouse user permission in get_valuation_rate)
if item.get("is_stock_item"):
if not warehouse:
warehouse = (
item.get("default_warehouse")
or item_group.get("default_warehouse")
or brand.get("default_warehouse")
)
warehouse = warehouse or get_default_warehouse(item_code, company)
return frappe.db.get_value(
"Bin", {"item_code": item_code, "warehouse": warehouse}, ["valuation_rate"], as_dict=True
) or {"valuation_rate": item.get("valuation_rate") or 0}