Merge pull request #33199 from s-aga-r/refactor/warehouse-tree
refactor: remove `balance` from `Warehouse Tree`
diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py
index 6e06d23..430a8d1 100644
--- a/erpnext/stock/doctype/warehouse/warehouse.py
+++ b/erpnext/stock/doctype/warehouse/warehouse.py
@@ -2,12 +2,10 @@
# License: GNU General Public License v3. See license.txt
-from collections import defaultdict
-
import frappe
from frappe import _, throw
from frappe.contacts.address_and_contact import load_address_and_contact
-from frappe.utils import cint, flt
+from frappe.utils import cint
from frappe.utils.nestedset import NestedSet
from pypika.terms import ExistsCriterion
@@ -166,60 +164,7 @@
["company", "in", (company, None, "")],
]
- warehouses = frappe.get_list(doctype, fields=fields, filters=filters, order_by="name")
-
- company_currency = ""
- if company:
- company_currency = frappe.get_cached_value("Company", company, "default_currency")
-
- warehouse_wise_value = get_warehouse_wise_stock_value(company)
-
- # return warehouses
- for wh in warehouses:
- wh["balance"] = warehouse_wise_value.get(wh.value)
- if company_currency:
- wh["company_currency"] = company_currency
- return warehouses
-
-
-def get_warehouse_wise_stock_value(company):
- warehouses = frappe.get_all(
- "Warehouse", fields=["name", "parent_warehouse"], filters={"company": company}
- )
- parent_warehouse = {d.name: d.parent_warehouse for d in warehouses}
-
- filters = {"warehouse": ("in", [data.name for data in warehouses])}
- bin_data = frappe.get_all(
- "Bin",
- fields=["sum(stock_value) as stock_value", "warehouse"],
- filters=filters,
- group_by="warehouse",
- )
-
- warehouse_wise_stock_value = defaultdict(float)
- for row in bin_data:
- if not row.stock_value:
- continue
-
- warehouse_wise_stock_value[row.warehouse] = row.stock_value
- update_value_in_parent_warehouse(
- warehouse_wise_stock_value, parent_warehouse, row.warehouse, row.stock_value
- )
-
- return warehouse_wise_stock_value
-
-
-def update_value_in_parent_warehouse(
- warehouse_wise_stock_value, parent_warehouse_dict, warehouse, stock_value
-):
- parent_warehouse = parent_warehouse_dict.get(warehouse)
- if not parent_warehouse:
- return
-
- warehouse_wise_stock_value[parent_warehouse] += flt(stock_value)
- update_value_in_parent_warehouse(
- warehouse_wise_stock_value, parent_warehouse_dict, parent_warehouse, stock_value
- )
+ return frappe.get_list(doctype, fields=fields, filters=filters, order_by="name")
@frappe.whitelist()
diff --git a/erpnext/stock/doctype/warehouse/warehouse_tree.js b/erpnext/stock/doctype/warehouse/warehouse_tree.js
index e9e14c7..eb635e6 100644
--- a/erpnext/stock/doctype/warehouse/warehouse_tree.js
+++ b/erpnext/stock/doctype/warehouse/warehouse_tree.js
@@ -17,11 +17,4 @@
description: __("Child nodes can be only created under 'Group' type nodes")}
],
ignore_fields:["parent_warehouse"],
- onrender: function(node) {
- if (node.data && node.data.balance!==undefined) {
- $('<span class="balance-area pull-right">'
- + format_currency((node.data.balance), node.data.company_currency)
- + '</span>').insertBefore(node.$ul);
- }
- }
}