Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: remove balance from Warehouse Tree #33199

Merged
merged 2 commits into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
}
}
}