mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-21 14:09:19 +00:00
fix: use get_cached_value to avoid db call with db.exists
This commit is contained in:
@@ -114,8 +114,9 @@ class Account(NestedSet):
|
|||||||
|
|
||||||
def validate_root_details(self):
|
def validate_root_details(self):
|
||||||
# does not exists parent
|
# does not exists parent
|
||||||
if frappe.db.exists("Account", self.name):
|
account_values = frappe.get_cached_value("Account", self.name, ["parent_account"], as_dict=1)
|
||||||
if not frappe.get_cached_value("Account", self.name, "parent_account"):
|
if account_values:
|
||||||
|
if not account_values.parent_account:
|
||||||
throw(_("Root cannot be edited."), RootNotEditable)
|
throw(_("Root cannot be edited."), RootNotEditable)
|
||||||
|
|
||||||
if not self.parent_account and not self.is_group:
|
if not self.parent_account and not self.is_group:
|
||||||
@@ -439,10 +440,13 @@ def update_account_number(name, account_name, account_number=None, from_descenda
|
|||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def merge_account(old, new, is_group, root_type, company):
|
def merge_account(old, new, is_group, root_type, company):
|
||||||
# Validate properties before merging
|
# Validate properties before merging
|
||||||
if not frappe.db.exists("Account", new):
|
account_data = frappe.get_cached_value(
|
||||||
|
"Account", new, ["is_group", "root_type", "company", "parent_account"], as_dict=True
|
||||||
|
)
|
||||||
|
if not account_data:
|
||||||
throw(_("Account {0} does not exist").format(new))
|
throw(_("Account {0} does not exist").format(new))
|
||||||
|
|
||||||
val = list(frappe.get_cached_value("Account", new, ["is_group", "root_type", "company"]))
|
val = list(account_data.values())[:3] # is_group, root_type, company
|
||||||
|
|
||||||
if val != [cint(is_group), root_type, company]:
|
if val != [cint(is_group), root_type, company]:
|
||||||
throw(
|
throw(
|
||||||
@@ -451,7 +455,7 @@ def merge_account(old, new, is_group, root_type, company):
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
if is_group and frappe.get_cached_value("Account", new, "parent_account") == old:
|
if is_group and account_data.parent_account == old:
|
||||||
frappe.db.set_value(
|
frappe.db.set_value(
|
||||||
"Account", new, "parent_account", frappe.get_cached_value("Account", old, "parent_account")
|
"Account", new, "parent_account", frappe.get_cached_value("Account", old, "parent_account")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -286,9 +286,11 @@ def get_accounts_with_children(accounts):
|
|||||||
|
|
||||||
all_accounts = []
|
all_accounts = []
|
||||||
for d in accounts:
|
for d in accounts:
|
||||||
if frappe.db.exists("Account", d):
|
account_data = frappe.get_cached_value("Account", d, ["lft", "rgt"], as_dict=1)
|
||||||
lft, rgt = frappe.get_cached_value("Account", d, ["lft", "rgt"])
|
if account_data:
|
||||||
children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
|
children = frappe.get_all(
|
||||||
|
"Account", filters={"lft": [">=", account_data.lft], "rgt": ["<=", account_data.rgt]}
|
||||||
|
)
|
||||||
all_accounts += [c.name for c in children]
|
all_accounts += [c.name for c in children]
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("Account: {0} does not exist").format(d))
|
frappe.throw(_("Account: {0} does not exist").format(d))
|
||||||
|
|||||||
@@ -975,7 +975,7 @@ def get_account_balances(accounts, company):
|
|||||||
def create_payment_gateway_account(gateway, payment_channel="Email"):
|
def create_payment_gateway_account(gateway, payment_channel="Email"):
|
||||||
from erpnext.setup.setup_wizard.operations.install_fixtures import create_bank_account
|
from erpnext.setup.setup_wizard.operations.install_fixtures import create_bank_account
|
||||||
|
|
||||||
company = frappe.get_cached_value("Global Defaults", None, "default_company")
|
company = frappe.get_cached_value("Global Defaults", "Global Defaults", "default_company")
|
||||||
if not company:
|
if not company:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user