mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 08:24:47 +00:00
Optimisation of warehouse_account_map (#13454)
This commit is contained in:
@@ -15,33 +15,39 @@ def get_warehouse_account_map():
|
||||
if not frappe.flags.warehouse_account_map or frappe.flags.in_test:
|
||||
warehouse_account = frappe._dict()
|
||||
|
||||
for d in frappe.get_all('Warehouse', filters = {"is_group": 0},
|
||||
fields = ["name", "account", "parent_warehouse", "company"]):
|
||||
for d in frappe.get_all('Warehouse',
|
||||
fields = ["name", "account", "parent_warehouse", "company"],
|
||||
order_by="lft, rgt"):
|
||||
if not d.account:
|
||||
d.account = get_warehouse_account(d.name, d.company)
|
||||
d.account = get_warehouse_account(d, warehouse_account)
|
||||
|
||||
if d.account:
|
||||
d.account_currency = frappe.db.get_value('Account', d.account, 'account_currency')
|
||||
d.account_currency = frappe.db.get_value('Account', d.account, 'account_currency', cache=True)
|
||||
warehouse_account.setdefault(d.name, d)
|
||||
|
||||
|
||||
frappe.flags.warehouse_account_map = warehouse_account
|
||||
|
||||
return frappe.flags.warehouse_account_map
|
||||
|
||||
def get_warehouse_account(warehouse, company):
|
||||
lft, rgt = frappe.db.get_value("Warehouse", warehouse, ["lft", "rgt"])
|
||||
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""", (lft, rgt, company), as_list=1)
|
||||
def get_warehouse_account(warehouse, warehouse_account=None):
|
||||
account = warehouse.account
|
||||
if not account and warehouse.parent_warehouse:
|
||||
if warehouse_account:
|
||||
account = warehouse_account.get(warehouse.parent_warehouse).account
|
||||
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 = account[0][0] if account else None
|
||||
|
||||
account = account[0][0] if account else None
|
||||
|
||||
if not account:
|
||||
account = get_company_default_inventory_account(company)
|
||||
|
||||
account = get_company_default_inventory_account(warehouse.company)
|
||||
|
||||
return account
|
||||
|
||||
def get_company_default_inventory_account(company):
|
||||
|
||||
Reference in New Issue
Block a user