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) 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) update_company_current_month_sales(self.company)
self.update_project() self.update_project()
update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference) update_linked_doc(self.doctype, self.name, self.inter_company_invoice_reference)
@@ -611,7 +611,7 @@ class SalesInvoice(SellingController):
if self.coupon_code: if self.coupon_code:
update_coupon_code_count(self.coupon_code, "cancelled") 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) update_company_current_month_sales(self.company)
self.update_project() self.update_project()
if not self.is_return and not self.is_consolidated and self.loyalty_program: if not self.is_return and not self.is_consolidated and self.loyalty_program:
@@ -1016,7 +1016,7 @@ class SalesInvoice(SellingController):
) )
if ( 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_return
and not self.is_internal_customer and not self.is_internal_customer
): ):
@@ -1063,7 +1063,7 @@ class SalesInvoice(SellingController):
"Delivery Note": ["dn_required", "update_stock"], "Delivery Note": ["dn_required", "update_stock"],
} }
for key, value in prev_doc_field_map.items(): 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]): if frappe.get_value("Customer", self.customer, value[0]):
continue continue
@@ -1466,7 +1466,7 @@ class SalesInvoice(SellingController):
def make_tax_gl_entries(self, gl_entries): def make_tax_gl_entries(self, gl_entries):
enable_discount_accounting = cint( 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"): for tax in self.get("taxes"):
@@ -1516,7 +1516,7 @@ class SalesInvoice(SellingController):
def make_item_gl_entries(self, gl_entries): def make_item_gl_entries(self, gl_entries):
# income account gl entries # income account gl entries
enable_discount_accounting = cint( 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"): for item in self.get("items"):
@@ -1591,7 +1591,7 @@ class SalesInvoice(SellingController):
def enable_discount_accounting(self): def enable_discount_accounting(self):
if not hasattr(self, "_enable_discount_accounting"): if not hasattr(self, "_enable_discount_accounting"):
self._enable_discount_accounting = cint( 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 return self._enable_discount_accounting

View File

@@ -9,7 +9,7 @@ from frappe.utils import getdate
def execute(filters=None): def execute(filters=None):
if filters.get("party_type") == "Customer": 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: else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name") 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): def execute(filters=None):
if filters.get("party_type") == "Customer": 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: else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name") 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") in ["Customer", "Supplier"]:
if filters.get("party_type") == "Customer": 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: else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name") 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): def make_discount_gl_entries(self, gl_entries):
enable_discount_accounting = cint( 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: if enable_discount_accounting:

View File

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

View File

@@ -266,7 +266,7 @@ class StatusUpdater(Document):
if hasattr(d, "qty") and d.qty > 0 and self.get("is_return"): 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)) 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: if hasattr(d, "item_code") and hasattr(d, "rate") and flt(d.rate) < 0:
frappe.throw( frappe.throw(
_( _(

View File

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

View File

@@ -680,7 +680,7 @@ def send_project_status_email_to_users():
def update_project_sales_billing(): 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": if sales_update_frequency == "Each Transaction":
return return
elif sales_update_frequency == "Monthly" and frappe.utils.now_datetime().day != 1: 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 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 return
self.has_unit_price_items = any( 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 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 return
self.has_unit_price_items = any( self.has_unit_price_items = any(
@@ -279,9 +279,7 @@ class SalesOrder(SellingController):
(self.po_no, self.name, self.customer), (self.po_no, self.name, self.customer),
) )
if so and so[0][0]: if so and so[0][0]:
if cint( if cint(frappe.get_settings("Selling Settings", "allow_against_multiple_purchase_orders")):
frappe.db.get_single_value("Selling Settings", "allow_against_multiple_purchase_orders")
):
frappe.msgprint( frappe.msgprint(
_( _(
"Warning: Sales Order {0} already exists against Customer's Purchase Order {1}" "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"]]) self.validate_rate_with_reference_doc([["Quotation", "prevdoc_docname", "quotation_item"]])
def update_enquiry_status(self, prevdoc, flag): def update_enquiry_status(self, prevdoc, flag):
@@ -483,7 +481,7 @@ class SalesOrder(SellingController):
update_coupon_code_count(self.coupon_code, "cancelled") update_coupon_code_count(self.coupon_code, "cancelled")
def update_project(self): 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 return
if self.project: if self.project:
@@ -815,7 +813,7 @@ def get_list_context(context=None):
@frappe.whitelist() @frappe.whitelist()
def is_enable_cutoff_date_on_bulk_delivery_note_creation(): 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() @frappe.whitelist()

View File

@@ -13,7 +13,7 @@ def execute(filters=None):
if not filters: if not filters:
filters = {} filters = {}
# Check if customer id is according to naming series or customer name # 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) columns = get_columns(customer_naming_type)
data = [] data = []

View File

@@ -15,9 +15,9 @@ def boot_session(bootinfo):
if frappe.session["user"] != "Guest": if frappe.session["user"] != "Guest":
update_page_info(bootinfo) update_page_info(bootinfo)
bootinfo.sysdefaults.territory = frappe.db.get_single_value("Selling Settings", "territory") bootinfo.sysdefaults.territory = frappe.get_settings("Selling Settings", "territory")
bootinfo.sysdefaults.customer_group = frappe.db.get_single_value("Selling Settings", "customer_group") bootinfo.sysdefaults.customer_group = frappe.get_settings("Selling Settings", "customer_group")
bootinfo.sysdefaults.use_server_side_reactivity = frappe.db.get_single_value( bootinfo.sysdefaults.use_server_side_reactivity = frappe.get_settings(
"Selling Settings", "use_server_side_reactivity" "Selling Settings", "use_server_side_reactivity"
) )
bootinfo.sysdefaults.allow_stale = cint(frappe.get_settings("Accounts Settings", "allow_stale")) 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( 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 # 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): def so_required(self):
"""check in manage account if sales order required or not""" """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"): for d in self.get("items"):
if not d.against_sales_order: if not d.against_sales_order:
frappe.throw(_("Sales Order required for Item {0}").format(d.item_code)) frappe.throw(_("Sales Order required for Item {0}").format(d.item_code))
@@ -314,7 +314,7 @@ class DeliveryNote(SellingController):
) )
if ( 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_return
and not self.is_internal_customer and not self.is_internal_customer
): ):

View File

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

View File

@@ -69,7 +69,7 @@ def make_packing_list(doc):
return return
parent_items_price, reset = {}, False 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) 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): def set_default_if_missing(self):
if cint(self.selling): 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) frappe.set_value("Selling Settings", "Selling Settings", "selling_price_list", self.name)
elif cint(self.buying): elif cint(self.buying):