mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-13 14:41:53 +00:00
refactor(stock): convert get_warehouse_account lookup to get_all
Replace the raw nearest-ancestor warehouse-account SELECT with frappe.get_all; `account is not null and ifnull(account,'')!=''` -> filter ["account","is","set"] (IS NOT NULL AND != ''), order_by lft desc, limit 1, pluck. Same result on MariaDB; valid under Postgres. Covered by the existing get_warehouse_account tests. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -61,19 +61,20 @@ def get_warehouse_account(warehouse, warehouse_account=None):
|
||||
|
||||
rebuild_tree("Warehouse")
|
||||
else:
|
||||
account = frappe.db.sql(
|
||||
"""
|
||||
select
|
||||
account from `tabWarehouse`
|
||||
where
|
||||
lft <= %s and rgt >= %s and company = %s
|
||||
and account is not null and ifnull(account, '') !=''
|
||||
order by lft desc limit 1""",
|
||||
(warehouse.lft, warehouse.rgt, warehouse.company),
|
||||
as_list=1,
|
||||
account = frappe.get_all(
|
||||
"Warehouse",
|
||||
filters={
|
||||
"lft": ["<=", warehouse.lft],
|
||||
"rgt": [">=", warehouse.rgt],
|
||||
"company": warehouse.company,
|
||||
"account": ["is", "set"],
|
||||
},
|
||||
pluck="account",
|
||||
order_by="lft desc",
|
||||
limit=1,
|
||||
)
|
||||
|
||||
account = account[0][0] if account else None
|
||||
account = account[0] if account else None
|
||||
|
||||
if not account and warehouse.company:
|
||||
account = get_company_default_inventory_account(warehouse.company)
|
||||
|
||||
Reference in New Issue
Block a user