From 3ce8386ca3d29b42e16ab6345e6659909ab34aaa Mon Sep 17 00:00:00 2001 From: s-aga-r Date: Thu, 1 Dec 2022 19:44:49 +0530 Subject: [PATCH] refactor: remove `balance` from `Warehouse Tree` --- erpnext/stock/doctype/warehouse/warehouse.py | 59 +------------------ .../stock/doctype/warehouse/warehouse_tree.js | 7 --- 2 files changed, 2 insertions(+), 64 deletions(-) diff --git a/erpnext/stock/doctype/warehouse/warehouse.py b/erpnext/stock/doctype/warehouse/warehouse.py index 6e06d236173b..430a8d17e01e 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 @@ def get_children(doctype, parent=None, company=None, is_root=False): ["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 e9e14c724668..eb635e6757d6 100644 --- a/erpnext/stock/doctype/warehouse/warehouse_tree.js +++ b/erpnext/stock/doctype/warehouse/warehouse_tree.js @@ -17,11 +17,4 @@ frappe.treeview_settings['Warehouse'] = { 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) { - $('' - + format_currency((node.data.balance), node.data.company_currency) - + '').insertBefore(node.$ul); - } - } }