perf: use get_cached_value instead of db.get_value in controllers (#32776)
This commit is contained in:
@@ -227,7 +227,7 @@ class AccountsController(TransactionBase):
|
||||
for item in self.get("items"):
|
||||
if item.get("enable_deferred_revenue") or item.get("enable_deferred_expense"):
|
||||
if not item.get(field_map.get(self.doctype)):
|
||||
default_deferred_account = frappe.db.get_value(
|
||||
default_deferred_account = frappe.get_cached_value(
|
||||
"Company", self.company, "default_" + field_map.get(self.doctype)
|
||||
)
|
||||
if not default_deferred_account:
|
||||
@@ -676,7 +676,7 @@ class AccountsController(TransactionBase):
|
||||
|
||||
def validate_enabled_taxes_and_charges(self):
|
||||
taxes_and_charges_doctype = self.meta.get_options("taxes_and_charges")
|
||||
if frappe.db.get_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
|
||||
if frappe.get_cached_value(taxes_and_charges_doctype, self.taxes_and_charges, "disabled"):
|
||||
frappe.throw(
|
||||
_("{0} '{1}' is disabled").format(taxes_and_charges_doctype, self.taxes_and_charges)
|
||||
)
|
||||
@@ -684,7 +684,7 @@ class AccountsController(TransactionBase):
|
||||
def validate_tax_account_company(self):
|
||||
for d in self.get("taxes"):
|
||||
if d.account_head:
|
||||
tax_account_company = frappe.db.get_value("Account", d.account_head, "company")
|
||||
tax_account_company = frappe.get_cached_value("Account", d.account_head, "company")
|
||||
if tax_account_company != self.company:
|
||||
frappe.throw(
|
||||
_("Row #{0}: Account {1} does not belong to company {2}").format(
|
||||
@@ -929,7 +929,9 @@ class AccountsController(TransactionBase):
|
||||
party_account = self.credit_to if is_purchase_invoice else self.debit_to
|
||||
party_type = "Supplier" if is_purchase_invoice else "Customer"
|
||||
|
||||
gain_loss_account = frappe.db.get_value("Company", self.company, "exchange_gain_loss_account")
|
||||
gain_loss_account = frappe.get_cached_value(
|
||||
"Company", self.company, "exchange_gain_loss_account"
|
||||
)
|
||||
if not gain_loss_account:
|
||||
frappe.throw(
|
||||
_("Please set default Exchange Gain/Loss Account in Company {}").format(self.get("company"))
|
||||
@@ -1026,7 +1028,7 @@ class AccountsController(TransactionBase):
|
||||
else self.grand_total
|
||||
),
|
||||
"outstanding_amount": self.outstanding_amount,
|
||||
"difference_account": frappe.db.get_value(
|
||||
"difference_account": frappe.get_cached_value(
|
||||
"Company", self.company, "exchange_gain_loss_account"
|
||||
),
|
||||
"exchange_gain_loss": flt(d.get("exchange_gain_loss")),
|
||||
@@ -1394,7 +1396,7 @@ class AccountsController(TransactionBase):
|
||||
@property
|
||||
def company_abbr(self):
|
||||
if not hasattr(self, "_abbr"):
|
||||
self._abbr = frappe.db.get_value("Company", self.company, "abbr")
|
||||
self._abbr = frappe.get_cached_value("Company", self.company, "abbr")
|
||||
|
||||
return self._abbr
|
||||
|
||||
@@ -1780,7 +1782,7 @@ class AccountsController(TransactionBase):
|
||||
"""
|
||||
|
||||
if self.is_internal_transfer() and not self.unrealized_profit_loss_account:
|
||||
unrealized_profit_loss_account = frappe.db.get_value(
|
||||
unrealized_profit_loss_account = frappe.get_cached_value(
|
||||
"Company", self.company, "unrealized_profit_loss_account"
|
||||
)
|
||||
|
||||
@@ -1895,7 +1897,9 @@ class AccountsController(TransactionBase):
|
||||
|
||||
@frappe.whitelist()
|
||||
def get_tax_rate(account_head):
|
||||
return frappe.db.get_value("Account", account_head, ["tax_rate", "account_name"], as_dict=True)
|
||||
return frappe.get_cached_value(
|
||||
"Account", account_head, ["tax_rate", "account_name"], as_dict=True
|
||||
)
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
@@ -1904,7 +1908,7 @@ def get_default_taxes_and_charges(master_doctype, tax_template=None, company=Non
|
||||
return {}
|
||||
|
||||
if tax_template and company:
|
||||
tax_template_company = frappe.db.get_value(master_doctype, tax_template, "company")
|
||||
tax_template_company = frappe.get_cached_value(master_doctype, tax_template, "company")
|
||||
if tax_template_company == company:
|
||||
return
|
||||
|
||||
|
||||
Reference in New Issue
Block a user