mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-07 23:31:20 +00:00
Improve performance for warehouse tree (#15207)
* Fix conflicts * Modify query structure * Remove whitespaces
This commit is contained in:
@@ -139,7 +139,7 @@ class Warehouse(NestedSet):
|
|||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def get_children(doctype, parent=None, company=None, is_root=False):
|
def get_children(doctype, parent=None, company=None, is_root=False):
|
||||||
from erpnext.stock.utils import get_stock_value_on
|
from erpnext.stock.utils import get_stock_value_from_bin
|
||||||
|
|
||||||
if is_root:
|
if is_root:
|
||||||
parent = ""
|
parent = ""
|
||||||
@@ -154,7 +154,7 @@ def get_children(doctype, parent=None, company=None, is_root=False):
|
|||||||
|
|
||||||
# return warehouses
|
# return warehouses
|
||||||
for wh in warehouses:
|
for wh in warehouses:
|
||||||
wh["balance"] = get_stock_value_on(warehouse=wh.value)
|
wh["balance"] = get_stock_value_from_bin(warehouse=wh.value)
|
||||||
return warehouses
|
return warehouses
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
@@ -9,6 +9,30 @@ from frappe.utils import flt, cstr, nowdate, nowtime
|
|||||||
|
|
||||||
class InvalidWarehouseCompany(frappe.ValidationError): pass
|
class InvalidWarehouseCompany(frappe.ValidationError): pass
|
||||||
|
|
||||||
|
def get_stock_value_from_bin(warehouse=None, item_code=None):
|
||||||
|
values = {}
|
||||||
|
conditions = ""
|
||||||
|
if warehouse:
|
||||||
|
conditions += """ and warehouse in (
|
||||||
|
select w2.name from `tabWarehouse` w1
|
||||||
|
join `tabWarehouse` w2 on
|
||||||
|
w1.name = %(warehouse)s
|
||||||
|
and w2.lft between w1.lft and w1.rgt
|
||||||
|
) """
|
||||||
|
|
||||||
|
values['warehouse'] = warehouse
|
||||||
|
|
||||||
|
if item_code:
|
||||||
|
conditions += " and item_code = %(item_code)s"
|
||||||
|
|
||||||
|
values['item_code'] = item_code
|
||||||
|
|
||||||
|
query = "select sum(stock_value) from `tabBin` where 1 = 1 %s" % conditions
|
||||||
|
|
||||||
|
stock_value = frappe.db.sql(query, values)
|
||||||
|
|
||||||
|
return stock_value
|
||||||
|
|
||||||
def get_stock_value_on(warehouse=None, posting_date=None, item_code=None):
|
def get_stock_value_on(warehouse=None, posting_date=None, item_code=None):
|
||||||
if not posting_date: posting_date = nowdate()
|
if not posting_date: posting_date = nowdate()
|
||||||
|
|
||||||
@@ -219,4 +243,3 @@ def validate_warehouse_company(warehouse, company):
|
|||||||
def is_group_warehouse(warehouse):
|
def is_group_warehouse(warehouse):
|
||||||
if frappe.db.get_value("Warehouse", warehouse, "is_group"):
|
if frappe.db.get_value("Warehouse", warehouse, "is_group"):
|
||||||
frappe.throw(_("Group node warehouse is not allowed to select for transactions"))
|
frappe.throw(_("Group node warehouse is not allowed to select for transactions"))
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user