perf: use cached selling settings (#47949)

* perf: Use cached stock repost settings

* perf: Use cached selling settings
This commit is contained in:
Ankush Menat
2025-06-06 19:40:12 +05:30
committed by GitHub
parent 7d88d9dd4d
commit 73746e2c71
17 changed files with 35 additions and 41 deletions

View File

@@ -495,7 +495,7 @@ class SalesInvoice(SellingController):
self.update_time_sheet(self.name)
if frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction":
if frappe.get_settings("Selling Settings", "sales_update_frequency") == "Each Transaction":
update_company_current_month_sales(self.company)
self.update_project()
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
@@ -611,7 +611,7 @@ class SalesInvoice(SellingController):
if self.coupon_code:
update_coupon_code_count(self.coupon_code, "cancelled")
if frappe.db.get_single_value("Selling Settings", "sales_update_frequency") == "Each Transaction":
if frappe.get_settings("Selling Settings", "sales_update_frequency") == "Each Transaction":
update_company_current_month_sales(self.company)
self.update_project()
if not self.is_return and not self.is_consolidated and self.loyalty_program:
@@ -1016,7 +1016,7 @@ class SalesInvoice(SellingController):
)
if (
cint(frappe.db.get_single_value("Selling Settings", "maintain_same_sales_rate"))
cint(frappe.get_settings("Selling Settings", "maintain_same_sales_rate"))
and not self.is_return
and not self.is_internal_customer
):
@@ -1063,7 +1063,7 @@ class SalesInvoice(SellingController):
"Delivery Note": ["dn_required", "update_stock"],
}
for key, value in prev_doc_field_map.items():
if frappe.db.get_single_value("Selling Settings", value[0]) == "Yes":
if frappe.get_settings("Selling Settings", value[0]) == "Yes":
if frappe.get_value("Customer", self.customer, value[0]):
continue
@@ -1466,7 +1466,7 @@ class SalesInvoice(SellingController):
def make_tax_gl_entries(self, gl_entries):
enable_discount_accounting = cint(
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
frappe.get_settings("Selling Settings", "enable_discount_accounting")
)
for tax in self.get("taxes"):
@@ -1516,7 +1516,7 @@ class SalesInvoice(SellingController):
def make_item_gl_entries(self, gl_entries):
# income account gl entries
enable_discount_accounting = cint(
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
frappe.get_settings("Selling Settings", "enable_discount_accounting")
)
for item in self.get("items"):
@@ -1591,7 +1591,7 @@ class SalesInvoice(SellingController):
def enable_discount_accounting(self):
if not hasattr(self, "_enable_discount_accounting"):
self._enable_discount_accounting = cint(
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
frappe.get_settings("Selling Settings", "enable_discount_accounting")
)
return self._enable_discount_accounting

View File

@@ -9,7 +9,7 @@ from frappe.utils import getdate
def execute(filters=None):
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
party_naming_by = frappe.get_settings("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")

View File

@@ -10,7 +10,7 @@ from erpnext.accounts.utils import get_fiscal_year
def execute(filters=None):
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
party_naming_by = frappe.get_settings("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")

View File

@@ -256,7 +256,7 @@ def is_party_name_visible(filters):
if filters.get("party_type") in ["Customer", "Supplier"]:
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
party_naming_by = frappe.get_settings("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")

View File

@@ -1962,7 +1962,7 @@ class AccountsController(TransactionBase):
def make_discount_gl_entries(self, gl_entries):
enable_discount_accounting = cint(
frappe.db.get_single_value("Selling Settings", "enable_discount_accounting")
frappe.get_settings("Selling Settings", "enable_discount_accounting")
)
if enable_discount_accounting:

View File

@@ -255,9 +255,7 @@ class SellingController(StockController):
title=_("Invalid Selling Price"),
)
if self.get("is_return") or not frappe.db.get_single_value(
"Selling Settings", "validate_selling_price"
):
if self.get("is_return") or not frappe.get_settings("Selling Settings", "validate_selling_price"):
return
is_internal_customer = self.get("is_internal_customer")
@@ -717,7 +715,7 @@ class SellingController(StockController):
def validate_for_duplicate_items(self):
check_list, chk_dupl_itm = [], []
if cint(frappe.db.get_single_value("Selling Settings", "allow_multiple_items")):
if cint(frappe.get_settings("Selling Settings", "allow_multiple_items")):
return
if self.doctype == "Sales Invoice" and self.is_consolidated:
return

View File

@@ -266,7 +266,7 @@ class StatusUpdater(Document):
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"):
frappe.throw(_("For an item {0}, quantity must be negative number").format(d.item_code))
if not frappe.db.get_single_value("Selling Settings", "allow_negative_rates_for_items"):
if not frappe.get_settings("Selling Settings", "allow_negative_rates_for_items"):
if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
frappe.throw(
_(

View File

@@ -1379,9 +1379,7 @@ class StockController(AccountsController):
force = True
if force or future_sle_exists(args) or repost_required_for_queue(self):
item_based_reposting = cint(
frappe.db.get_single_value("Stock Reposting Settings", "item_based_reposting")
)
item_based_reposting = frappe.get_settings("Stock Reposting Settings", "item_based_reposting")
if item_based_reposting:
create_item_wise_repost_entries(
voucher_type=self.doctype,
@@ -1673,7 +1671,7 @@ def is_reposting_pending():
def future_sle_exists(args, sl_entries=None, allow_force_reposting=True):
from erpnext.stock.utils import get_combine_datetime
if allow_force_reposting and frappe.db.get_single_value(
if allow_force_reposting and frappe.get_settings(
"Stock Reposting Settings", "do_reposting_for_each_stock_transaction"
):
return True

View File

@@ -680,7 +680,7 @@ def send_project_status_email_to_users():
def update_project_sales_billing():
sales_update_frequency = frappe.db.get_single_value("Selling Settings", "sales_update_frequency")
sales_update_frequency = frappe.get_settings("Selling Settings", "sales_update_frequency")
if sales_update_frequency == "Each Transaction":
return
elif sales_update_frequency == "Monthly" and frappe.utils.now_datetime().day != 1:

View File

@@ -167,7 +167,7 @@ class Quotation(SellingController):
"""
If permitted in settings and any item has 0 qty, the SO has unit price items.
"""
if not frappe.db.get_single_value("Selling Settings", "allow_zero_qty_in_quotation"):
if not frappe.get_settings("Selling Settings", "allow_zero_qty_in_quotation"):
return
self.has_unit_price_items = any(

View File

@@ -253,7 +253,7 @@ class SalesOrder(SellingController):
"""
If permitted in settings and any item has 0 qty, the SO has unit price items.
"""
if not frappe.db.get_single_value("Selling Settings", "allow_zero_qty_in_sales_order"):
if not frappe.get_settings("Selling Settings", "allow_zero_qty_in_sales_order"):
return
self.has_unit_price_items = any(
@@ -279,9 +279,7 @@ class SalesOrder(SellingController):
(self.po_no, self.name, self.customer),
)
if so and so[0][0]:
if cint(
frappe.db.get_single_value("Selling Settings", "allow_against_multiple_purchase_orders")
):
if cint(frappe.get_settings("Selling Settings", "allow_against_multiple_purchase_orders")):
frappe.msgprint(
_(
"Warning: Sales Order {0} already exists against Customer's Purchase Order {1}"
@@ -405,7 +403,7 @@ class SalesOrder(SellingController):
}
)
if cint(frappe.db.get_single_value("Selling Settings", "maintain_same_sales_rate")):
if cint(frappe.get_settings("Selling Settings", "maintain_same_sales_rate")):
self.validate_rate_with_reference_doc([["Quotation", "prevdoc_docname", "quotation_item"]])
def update_enquiry_status(self, prevdoc, flag):
@@ -483,7 +481,7 @@ class SalesOrder(SellingController):
update_coupon_code_count(self.coupon_code, "cancelled")
def update_project(self):
if frappe.db.get_single_value("Selling Settings", "sales_update_frequency") != "Each Transaction":
if frappe.get_settings("Selling Settings", "sales_update_frequency") != "Each Transaction":
return
if self.project:
@@ -815,7 +813,7 @@ def get_list_context(context=None):
@frappe.whitelist()
def is_enable_cutoff_date_on_bulk_delivery_note_creation():
return frappe.db.get_single_value("Selling Settings", "enable_cutoff_date_on_bulk_delivery_note_creation")
return frappe.get_settings("Selling Settings", "enable_cutoff_date_on_bulk_delivery_note_creation")
@frappe.whitelist()

View File

@@ -13,7 +13,7 @@ def execute(filters=None):
if not filters:
filters = {}
# Check if customer id is according to naming series or customer name
customer_naming_type = frappe.db.get_single_value("Selling Settings", "cust_master_name")
customer_naming_type = frappe.get_settings("Selling Settings", "cust_master_name")
columns = get_columns(customer_naming_type)
data = []

View File

@@ -15,9 +15,9 @@ def boot_session(bootinfo):
if frappe.session["user"] != "Guest":
update_page_info(bootinfo)
bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory")
bootinfo.sysdefaults.customer_group = frappe.db.get_single_value("Selling Settings", "customer_group")
bootinfo.sysdefaults.use_server_side_reactivity = frappe.db.get_single_value(
bootinfo.sysdefaults.territory = frappe.get_settings("Selling Settings", "territory")
bootinfo.sysdefaults.customer_group = frappe.get_settings("Selling Settings", "customer_group")
bootinfo.sysdefaults.use_server_side_reactivity = frappe.get_settings(
"Selling Settings", "use_server_side_reactivity"
)
bootinfo.sysdefaults.allow_stale = cint(frappe.get_settings("Accounts Settings", "allow_stale"))
@@ -30,7 +30,7 @@ def boot_session(bootinfo):
)
bootinfo.sysdefaults.allow_sales_order_creation_for_expired_quotation = cint(
frappe.db.get_single_value("Selling Settings", "allow_sales_order_creation_for_expired_quotation")
frappe.get_settings("Selling Settings", "allow_sales_order_creation_for_expired_quotation")
)
# if no company, show a dialog box to create a new company

View File

@@ -247,7 +247,7 @@ class DeliveryNote(SellingController):
def so_required(self):
"""check in manage account if sales order required or not"""
if frappe.db.get_single_value("Selling Settings", "so_required") == "Yes":
if frappe.get_settings("Selling Settings", "so_required") == "Yes":
for d in self.get("items"):
if not d.against_sales_order:
frappe.throw(_("Sales Order required for Item {0}").format(d.item_code))
@@ -314,7 +314,7 @@ class DeliveryNote(SellingController):
)
if (
cint(frappe.db.get_single_value("Selling Settings", "maintain_same_sales_rate"))
cint(frappe.get_settings("Selling Settings", "maintain_same_sales_rate"))
and not self.is_return
and not self.is_internal_customer
):

View File

@@ -243,9 +243,9 @@ class Item(Document):
def add_price(self, price_list=None):
"""Add a new price"""
if not price_list:
price_list = frappe.db.get_single_value(
"Selling Settings", "selling_price_list"
) or frappe.db.get_value("Price List", _("Standard Selling"))
price_list = frappe.get_settings("Selling Settings", "selling_price_list") or frappe.db.get_value(
"Price List", _("Standard Selling")
)
if price_list:
item_price = frappe.get_doc(
{

View File

@@ -69,7 +69,7 @@ def make_packing_list(doc):
return
parent_items_price, reset = {}, False
set_price_from_children = frappe.db.get_single_value("Selling Settings", "editable_bundle_item_rates")
set_price_from_children = frappe.get_settings("Selling Settings", "editable_bundle_item_rates")
stale_packed_items_table = get_indexed_packed_items_table(doc)

View File

@@ -39,7 +39,7 @@ class PriceList(Document):
def set_default_if_missing(self):
if cint(self.selling):
if not frappe.db.get_single_value("Selling Settings", "selling_price_list"):
if not frappe.get_settings("Selling Settings", "selling_price_list"):
frappe.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.name)
elif cint(self.buying):