Skip to content

Commit

Permalink
Merge pull request #44443 from sagarvora/minor-perfs
Browse files Browse the repository at this point in the history
perf: reduce queries during transaction save
  • Loading branch information
sagarvora authored Nov 29, 2024
2 parents 9ee4f58 + b6b8a06 commit 279dcab
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
14 changes: 7 additions & 7 deletions erpnext/accounts/party.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,12 @@
from erpnext.exceptions import InvalidAccountCurrency, PartyDisabled, PartyFrozen
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 = {
"Supplier Quotation",
"Purchase Order",
Expand Down Expand Up @@ -987,10 +993,4 @@ def add_party_account(party_type, party, company, account):


def render_address(address, check_permissions=True):
try:
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)
return frappe.call(_render_address, address, check_permissions=check_permissions)
8 changes: 1 addition & 7 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,19 +74,13 @@ def set_missing_lead_customer_details(self, for_validate=False):
if customer:
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(
customer,
ignore_permissions=self.flags.ignore_permissions,
doctype=self.doctype,
company=self.company,
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,
shipping_address=self.shipping_address_name,
company_address=self.get("company_address"),
Expand Down
10 changes: 5 additions & 5 deletions erpnext/utilities/transaction_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,11 @@ def validate_uom_is_integer(doc, uom_field, qty_fields, child_dt=None):
if isinstance(qty_fields, str):
qty_fields = [qty_fields]

distinct_uoms = list(set(d.get(uom_field) for d in doc.get_all_children()))
integer_uoms = list(
filter(
lambda uom: frappe.db.get_value("UOM", uom, "must_be_whole_number", cache=True) or None,
distinct_uoms,
distinct_uoms = tuple(set(uom for uom in (d.get(uom_field) for d in doc.get_all_children()) if uom))
integer_uoms = set(
d[0]
for d in frappe.db.get_values(
"UOM", (("name", "in", distinct_uoms), ("must_be_whole_number", "=", 1)), cache=True
)
)

Expand Down

0 comments on commit 279dcab

Please sign in to comment.