perf: reduce queries during transaction save

This commit is contained in:
Sagar Vora
2024-11-30 00:11:03 +05:30
parent 810c72a30c
commit b6b8a06fda
3 changed files with 13 additions and 19 deletions

View File

@@ -29,6 +29,12 @@ from erpnext.accounts.utils import get_fiscal_year
from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen
from erpnext.utilities.regional import temporary_flag from erpnext.utilities.regional import temporary_flag
try:
from frappe.contacts.doctype.address.address import render_address as _render_address
except ImportError:
# Older frappe versions where this function is not available
from frappe.contacts.doctype.address.address import get_address_display as _render_address
PURCHASE_TRANSACTION_TYPES = { PURCHASE_TRANSACTION_TYPES = {
"Supplier Quotation", "Supplier Quotation",
"Purchase Order", "Purchase Order",
@@ -987,10 +993,4 @@ def add_party_account(party_type, party, company, account):
def render_address(address, check_permissions=True): def render_address(address, check_permissions=True):
try: return frappe.call(_render_address, address, check_permissions=check_permissions)
from frappe.contacts.doctype.address.address import render_address as _render
except ImportError:
# Older frappe versions where this function is not available
from frappe.contacts.doctype.address.address import get_address_display as _render
return frappe.call(_render, address, check_permissions=check_permissions)

View File

@@ -74,19 +74,13 @@ class SellingController(StockController):
if customer: if customer:
from erpnext.accounts.party import _get_party_details from erpnext.accounts.party import _get_party_details
fetch_payment_terms_template = False
if self.get("__islocal") or self.company != frappe.db.get_value(
self.doctype, self.name, "company"
):
fetch_payment_terms_template = True
party_details = _get_party_details( party_details = _get_party_details(
customer, customer,
ignore_permissions=self.flags.ignore_permissions, ignore_permissions=self.flags.ignore_permissions,
doctype=self.doctype, doctype=self.doctype,
company=self.company, company=self.company,
posting_date=self.get("posting_date"), posting_date=self.get("posting_date"),
fetch_payment_terms_template=fetch_payment_terms_template, fetch_payment_terms_template=self.has_value_changed("company"),
party_address=self.customer_address, party_address=self.customer_address,
shipping_address=self.shipping_address_name, shipping_address=self.shipping_address_name,
company_address=self.get("company_address"), company_address=self.get("company_address"),

View File

@@ -257,11 +257,11 @@ def validate_uom_is_integer(doc, uom_field, qty_fields, child_dt=None):
if isinstance(qty_fields, str): if isinstance(qty_fields, str):
qty_fields = [qty_fields] qty_fields = [qty_fields]
distinct_uoms = list(set(d.get(uom_field) for d in doc.get_all_children())) distinct_uoms = tuple(set(uom for uom in (d.get(uom_field) for d in doc.get_all_children()) if uom))
integer_uoms = list( integer_uoms = set(
filter( d[0]
lambda uom: frappe.db.get_value("UOM", uom, "must_be_whole_number", cache=True) or None, for d in frappe.db.get_values(
distinct_uoms, "UOM", (("name", "in", distinct_uoms), ("must_be_whole_number", "=", 1)), cache=True
) )
) )