perf: use get_cached_value instead of db.get_value in accounts module

This commit is contained in:
Daizy Modi 2022-11-03 13:38:48 +05:30
parent 7a5a500d29
commit 27df455b98
33 changed files with 101 additions and 90 deletions

View File

@ -76,7 +76,7 @@ def get(
def build_result(account, dates, gl_entries): def build_result(account, dates, gl_entries):
result = [[getdate(date), 0.0] for date in dates] result = [[getdate(date), 0.0] for date in dates]
root_type = frappe.db.get_value("Account", account, "root_type") root_type = frappe.get_cached_value("Account", account, "root_type")
# start with the first date # start with the first date
date_index = 0 date_index = 0

View File

@ -58,7 +58,7 @@ class Account(NestedSet):
def validate_parent(self): def validate_parent(self):
"""Fetch Parent Details and validate parent account""" """Fetch Parent Details and validate parent account"""
if self.parent_account: if self.parent_account:
par = frappe.db.get_value( par = frappe.get_cached_value(
"Account", self.parent_account, ["name", "is_group", "company"], as_dict=1 "Account", self.parent_account, ["name", "is_group", "company"], as_dict=1
) )
if not par: if not par:
@ -82,7 +82,7 @@ class Account(NestedSet):
def set_root_and_report_type(self): def set_root_and_report_type(self):
if self.parent_account: if self.parent_account:
par = frappe.db.get_value( par = frappe.get_cached_value(
"Account", self.parent_account, ["report_type", "root_type"], as_dict=1 "Account", self.parent_account, ["report_type", "root_type"], as_dict=1
) )
@ -92,7 +92,9 @@ class Account(NestedSet):
self.root_type = par.root_type self.root_type = par.root_type
if self.is_group: if self.is_group:
db_value = frappe.db.get_value("Account", self.name, ["report_type", "root_type"], as_dict=1) db_value = frappe.get_cached_value(
"Account", self.name, ["report_type", "root_type"], as_dict=1
)
if db_value: if db_value:
if self.report_type != db_value.report_type: if self.report_type != db_value.report_type:
frappe.db.sql( frappe.db.sql(
@ -113,7 +115,7 @@ 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): if frappe.db.exists("Account", self.name):
if not frappe.db.get_value("Account", self.name, "parent_account"): if not frappe.get_cached_value("Account", self.name, "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:
@ -127,7 +129,9 @@ class Account(NestedSet):
return return
ancestors = get_root_company(self.company) ancestors = get_root_company(self.company)
if ancestors: if ancestors:
if frappe.get_value("Company", self.company, "allow_account_creation_against_child_company"): if frappe.get_cached_value(
"Company", self.company, "allow_account_creation_against_child_company"
):
return return
if not frappe.db.get_value( if not frappe.db.get_value(
"Account", {"account_name": self.account_name, "company": ancestors[0]}, "name" "Account", {"account_name": self.account_name, "company": ancestors[0]}, "name"
@ -138,7 +142,7 @@ class Account(NestedSet):
if not descendants: if not descendants:
return return
parent_acc_name_map = {} parent_acc_name_map = {}
parent_acc_name, parent_acc_number = frappe.db.get_value( parent_acc_name, parent_acc_number = frappe.get_cached_value(
"Account", self.parent_account, ["account_name", "account_number"] "Account", self.parent_account, ["account_name", "account_number"]
) )
filters = { filters = {
@ -162,7 +166,7 @@ class Account(NestedSet):
if self.get("__islocal"): if self.get("__islocal"):
return return
existing_is_group = frappe.db.get_value("Account", self.name, "is_group") existing_is_group = frappe.get_cached_value("Account", self.name, "is_group")
if cint(self.is_group) != cint(existing_is_group): if cint(self.is_group) != cint(existing_is_group):
if self.check_gle_exists(): if self.check_gle_exists():
throw(_("Account with existing transaction cannot be converted to ledger")) throw(_("Account with existing transaction cannot be converted to ledger"))
@ -173,7 +177,7 @@ class Account(NestedSet):
throw(_("Account with child nodes cannot be set as ledger")) throw(_("Account with child nodes cannot be set as ledger"))
def validate_frozen_accounts_modifier(self): def validate_frozen_accounts_modifier(self):
old_value = frappe.db.get_value("Account", self.name, "freeze_account") old_value = frappe.get_cached_value("Account", self.name, "freeze_account")
if old_value and old_value != self.freeze_account: if old_value and old_value != self.freeze_account:
frozen_accounts_modifier = frappe.db.get_value( frozen_accounts_modifier = frappe.db.get_value(
"Accounts Settings", None, "frozen_accounts_modifier" "Accounts Settings", None, "frozen_accounts_modifier"
@ -223,9 +227,9 @@ class Account(NestedSet):
) )
# validate if parent of child company account to be added is a group # validate if parent of child company account to be added is a group
if frappe.db.get_value("Account", self.parent_account, "is_group") and not frappe.db.get_value( if frappe.get_cached_value(
"Account", parent_acc_name_map[company], "is_group" "Account", self.parent_account, "is_group"
): ) and not frappe.get_cached_value("Account", parent_acc_name_map[company], "is_group"):
msg = _( msg = _(
"While creating account for Child Company {0}, parent account {1} found as a ledger account." "While creating account for Child Company {0}, parent account {1} found as a ledger account."
).format(company_bold, parent_acc_name_bold) ).format(company_bold, parent_acc_name_bold)
@ -377,17 +381,17 @@ def validate_account_number(name, account_number, company):
@frappe.whitelist() @frappe.whitelist()
def update_account_number(name, account_name, account_number=None, from_descendant=False): def update_account_number(name, account_name, account_number=None, from_descendant=False):
account = frappe.db.get_value("Account", name, "company", as_dict=True) account = frappe.get_cached_value("Account", name, "company", as_dict=True)
if not account: if not account:
return return
old_acc_name, old_acc_number = frappe.db.get_value( old_acc_name, old_acc_number = frappe.get_cached_value(
"Account", name, ["account_name", "account_number"] "Account", name, ["account_name", "account_number"]
) )
# check if account exists in parent company # check if account exists in parent company
ancestors = get_ancestors_of("Company", account.company) ancestors = get_ancestors_of("Company", account.company)
allow_independent_account_creation = frappe.get_value( allow_independent_account_creation = frappe.get_cached_value(
"Company", account.company, "allow_account_creation_against_child_company" "Company", account.company, "allow_account_creation_against_child_company"
) )
@ -438,7 +442,7 @@ def merge_account(old, new, is_group, root_type, company):
if not frappe.db.exists("Account", new): if not frappe.db.exists("Account", new):
throw(_("Account {0} does not exist").format(new)) throw(_("Account {0} does not exist").format(new))
val = list(frappe.db.get_value("Account", new, ["is_group", "root_type", "company"])) val = list(frappe.get_cached_value("Account", new, ["is_group", "root_type", "company"]))
if val != [cint(is_group), root_type, company]: if val != [cint(is_group), root_type, company]:
throw( throw(
@ -447,9 +451,9 @@ def merge_account(old, new, is_group, root_type, company):
) )
) )
if is_group and frappe.db.get_value("Account", new, "parent_account") == old: if is_group and frappe.get_cached_value("Account", new, "parent_account") == old:
frappe.db.set_value( frappe.db.set_value(
"Account", new, "parent_account", frappe.db.get_value("Account", old, "parent_account") "Account", new, "parent_account", frappe.get_cached_value("Account", old, "parent_account")
) )
frappe.rename_doc("Account", old, new, merge=1, force=1) frappe.rename_doc("Account", old, new, merge=1, force=1)

View File

@ -53,7 +53,7 @@ def create_charts(
"account_number": account_number, "account_number": account_number,
"account_type": child.get("account_type"), "account_type": child.get("account_type"),
"account_currency": child.get("account_currency") "account_currency": child.get("account_currency")
or frappe.db.get_value("Company", company, "default_currency"), or frappe.get_cached_value("Company", company, "default_currency"),
"tax_rate": child.get("tax_rate"), "tax_rate": child.get("tax_rate"),
} }
) )
@ -148,7 +148,7 @@ def get_charts_for_country(country, with_standard=False):
) or frappe.local.flags.allow_unverified_charts: ) or frappe.local.flags.allow_unverified_charts:
charts.append(content["name"]) charts.append(content["name"])
country_code = frappe.db.get_value("Country", country, "code") country_code = frappe.get_cached_value("Country", country, "code")
if country_code: if country_code:
folders = ("verified",) folders = ("verified",)
if frappe.local.flags.allow_unverified_charts: if frappe.local.flags.allow_unverified_charts:

View File

@ -77,6 +77,6 @@ def get_party_bank_account(party_type, party):
@frappe.whitelist() @frappe.whitelist()
def get_bank_account_details(bank_account): def get_bank_account_details(bank_account):
return frappe.db.get_value( return frappe.get_cached_value(
"Bank Account", bank_account, ["account", "bank", "bank_account_no"], as_dict=1 "Bank Account", bank_account, ["account", "bank", "bank_account_no"], as_dict=1
) )

View File

@ -57,7 +57,7 @@ def get_bank_transactions(bank_account, from_date=None, to_date=None):
@frappe.whitelist() @frappe.whitelist()
def get_account_balance(bank_account, till_date): def get_account_balance(bank_account, till_date):
# returns account balance till the specified date # returns account balance till the specified date
account = frappe.db.get_value("Bank Account", bank_account, "account") account = frappe.get_cached_value("Bank Account", bank_account, "account")
filters = frappe._dict( filters = frappe._dict(
{"account": account, "report_date": till_date, "include_pos_transactions": 1} {"account": account, "report_date": till_date, "include_pos_transactions": 1}
) )
@ -130,8 +130,10 @@ def create_journal_entry_bts(
fieldname=["name", "deposit", "withdrawal", "bank_account"], fieldname=["name", "deposit", "withdrawal", "bank_account"],
as_dict=True, as_dict=True,
)[0] )[0]
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account") company_account = frappe.get_cached_value(
account_type = frappe.db.get_value("Account", second_account, "account_type") "Bank Account", bank_transaction.bank_account, "account"
)
account_type = frappe.get_cached_value("Account", second_account, "account_type")
if account_type in ["Receivable", "Payable"]: if account_type in ["Receivable", "Payable"]:
if not (party_type and party): if not (party_type and party):
frappe.throw( frappe.throw(
@ -164,7 +166,7 @@ def create_journal_entry_bts(
} }
) )
company = frappe.get_value("Account", company_account, "company") company = frappe.get_cached_value("Account", company_account, "company")
journal_entry_dict = { journal_entry_dict = {
"voucher_type": entry_type, "voucher_type": entry_type,
@ -219,8 +221,10 @@ def create_payment_entry_bts(
paid_amount = bank_transaction.unallocated_amount paid_amount = bank_transaction.unallocated_amount
payment_type = "Receive" if bank_transaction.deposit > 0 else "Pay" payment_type = "Receive" if bank_transaction.deposit > 0 else "Pay"
company_account = frappe.get_value("Bank Account", bank_transaction.bank_account, "account") company_account = frappe.get_cached_value(
company = frappe.get_value("Account", company_account, "company") "Bank Account", bank_transaction.bank_account, "account"
)
company = frappe.get_cached_value("Account", company_account, "company")
payment_entry_dict = { payment_entry_dict = {
"company": company, "company": company,
"payment_type": payment_type, "payment_type": payment_type,
@ -266,7 +270,7 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
# updated clear date of all the vouchers based on the bank transaction # updated clear date of all the vouchers based on the bank transaction
vouchers = json.loads(vouchers) vouchers = json.loads(vouchers)
transaction = frappe.get_doc("Bank Transaction", bank_transaction_name) transaction = frappe.get_doc("Bank Transaction", bank_transaction_name)
company_account = frappe.db.get_value("Bank Account", transaction.bank_account, "account") company_account = frappe.get_cached_value("Bank Account", transaction.bank_account, "account")
if transaction.unallocated_amount == 0: if transaction.unallocated_amount == 0:
frappe.throw(_("This bank transaction is already fully reconciled")) frappe.throw(_("This bank transaction is already fully reconciled"))
@ -290,7 +294,7 @@ def reconcile_vouchers(bank_transaction_name, vouchers):
"The sum total of amounts of all selected vouchers should be less than the unallocated amount of the bank transaction" "The sum total of amounts of all selected vouchers should be less than the unallocated amount of the bank transaction"
) )
) )
account = frappe.db.get_value("Bank Account", transaction.bank_account, "account") account = frappe.get_cached_value("Bank Account", transaction.bank_account, "account")
for voucher in vouchers: for voucher in vouchers:
gl_entry = frappe.db.get_value( gl_entry = frappe.db.get_value(

View File

@ -74,7 +74,7 @@ def get_header_mapping(columns, bank_account):
def get_bank_mapping(bank_account): def get_bank_mapping(bank_account):
bank_name = frappe.db.get_value("Bank Account", bank_account, "bank") bank_name = frappe.get_cached_value("Bank Account", bank_account, "bank")
bank = frappe.get_doc("Bank", bank_name) bank = frappe.get_doc("Bank", bank_name)
mapping = {row.file_field: row.bank_transaction_field for row in bank.bank_transaction_mapping} mapping = {row.file_field: row.bank_transaction_field for row in bank.bank_transaction_mapping}

View File

@ -59,7 +59,7 @@ class Budget(Document):
account_list = [] account_list = []
for d in self.get("accounts"): for d in self.get("accounts"):
if d.account: if d.account:
account_details = frappe.db.get_value( account_details = frappe.get_cached_value(
"Account", d.account, ["is_group", "company", "report_type"], as_dict=1 "Account", d.account, ["is_group", "company", "report_type"], as_dict=1
) )
@ -306,7 +306,7 @@ def get_other_condition(args, budget, for_doc):
if args.get("fiscal_year"): if args.get("fiscal_year"):
date_field = "schedule_date" if for_doc == "Material Request" else "transaction_date" date_field = "schedule_date" if for_doc == "Material Request" else "transaction_date"
start_date, end_date = frappe.db.get_value( start_date, end_date = frappe.get_cached_value(
"Fiscal Year", args.get("fiscal_year"), ["year_start_date", "year_end_date"] "Fiscal Year", args.get("fiscal_year"), ["year_start_date", "year_end_date"]
) )
@ -379,7 +379,7 @@ def get_accumulated_monthly_budget(monthly_distribution, posting_date, fiscal_ye
): ):
distribution.setdefault(d.month, d.percentage_allocation) distribution.setdefault(d.month, d.percentage_allocation)
dt = frappe.db.get_value("Fiscal Year", fiscal_year, "year_start_date") dt = frappe.get_cached_value("Fiscal Year", fiscal_year, "year_start_date")
accumulated_percentage = 0.0 accumulated_percentage = 0.0
while dt <= getdate(posting_date): while dt <= getdate(posting_date):

View File

@ -45,8 +45,8 @@ def validate_columns(data):
@frappe.whitelist() @frappe.whitelist()
def validate_company(company): def validate_company(company):
parent_company, allow_account_creation_against_child_company = frappe.db.get_value( parent_company, allow_account_creation_against_child_company = frappe.get_cached_value(
"Company", {"name": company}, ["parent_company", "allow_account_creation_against_child_company"] "Company", company, ["parent_company", "allow_account_creation_against_child_company"]
) )
if parent_company and (not allow_account_creation_against_child_company): if parent_company and (not allow_account_creation_against_child_company):

View File

@ -19,7 +19,7 @@ class Dunning(AccountsController):
self.validate_overdue_days() self.validate_overdue_days()
self.validate_amount() self.validate_amount()
if not self.income_account: if not self.income_account:
self.income_account = frappe.db.get_value("Company", self.company, "default_income_account") self.income_account = frappe.get_cached_value("Company", self.company, "default_income_account")
def validate_overdue_days(self): def validate_overdue_days(self):
self.overdue_days = (getdate(self.posting_date) - getdate(self.due_date)).days or 0 self.overdue_days = (getdate(self.posting_date) - getdate(self.due_date)).days or 0

View File

@ -222,7 +222,7 @@ class ExchangeRateRevaluation(Document):
@frappe.whitelist() @frappe.whitelist()
def get_account_details(account, company, posting_date, party_type=None, party=None): def get_account_details(account, company, posting_date, party_type=None, party=None):
account_currency, account_type = frappe.db.get_value( account_currency, account_type = frappe.get_cached_value(
"Account", account, ["account_currency", "account_type"] "Account", account, ["account_currency", "account_type"]
) )
if account_type in ["Receivable", "Payable"] and not (party_type and party): if account_type in ["Receivable", "Payable"] and not (party_type and party):

View File

@ -170,4 +170,4 @@ def auto_create_fiscal_year():
def get_from_and_to_date(fiscal_year): def get_from_and_to_date(fiscal_year):
fields = ["year_start_date as from_date", "year_end_date as to_date"] fields = ["year_start_date as from_date", "year_end_date as to_date"]
return frappe.db.get_value("Fiscal Year", fiscal_year, fields, as_dict=1) return frappe.get_cached_value("Fiscal Year", fiscal_year, fields, as_dict=1)

View File

@ -58,7 +58,7 @@ class GLEntry(Document):
validate_balance_type(self.account, adv_adj) validate_balance_type(self.account, adv_adj)
validate_frozen_account(self.account, adv_adj) validate_frozen_account(self.account, adv_adj)
if frappe.db.get_value("Account", self.account, "account_type") not in [ if frappe.get_cached_value("Account", self.account, "account_type") not in [
"Receivable", "Receivable",
"Payable", "Payable",
]: ]:
@ -120,7 +120,7 @@ class GLEntry(Document):
frappe.throw(msg, title=_("Missing Cost Center")) frappe.throw(msg, title=_("Missing Cost Center"))
def validate_dimensions_for_pl_and_bs(self): def validate_dimensions_for_pl_and_bs(self):
account_type = frappe.db.get_value("Account", self.account, "report_type") account_type = frappe.get_cached_value("Account", self.account, "report_type")
for dimension in get_checks_for_pl_and_bs_accounts(): for dimension in get_checks_for_pl_and_bs_accounts():
if ( if (
@ -188,7 +188,7 @@ class GLEntry(Document):
def check_pl_account(self): def check_pl_account(self):
if ( if (
self.is_opening == "Yes" self.is_opening == "Yes"
and frappe.db.get_value("Account", self.account, "report_type") == "Profit and Loss" and frappe.get_cached_value("Account", self.account, "report_type") == "Profit and Loss"
and not self.is_cancelled and not self.is_cancelled
): ):
frappe.throw( frappe.throw(
@ -281,7 +281,7 @@ class GLEntry(Document):
def validate_balance_type(account, adv_adj=False): def validate_balance_type(account, adv_adj=False):
if not adv_adj and account: if not adv_adj and account:
balance_must_be = frappe.db.get_value("Account", account, "balance_must_be") balance_must_be = frappe.get_cached_value("Account", account, "balance_must_be")
if balance_must_be: if balance_must_be:
balance = frappe.db.sql( balance = frappe.db.sql(
"""select sum(debit) - sum(credit) """select sum(debit) - sum(credit)

View File

@ -21,7 +21,7 @@ class ItemTaxTemplate(Document):
check_list = [] check_list = []
for d in self.get("taxes"): for d in self.get("taxes"):
if d.tax_type: if d.tax_type:
account_type = frappe.db.get_value("Account", d.tax_type, "account_type") account_type = frappe.get_cached_value("Account", d.tax_type, "account_type")
if account_type not in [ if account_type not in [
"Tax", "Tax",

View File

@ -319,7 +319,7 @@ class JournalEntry(AccountsController):
def validate_party(self): def validate_party(self):
for d in self.get("accounts"): for d in self.get("accounts"):
account_type = frappe.db.get_value("Account", d.account, "account_type") account_type = frappe.get_cached_value("Account", d.account, "account_type")
if account_type in ["Receivable", "Payable"]: if account_type in ["Receivable", "Payable"]:
if not (d.party_type and d.party): if not (d.party_type and d.party):
frappe.throw( frappe.throw(
@ -382,7 +382,7 @@ class JournalEntry(AccountsController):
def validate_against_jv(self): def validate_against_jv(self):
for d in self.get("accounts"): for d in self.get("accounts"):
if d.reference_type == "Journal Entry": if d.reference_type == "Journal Entry":
account_root_type = frappe.db.get_value("Account", d.account, "root_type") account_root_type = frappe.get_cached_value("Account", d.account, "root_type")
if account_root_type == "Asset" and flt(d.debit) > 0: if account_root_type == "Asset" and flt(d.debit) > 0:
frappe.throw( frappe.throw(
_( _(
@ -631,7 +631,7 @@ class JournalEntry(AccountsController):
def validate_multi_currency(self): def validate_multi_currency(self):
alternate_currency = [] alternate_currency = []
for d in self.get("accounts"): for d in self.get("accounts"):
account = frappe.db.get_value( account = frappe.get_cached_value(
"Account", d.account, ["account_currency", "account_type"], as_dict=1 "Account", d.account, ["account_currency", "account_type"], as_dict=1
) )
if account: if account:
@ -762,7 +762,7 @@ class JournalEntry(AccountsController):
party_amount += d.debit_in_account_currency or d.credit_in_account_currency party_amount += d.debit_in_account_currency or d.credit_in_account_currency
party_account_currency = d.account_currency party_account_currency = d.account_currency
elif frappe.db.get_value("Account", d.account, "account_type") in ["Bank", "Cash"]: elif frappe.get_cached_value("Account", d.account, "account_type") in ["Bank", "Cash"]:
bank_amount += d.debit_in_account_currency or d.credit_in_account_currency bank_amount += d.debit_in_account_currency or d.credit_in_account_currency
bank_account_currency = d.account_currency bank_account_currency = d.account_currency
@ -987,7 +987,7 @@ def get_default_bank_cash_account(company, account_type=None, mode_of_payment=No
account = account_list[0].name account = account_list[0].name
if account: if account:
account_details = frappe.db.get_value( account_details = frappe.get_cached_value(
"Account", account, ["account_currency", "account_type"], as_dict=1 "Account", account, ["account_currency", "account_type"], as_dict=1
) )
@ -1116,7 +1116,7 @@ def get_payment_entry(ref_doc, args):
"party_type": args.get("party_type"), "party_type": args.get("party_type"),
"party": ref_doc.get(args.get("party_type").lower()), "party": ref_doc.get(args.get("party_type").lower()),
"cost_center": cost_center, "cost_center": cost_center,
"account_type": frappe.db.get_value("Account", args.get("party_account"), "account_type"), "account_type": frappe.get_cached_value("Account", args.get("party_account"), "account_type"),
"account_currency": args.get("party_account_currency") "account_currency": args.get("party_account_currency")
or get_account_currency(args.get("party_account")), or get_account_currency(args.get("party_account")),
"balance": get_balance_on(args.get("party_account")), "balance": get_balance_on(args.get("party_account")),
@ -1283,7 +1283,7 @@ def get_party_account_and_balance(company, party_type, party, cost_center=None):
"account": account, "account": account,
"balance": account_balance, "balance": account_balance,
"party_balance": party_balance, "party_balance": party_balance,
"account_currency": frappe.db.get_value("Account", account, "account_currency"), "account_currency": frappe.get_cached_value("Account", account, "account_currency"),
} }
@ -1296,7 +1296,7 @@ def get_account_balance_and_party_type(
frappe.msgprint(_("No Permission"), raise_exception=1) frappe.msgprint(_("No Permission"), raise_exception=1)
company_currency = erpnext.get_company_currency(company) company_currency = erpnext.get_company_currency(company)
account_details = frappe.db.get_value( account_details = frappe.get_cached_value(
"Account", account, ["account_type", "account_currency"], as_dict=1 "Account", account, ["account_type", "account_currency"], as_dict=1
) )
@ -1349,7 +1349,7 @@ def get_exchange_rate(
): ):
from erpnext.setup.utils import get_exchange_rate from erpnext.setup.utils import get_exchange_rate
account_details = frappe.db.get_value( account_details = frappe.get_cached_value(
"Account", account, ["account_type", "root_type", "account_currency", "company"], as_dict=1 "Account", account, ["account_type", "root_type", "account_currency", "company"], as_dict=1
) )

View File

@ -25,7 +25,7 @@ class ModeofPayment(Document):
def validate_accounts(self): def validate_accounts(self):
for entry in self.accounts: for entry in self.accounts:
"""Error when Company of Ledger account doesn't match with Company Selected""" """Error when Company of Ledger account doesn't match with Company Selected"""
if frappe.db.get_value("Account", entry.default_account, "company") != entry.company: if frappe.get_cached_value("Account", entry.default_account, "company") != entry.company:
frappe.throw( frappe.throw(
_("Account {0} does not match with Company {1} in Mode of Account: {2}").format( _("Account {0} does not match with Company {1} in Mode of Account: {2}").format(
entry.default_account, entry.company, self.name entry.default_account, entry.company, self.name

View File

@ -256,7 +256,7 @@ class PaymentEntry(AccountsController):
self.validate_account_type(self.paid_to, ["Bank", "Cash"]) self.validate_account_type(self.paid_to, ["Bank", "Cash"])
def validate_account_type(self, account, account_types): def validate_account_type(self, account, account_types):
account_type = frappe.db.get_value("Account", account, "account_type") account_type = frappe.get_cached_value("Account", account, "account_type")
# if account_type not in account_types: # if account_type not in account_types:
# frappe.throw(_("Account Type for {0} must be {1}").format(account, comma_or(account_types))) # frappe.throw(_("Account Type for {0} must be {1}").format(account, comma_or(account_types)))
@ -743,7 +743,7 @@ class PaymentEntry(AccountsController):
def validate_transaction_reference(self): def validate_transaction_reference(self):
bank_account = self.paid_to if self.payment_type == "Receive" else self.paid_from bank_account = self.paid_to if self.payment_type == "Receive" else self.paid_from
bank_account_type = frappe.db.get_value("Account", bank_account, "account_type") bank_account_type = frappe.get_cached_value("Account", bank_account, "account_type")
if bank_account_type == "Bank": if bank_account_type == "Bank":
if not self.reference_no or not self.reference_date: if not self.reference_no or not self.reference_date:
@ -1321,7 +1321,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices):
d.voucher_type, d.voucher_no, "payment_terms_template" d.voucher_type, d.voucher_no, "payment_terms_template"
) )
if payment_term_template: if payment_term_template:
allocate_payment_based_on_payment_terms = frappe.db.get_value( allocate_payment_based_on_payment_terms = frappe.get_cached_value(
"Payment Terms Template", payment_term_template, "allocate_payment_based_on_payment_terms" "Payment Terms Template", payment_term_template, "allocate_payment_based_on_payment_terms"
) )
if allocate_payment_based_on_payment_terms: if allocate_payment_based_on_payment_terms:
@ -1553,7 +1553,7 @@ def get_account_details(account, date, cost_center=None):
{ {
"account_currency": get_account_currency(account), "account_currency": get_account_currency(account),
"account_balance": account_balance, "account_balance": account_balance,
"account_type": frappe.db.get_value("Account", account, "account_type"), "account_type": frappe.get_cached_value("Account", account, "account_type"),
} }
) )
@ -1722,9 +1722,9 @@ def get_payment_entry(
if doc.doctype == "Purchase Invoice" and doc.invoice_is_blocked(): if doc.doctype == "Purchase Invoice" and doc.invoice_is_blocked():
frappe.msgprint(_("{0} is on hold till {1}").format(doc.name, doc.release_date)) frappe.msgprint(_("{0} is on hold till {1}").format(doc.name, doc.release_date))
else: else:
if doc.doctype in ("Sales Invoice", "Purchase Invoice") and frappe.get_value( if doc.doctype in ("Sales Invoice", "Purchase Invoice") and frappe.get_cached_value(
"Payment Terms Template", "Payment Terms Template",
{"name": doc.payment_terms_template}, doc.payment_terms_template,
"allocate_payment_based_on_payment_terms", "allocate_payment_based_on_payment_terms",
): ):

View File

@ -11,7 +11,7 @@ class PaymentGatewayAccount(Document):
self.name = self.payment_gateway + " - " + self.currency self.name = self.payment_gateway + " - " + self.currency
def validate(self): def validate(self):
self.currency = frappe.db.get_value("Account", self.payment_account, "account_currency") self.currency = frappe.get_cached_value("Account", self.payment_account, "account_currency")
self.update_default_payment_gateway() self.update_default_payment_gateway()
self.set_as_default_if_not_set() self.set_as_default_if_not_set()

View File

@ -97,7 +97,7 @@ class PaymentLedgerEntry(Document):
) )
def validate_dimensions_for_pl_and_bs(self): def validate_dimensions_for_pl_and_bs(self):
account_type = frappe.db.get_value("Account", self.account, "report_type") account_type = frappe.get_cached_value("Account", self.account, "report_type")
for dimension in get_checks_for_pl_and_bs_accounts(): for dimension in get_checks_for_pl_and_bs_accounts():
if ( if (

View File

@ -53,7 +53,7 @@ class PaymentRequest(Document):
def validate_currency(self): def validate_currency(self):
ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name) ref_doc = frappe.get_doc(self.reference_doctype, self.reference_name)
if self.payment_account and ref_doc.currency != frappe.db.get_value( if self.payment_account and ref_doc.currency != frappe.get_cached_value(
"Account", self.payment_account, "account_currency" "Account", self.payment_account, "account_currency"
): ):
frappe.throw(_("Transaction currency must be same as Payment Gateway currency")) frappe.throw(_("Transaction currency must be same as Payment Gateway currency"))

View File

@ -43,7 +43,7 @@ class PeriodClosingVoucher(AccountsController):
make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name) make_reverse_gl_entries(voucher_type="Period Closing Voucher", voucher_no=self.name)
def validate_account_head(self): def validate_account_head(self):
closing_account_type = frappe.db.get_value("Account", self.closing_account_head, "root_type") closing_account_type = frappe.get_cached_value("Account", self.closing_account_head, "root_type")
if closing_account_type not in ["Liability", "Equity"]: if closing_account_type not in ["Liability", "Equity"]:
frappe.throw( frappe.throw(

View File

@ -335,7 +335,8 @@ class POSInvoice(SalesInvoice):
if ( if (
self.change_amount self.change_amount
and self.account_for_change_amount and self.account_for_change_amount
and frappe.db.get_value("Account", self.account_for_change_amount, "company") != self.company and frappe.get_cached_value("Account", self.account_for_change_amount, "company")
!= self.company
): ):
frappe.throw( frappe.throw(
_("The selected change account {} doesn't belongs to Company {}.").format( _("The selected change account {} doesn't belongs to Company {}.").format(
@ -486,7 +487,7 @@ class POSInvoice(SalesInvoice):
customer_price_list, customer_group, customer_currency = frappe.db.get_value( customer_price_list, customer_group, customer_currency = frappe.db.get_value(
"Customer", self.customer, ["default_price_list", "customer_group", "default_currency"] "Customer", self.customer, ["default_price_list", "customer_group", "default_currency"]
) )
customer_group_price_list = frappe.db.get_value( customer_group_price_list = frappe.get_cached_value(
"Customer Group", customer_group, "default_price_list" "Customer Group", customer_group, "default_price_list"
) )
selling_price_list = ( selling_price_list = (
@ -532,7 +533,7 @@ class POSInvoice(SalesInvoice):
if not self.debit_to: if not self.debit_to:
self.debit_to = get_party_account("Customer", self.customer, self.company) self.debit_to = get_party_account("Customer", self.customer, self.company)
self.party_account_currency = frappe.db.get_value( self.party_account_currency = frappe.get_cached_value(
"Account", self.debit_to, "account_currency", cache=True "Account", self.debit_to, "account_currency", cache=True
) )
if not self.due_date and self.customer: if not self.due_date and self.customer:

View File

@ -153,8 +153,8 @@ class PurchaseInvoice(BuyingController):
def set_missing_values(self, for_validate=False): def set_missing_values(self, for_validate=False):
if not self.credit_to: if not self.credit_to:
self.credit_to = get_party_account("Supplier", self.supplier, self.company) self.credit_to = get_party_account("Supplier", self.supplier, self.company)
self.party_account_currency = frappe.db.get_value( self.party_account_currency = frappe.get_cached_value(
"Account", self.credit_to, "account_currency", cache=True "Account", self.credit_to, "account_currency"
) )
if not self.due_date: if not self.due_date:
self.due_date = get_due_date( self.due_date = get_due_date(
@ -175,7 +175,7 @@ class PurchaseInvoice(BuyingController):
if not self.credit_to: if not self.credit_to:
self.raise_missing_debit_credit_account_error("Supplier", self.supplier) self.raise_missing_debit_credit_account_error("Supplier", self.supplier)
account = frappe.db.get_value( account = frappe.get_cached_value(
"Account", self.credit_to, ["account_type", "report_type", "account_currency"], as_dict=True "Account", self.credit_to, ["account_type", "report_type", "account_currency"], as_dict=True
) )
@ -673,7 +673,7 @@ class PurchaseInvoice(BuyingController):
exchange_rate_map, net_rate_map = get_purchase_document_details(self) exchange_rate_map, net_rate_map = get_purchase_document_details(self)
provisional_accounting_for_non_stock_items = cint( provisional_accounting_for_non_stock_items = cint(
frappe.db.get_value( frappe.get_cached_value(
"Company", self.company, "enable_provisional_accounting_for_non_stock_items" "Company", self.company, "enable_provisional_accounting_for_non_stock_items"
) )
) )
@ -984,7 +984,7 @@ class PurchaseInvoice(BuyingController):
asset_amount = flt(item.net_amount) + flt(item.item_tax_amount / self.conversion_rate) asset_amount = flt(item.net_amount) + flt(item.item_tax_amount / self.conversion_rate)
base_asset_amount = flt(item.base_net_amount + item.item_tax_amount) base_asset_amount = flt(item.base_net_amount + item.item_tax_amount)
item_exp_acc_type = frappe.db.get_value("Account", item.expense_account, "account_type") item_exp_acc_type = frappe.get_cached_value("Account", item.expense_account, "account_type")
if not item.expense_account or item_exp_acc_type not in [ if not item.expense_account or item_exp_acc_type not in [
"Asset Received But Not Billed", "Asset Received But Not Billed",
"Fixed Asset", "Fixed Asset",

View File

@ -27,7 +27,7 @@ class SalesTaxesandChargesTemplate(Document):
def set_missing_values(self): def set_missing_values(self):
for data in self.taxes: for data in self.taxes:
if data.charge_type == "On Net Total" and flt(data.rate) == 0.0: if data.charge_type == "On Net Total" and flt(data.rate) == 0.0:
data.rate = frappe.db.get_value("Account", data.account_head, "tax_rate") data.rate = frappe.get_cached_value("Account", data.account_head, "tax_rate")
def valdiate_taxes_and_charges_template(doc): def valdiate_taxes_and_charges_template(doc):

View File

@ -296,7 +296,7 @@ def get_default_price_list(party):
return party.default_price_list return party.default_price_list
if party.doctype == "Customer": if party.doctype == "Customer":
return frappe.db.get_value("Customer Group", party.customer_group, "default_price_list") return frappe.get_cached_value("Customer Group", party.customer_group, "default_price_list")
def set_price_list(party_details, party, party_type, given_price_list, pos=None): def set_price_list(party_details, party, party_type, given_price_list, pos=None):
@ -385,7 +385,7 @@ def get_party_account(party_type, party=None, company=None):
existing_gle_currency = get_party_gle_currency(party_type, party, company) existing_gle_currency = get_party_gle_currency(party_type, party, company)
if existing_gle_currency: if existing_gle_currency:
if account: if account:
account_currency = frappe.db.get_value("Account", account, "account_currency", cache=True) account_currency = frappe.get_cached_value("Account", account, "account_currency", cache=True)
if (account and account_currency != existing_gle_currency) or not account: if (account and account_currency != existing_gle_currency) or not account:
account = get_party_gle_account(party_type, party, company) account = get_party_gle_account(party_type, party, company)
@ -402,7 +402,7 @@ def get_party_bank_account(party_type, party):
def get_party_account_currency(party_type, party, company): def get_party_account_currency(party_type, party, company):
def generator(): def generator():
party_account = get_party_account(party_type, party, company) party_account = get_party_account(party_type, party, company)
return frappe.db.get_value("Account", party_account, "account_currency", cache=True) return frappe.get_cached_value("Account", party_account, "account_currency", cache=True)
return frappe.local_cache("party_account_currency", (party_type, party, company), generator) return frappe.local_cache("party_account_currency", (party_type, party, company), generator)
@ -474,7 +474,7 @@ def validate_party_accounts(doc):
else: else:
companies.append(account.company) companies.append(account.company)
party_account_currency = frappe.db.get_value( party_account_currency = frappe.get_cached_value(
"Account", account.account, "account_currency", cache=True "Account", account.account, "account_currency", cache=True
) )
if frappe.db.get_default("Company"): if frappe.db.get_default("Company"):
@ -482,7 +482,9 @@ def validate_party_accounts(doc):
"Company", frappe.db.get_default("Company"), "default_currency" "Company", frappe.db.get_default("Company"), "default_currency"
) )
else: else:
company_default_currency = frappe.db.get_value("Company", account.company, "default_currency") company_default_currency = frappe.get_cached_value(
"Company", account.company, "default_currency"
)
validate_party_gle_currency(doc.doctype, doc.name, account.company, party_account_currency) validate_party_gle_currency(doc.doctype, doc.name, account.company, party_account_currency)
@ -801,7 +803,7 @@ def get_dashboard_info(party_type, party, loyalty_program=None):
) )
for d in companies: for d in companies:
company_default_currency = frappe.db.get_value("Company", d.company, "default_currency") company_default_currency = frappe.get_cached_value("Company", d.company, "default_currency")
party_account_currency = get_party_account_currency(party_type, party, d.company) party_account_currency = get_party_account_currency(party_type, party, d.company)
if party_account_currency == company_default_currency: if party_account_currency == company_default_currency:

View File

@ -21,7 +21,7 @@ def execute(filters=None):
if not filters.get("account"): if not filters.get("account"):
return columns, [] return columns, []
account_currency = frappe.db.get_value("Account", filters.account, "account_currency") account_currency = frappe.get_cached_value("Account", filters.account, "account_currency")
data = get_entries(filters) data = get_entries(filters)

View File

@ -180,7 +180,7 @@ def get_account_type_based_gl_data(company, start_date, end_date, account_type,
filters = frappe._dict(filters or {}) filters = frappe._dict(filters or {})
if filters.include_default_book_entries: if filters.include_default_book_entries:
company_fb = frappe.db.get_value("Company", company, "default_finance_book") company_fb = frappe.get_cached_value("Company", company, "default_finance_book")
cond = """ AND (finance_book in (%s, %s, '') OR finance_book IS NULL) cond = """ AND (finance_book in (%s, %s, '') OR finance_book IS NULL)
""" % ( """ % (
frappe.db.escape(filters.finance_book), frappe.db.escape(filters.finance_book),

View File

@ -641,7 +641,7 @@ def set_gl_entries_by_account(
"rgt": root_rgt, "rgt": root_rgt,
"company": d.name, "company": d.name,
"finance_book": filters.get("finance_book"), "finance_book": filters.get("finance_book"),
"company_fb": frappe.db.get_value("Company", d.name, "default_finance_book"), "company_fb": frappe.get_cached_value("Company", d.name, "default_finance_book"),
}, },
as_dict=True, as_dict=True,
) )

View File

@ -220,8 +220,8 @@ class PartyLedgerSummaryReport(object):
if self.filters.party_type == "Customer": if self.filters.party_type == "Customer":
if self.filters.get("customer_group"): if self.filters.get("customer_group"):
lft, rgt = frappe.db.get_value( lft, rgt = frappe.get_cached_value(
"Customer Group", self.filters.get("customer_group"), ["lft", "rgt"] "Customer Group", self.filters.get("customer_group"), ["lft" "rgt"]
) )
conditions.append( conditions.append(

View File

@ -90,7 +90,7 @@ def set_gl_entries_by_account(dimension_list, filters, account, gl_entries_by_ac
gl_filters["dimensions"] = set(dimension_list) gl_filters["dimensions"] = set(dimension_list)
if filters.get("include_default_book_entries"): if filters.get("include_default_book_entries"):
gl_filters["company_fb"] = frappe.db.get_value( gl_filters["company_fb"] = frappe.get_cached_value(
"Company", filters.company, "default_finance_book" "Company", filters.company, "default_finance_book"
) )

View File

@ -440,7 +440,7 @@ def set_gl_entries_by_account(
} }
if filters.get("include_default_book_entries"): if filters.get("include_default_book_entries"):
gl_filters["company_fb"] = frappe.db.get_value("Company", company, "default_finance_book") gl_filters["company_fb"] = frappe.get_cached_value("Company", company, "default_finance_book")
for key, value in filters.items(): for key, value in filters.items():
if value: if value:

View File

@ -174,7 +174,7 @@ def get_gl_entries(filters, accounting_dimensions):
order_by_statement = "order by account, posting_date, creation" order_by_statement = "order by account, posting_date, creation"
if filters.get("include_default_book_entries"): if filters.get("include_default_book_entries"):
filters["company_fb"] = frappe.db.get_value( filters["company_fb"] = frappe.get_cached_value(
"Company", filters.get("company"), "default_finance_book" "Company", filters.get("company"), "default_finance_book"
) )
@ -287,7 +287,7 @@ def get_accounts_with_children(accounts):
all_accounts = [] all_accounts = []
for d in accounts: for d in accounts:
if frappe.db.exists("Account", d): if frappe.db.exists("Account", d):
lft, rgt = frappe.db.get_value("Account", d, ["lft", "rgt"]) lft, rgt = frappe.get_cached_value("Account", d, ["lft", "rgt"])
children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]}) children = frappe.get_all("Account", filters={"lft": [">=", lft], "rgt": ["<=", rgt]})
all_accounts += [c.name for c in children] all_accounts += [c.name for c in children]
else: else:

View File

@ -38,7 +38,7 @@ def validate_filters(filters):
if not filters.fiscal_year: if not filters.fiscal_year:
frappe.throw(_("Fiscal Year {0} is required").format(filters.fiscal_year)) frappe.throw(_("Fiscal Year {0} is required").format(filters.fiscal_year))
fiscal_year = frappe.db.get_value( fiscal_year = frappe.get_cached_value(
"Fiscal Year", filters.fiscal_year, ["year_start_date", "year_end_date"], as_dict=True "Fiscal Year", filters.fiscal_year, ["year_start_date", "year_end_date"], as_dict=True
) )
if not fiscal_year: if not fiscal_year:
@ -177,7 +177,7 @@ def get_rootwise_opening_balances(filters, report_type):
"year_start_date": filters.year_start_date, "year_start_date": filters.year_start_date,
"project": filters.project, "project": filters.project,
"finance_book": filters.finance_book, "finance_book": filters.finance_book,
"company_fb": frappe.db.get_value("Company", filters.company, "default_finance_book"), "company_fb": frappe.get_cached_value("Company", filters.company, "default_finance_book"),
} }
if accounting_dimensions: if accounting_dimensions:

View File

@ -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.db.get_value("Global Defaults", None, "default_company") company = frappe.get_cached_value("Global Defaults", None, "default_company")
if not company: if not company:
return return