Skip to content

Commit

Permalink
Merge pull request #33199 from s-aga-r/refactor/warehouse-tree
Browse files Browse the repository at this point in the history
refactor: remove `balance` from `Warehouse Tree`
  • Loading branch information
rohitwaghchaure authored Dec 2, 2022
2 parents 295ce0e + b3ae6cc commit 66dbf94
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 64 deletions.
59 changes: 2 additions & 57 deletions erpnext/stock/doctype/warehouse/warehouse.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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()
Expand Down
7 changes: 0 additions & 7 deletions erpnext/stock/doctype/warehouse/warehouse_tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
$('<span class="balance-area pull-right">'
+ format_currency((node.data.balance), node.data.company_currency)
+ '</span>').insertBefore(node.$ul);
}
}
}

0 comments on commit 66dbf94

Please sign in to comment.