From ea5c2c454b9e302f3fe3dca934cc276cc139e0fd Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Fri, 6 Jun 2025 18:54:49 +0530 Subject: [PATCH] perf: use cached stock settings (#47945) --- erpnext/controllers/buying_controller.py | 4 ++-- erpnext/controllers/queries.py | 2 +- erpnext/controllers/selling_controller.py | 6 +++--- erpnext/controllers/status_updater.py | 2 +- erpnext/controllers/stock_controller.py | 12 +++++------- erpnext/controllers/subcontracting_controller.py | 2 +- .../selling/doctype/sales_order/sales_order.py | 10 +++++----- erpnext/stock/doctype/batch/batch.py | 6 +++--- erpnext/stock/doctype/item/item.py | 16 ++++++---------- erpnext/stock/doctype/packed_item/packed_item.py | 2 +- erpnext/stock/doctype/pick_list/pick_list.py | 4 ++-- .../doctype/purchase_receipt/purchase_receipt.py | 8 +++----- .../serial_and_batch_bundle.py | 6 ++---- erpnext/stock/doctype/stock_entry/stock_entry.py | 8 ++++---- .../stock_ledger_entry/stock_ledger_entry.py | 2 +- .../stock_reservation_entry.py | 12 +++++------- erpnext/stock/get_item_details.py | 6 +++--- erpnext/stock/serial_batch_bundle.py | 16 ++++++---------- erpnext/stock/stock_balance.py | 2 +- erpnext/stock/utils.py | 2 +- 20 files changed, 56 insertions(+), 72 deletions(-) diff --git a/erpnext/controllers/buying_controller.py b/erpnext/controllers/buying_controller.py index 5a6e1f78178..4fc8c581532 100644 --- a/erpnext/controllers/buying_controller.py +++ b/erpnext/controllers/buying_controller.py @@ -75,7 +75,7 @@ class BuyingController(SubcontractingController): if self.docstatus == 1 and self.doctype in ["Purchase Receipt", "Purchase Invoice"]: self.set_onload( "allow_to_make_qc_after_submission", - frappe.db.get_single_value( + frappe.get_settings( "Stock Settings", "allow_to_make_quality_inspection_after_purchase_or_delivery" ), ) @@ -545,7 +545,7 @@ class BuyingController(SubcontractingController): item.bom = None def set_qty_as_per_stock_uom(self): - allow_to_edit_stock_qty = frappe.db.get_single_value( + allow_to_edit_stock_qty = frappe.get_settings( "Stock Settings", "allow_to_edit_stock_uom_qty_for_purchase" ) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index c5d4b0b3418..44eebf8981c 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -948,7 +948,7 @@ def get_filtered_child_rows(doctype, txt, searchfield, start, page_len, filters) @frappe.whitelist() @frappe.validate_and_sanitize_search_inputs def get_item_uom_query(doctype, txt, searchfield, start, page_len, filters): - if frappe.db.get_single_value("Stock Settings", "allow_uom_with_conversion_rate_defined_in_item"): + if frappe.get_settings("Stock Settings", "allow_uom_with_conversion_rate_defined_in_item"): query_filters = {"parent": filters.get("item_code")} if txt: diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 9a70f6c3636..2d2d163b737 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -38,7 +38,7 @@ class SellingController(StockController): if self.docstatus == 1 and self.doctype in ["Delivery Note", "Sales Invoice"]: self.set_onload( "allow_to_make_qc_after_submission", - frappe.db.get_single_value( + frappe.get_settings( "Stock Settings", "allow_to_make_quality_inspection_after_purchase_or_delivery" ), ) @@ -224,7 +224,7 @@ class SellingController(StockController): frappe.throw(_("Maximum discount for Item {0} is {1}%").format(d.item_code, discount)) def set_qty_as_per_stock_uom(self): - allow_to_edit_stock_qty = frappe.db.get_single_value( + allow_to_edit_stock_qty = frappe.get_settings( "Stock Settings", "allow_to_edit_stock_uom_qty_for_sales" ) @@ -960,7 +960,7 @@ def get_serial_and_batch_bundle(child, parent, delivery_note_child=None): if child.get("use_serial_batch_fields"): return - if not frappe.db.get_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"): + if not frappe.get_settings("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"): return item_details = frappe.db.get_value("Item", child.item_code, ["has_serial_no", "has_batch_no"], as_dict=1) diff --git a/erpnext/controllers/status_updater.py b/erpnext/controllers/status_updater.py index 39acbac6d5e..9e02b2ba0f4 100644 --- a/erpnext/controllers/status_updater.py +++ b/erpnext/controllers/status_updater.py @@ -336,7 +336,7 @@ class StatusUpdater(Document): qty_or_amount, ) - role_allowed_to_over_deliver_receive = frappe.db.get_single_value( + role_allowed_to_over_deliver_receive = frappe.get_settings( "Stock Settings", "role_allowed_to_over_deliver_receive" ) role_allowed_to_over_bill = frappe.db.get_single_value( diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index 61b0aabbe69..cb23f0ab7f6 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -518,7 +518,7 @@ class StockController(AccountsController): ) def set_use_serial_batch_fields(self): - if frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields"): + if frappe.get_settings("Stock Settings", "use_serial_batch_fields"): for row in self.items: row.use_serial_batch_fields = 1 @@ -1076,7 +1076,7 @@ class StockController(AccountsController): "Purchase Invoice", "Sales Invoice", "Delivery Note", - ] and frappe.db.get_single_value( + ] and frappe.get_settings( "Stock Settings", "allow_to_make_quality_inspection_after_purchase_or_delivery" ): return @@ -1092,7 +1092,7 @@ class StockController(AccountsController): def validate_qi_submission(self, row): """Check if QI is submitted on row level, during submission""" - action = frappe.db.get_single_value("Stock Settings", "action_if_quality_inspection_is_not_submitted") + action = frappe.get_settings("Stock Settings", "action_if_quality_inspection_is_not_submitted") qa_docstatus = frappe.db.get_value("Quality Inspection", row.quality_inspection, "docstatus") if qa_docstatus != 1: @@ -1107,7 +1107,7 @@ class StockController(AccountsController): def validate_qi_rejection(self, row): """Check if QI is rejected on row level, during submission""" - action = frappe.db.get_single_value("Stock Settings", "action_if_quality_inspection_is_rejected") + action = frappe.get_settings("Stock Settings", "action_if_quality_inspection_is_rejected") qa_status = frappe.db.get_value("Quality Inspection", row.quality_inspection, "status") if qa_status == "Rejected": @@ -1206,9 +1206,7 @@ class StockController(AccountsController): item_wise_received_qty = self.get_item_wise_inter_received_qty() precision = frappe.get_precision(self.doctype + " Item", "qty") - over_receipt_allowance = frappe.db.get_single_value( - "Stock Settings", "over_delivery_receipt_allowance" - ) + over_receipt_allowance = frappe.get_settings("Stock Settings", "over_delivery_receipt_allowance") parent_doctype = { "Purchase Receipt": "Delivery Note", diff --git a/erpnext/controllers/subcontracting_controller.py b/erpnext/controllers/subcontracting_controller.py index 7244787e144..81b803488b7 100644 --- a/erpnext/controllers/subcontracting_controller.py +++ b/erpnext/controllers/subcontracting_controller.py @@ -590,7 +590,7 @@ class SubcontractingController(StockController): rm_obj.reference_name = item_row.name - use_serial_batch_fields = frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields") + use_serial_batch_fields = frappe.get_settings("Stock Settings", "use_serial_batch_fields") if self.doctype == self.subcontract_data.order_doctype: rm_obj.required_qty = flt(qty, rm_obj.precision("required_qty")) diff --git a/erpnext/selling/doctype/sales_order/sales_order.py b/erpnext/selling/doctype/sales_order/sales_order.py index 03cdc6e8c3b..68a371b4f2f 100755 --- a/erpnext/selling/doctype/sales_order/sales_order.py +++ b/erpnext/selling/doctype/sales_order/sales_order.py @@ -195,7 +195,7 @@ class SalesOrder(SellingController): def onload(self) -> None: super().onload() - if frappe.db.get_single_value("Stock Settings", "enable_stock_reservation"): + if frappe.get_settings("Stock Settings", "enable_stock_reservation"): if self.has_unreserved_stock(): self.set_onload("has_unreserved_stock", True) @@ -246,7 +246,7 @@ class SalesOrder(SellingController): self.enable_auto_reserve_stock() def enable_auto_reserve_stock(self): - if self.is_new() and frappe.db.get_single_value("Stock Settings", "auto_reserve_stock"): + if self.is_new() and frappe.get_settings("Stock Settings", "auto_reserve_stock"): self.reserve_stock = 1 def set_has_unit_price_items(self): @@ -633,7 +633,7 @@ class SalesOrder(SellingController): if total_picked_qty and total_qty: per_picked = total_picked_qty / total_qty * 100 - pick_percentage = frappe.db.get_single_value("Stock Settings", "over_picking_allowance") + pick_percentage = frappe.get_settings("Stock Settings", "over_picking_allowance") if pick_percentage: total_qty += flt(total_qty) * (pick_percentage / 100) @@ -729,7 +729,7 @@ class SalesOrder(SellingController): def validate_reserved_stock(self): """Clean reserved stock flag for non-stock Item""" - enable_stock_reservation = frappe.db.get_single_value("Stock Settings", "enable_stock_reservation") + enable_stock_reservation = frappe.get_settings("Stock Settings", "enable_stock_reservation") for item in self.items: if item.reserve_stock and (not enable_stock_reservation or not cint(item.is_stock_item)): @@ -1861,4 +1861,4 @@ def get_work_order_items(sales_order, for_raw_material_request=0): @frappe.whitelist() def get_stock_reservation_status(): - return frappe.db.get_single_value("Stock Settings", "enable_stock_reservation") + return frappe.get_settings("Stock Settings", "enable_stock_reservation") diff --git a/erpnext/stock/doctype/batch/batch.py b/erpnext/stock/doctype/batch/batch.py index c7d9823d144..1a0557a5a0a 100644 --- a/erpnext/stock/doctype/batch/batch.py +++ b/erpnext/stock/doctype/batch/batch.py @@ -37,7 +37,7 @@ def batch_uses_naming_series(): Verify if the Batch is to be named using a naming series :return: bool """ - use_naming_series = cint(frappe.db.get_single_value("Stock Settings", "use_naming_series")) + use_naming_series = cint(frappe.get_settings("Stock Settings", "use_naming_series")) return bool(use_naming_series) @@ -49,7 +49,7 @@ def _get_batch_prefix(): is set to use naming series. :return: The naming series. """ - naming_series_prefix = frappe.db.get_single_value("Stock Settings", "naming_series_prefix") + naming_series_prefix = frappe.get_settings("Stock Settings", "naming_series_prefix") if not naming_series_prefix: naming_series_prefix = "BATCH-" @@ -160,7 +160,7 @@ class Batch(Document): from erpnext.stock.utils import get_valuation_method if self.is_new(): - if get_valuation_method(self.item) == "Moving Average" and frappe.db.get_single_value( + if get_valuation_method(self.item) == "Moving Average" and frappe.get_settings( "Stock Settings", "do_not_use_batchwise_valuation" ): self.use_batchwise_valuation = 0 diff --git a/erpnext/stock/doctype/item/item.py b/erpnext/stock/doctype/item/item.py index c41c0528834..3789514589a 100644 --- a/erpnext/stock/doctype/item/item.py +++ b/erpnext/stock/doctype/item/item.py @@ -227,7 +227,7 @@ class Item(Document): def validate_description(self): """Clean HTML description if set""" if ( - cint(frappe.db.get_single_value("Stock Settings", "clean_description_html")) + cint(frappe.get_settings("Stock Settings", "clean_description_html")) and self.description != self.item_name # perf: Avoid cleaning up a fallback ): self.description = clean_html(self.description) @@ -274,7 +274,7 @@ class Item(Document): for default in self.item_defaults or [ frappe._dict({"company": frappe.defaults.get_defaults().company}) ]: - default_warehouse = default.default_warehouse or frappe.db.get_single_value( + default_warehouse = default.default_warehouse or frappe.get_settings( "Stock Settings", "default_warehouse" ) if default_warehouse: @@ -317,9 +317,7 @@ class Item(Document): ) def validate_retain_sample(self): - if self.retain_sample and not frappe.db.get_single_value( - "Stock Settings", "sample_retention_warehouse" - ): + if self.retain_sample and not frappe.get_settings("Stock Settings", "sample_retention_warehouse"): frappe.throw(_("Please select Sample Retention Warehouse in Stock Settings first")) if self.retain_sample and not self.has_batch_no: frappe.throw( @@ -664,7 +662,7 @@ class Item(Document): def recalculate_bin_qty(self, new_name): from erpnext.stock.stock_balance import repost_stock - existing_allow_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock") + existing_allow_negative_stock = frappe.get_settings("Stock Settings", "allow_negative_stock") frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1) repost_stock_for_warehouses = frappe.get_all( @@ -963,9 +961,7 @@ class Item(Document): return if not values.get("valuation_method") and self.get("valuation_method"): - values["valuation_method"] = ( - frappe.db.get_single_value("Stock Settings", "valuation_method") or "FIFO" - ) + values["valuation_method"] = frappe.get_settings("Stock Settings", "valuation_method") or "FIFO" changed_fields = [ field for field in restricted_fields if cstr(self.get(field)) != cstr(values.get(field)) @@ -1051,7 +1047,7 @@ class Item(Document): def validate_auto_reorder_enabled_in_stock_settings(self): if self.reorder_levels: - enabled = frappe.db.get_single_value("Stock Settings", "auto_indent") + enabled = frappe.get_settings("Stock Settings", "auto_indent") if not enabled: frappe.msgprint( msg=_("You have to enable auto re-order in Stock Settings to maintain re-order levels."), diff --git a/erpnext/stock/doctype/packed_item/packed_item.py b/erpnext/stock/doctype/packed_item/packed_item.py index ee5d330a221..2dc28b1f04b 100644 --- a/erpnext/stock/doctype/packed_item/packed_item.py +++ b/erpnext/stock/doctype/packed_item/packed_item.py @@ -234,7 +234,7 @@ def update_packed_item_stock_data(main_item_row, pi_row, packing_item, item_data bin = get_packed_item_bin_qty(packing_item.item_code, pi_row.warehouse) pi_row.actual_qty = flt(bin.get("actual_qty")) pi_row.projected_qty = flt(bin.get("projected_qty")) - pi_row.use_serial_batch_fields = frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields") + pi_row.use_serial_batch_fields = frappe.get_settings("Stock Settings", "use_serial_batch_fields") def update_packed_item_price_data(pi_row, item_data, doc): diff --git a/erpnext/stock/doctype/pick_list/pick_list.py b/erpnext/stock/doctype/pick_list/pick_list.py index a80a59a822d..38005a12d38 100644 --- a/erpnext/stock/doctype/pick_list/pick_list.py +++ b/erpnext/stock/doctype/pick_list/pick_list.py @@ -440,7 +440,7 @@ class PickList(Document): def validate_picked_qty(self, data): over_delivery_receipt_allowance = 100 + flt( - frappe.db.get_single_value("Stock Settings", "over_delivery_receipt_allowance") + frappe.get_settings("Stock Settings", "over_delivery_receipt_allowance") ) for row in data: @@ -1102,7 +1102,7 @@ def get_available_item_locations_for_batched_item( { "item_code": item_code, "warehouse": from_warehouses, - "based_on": frappe.db.get_single_value("Stock Settings", "pick_serial_and_batch_based_on"), + "based_on": frappe.get_settings("Stock Settings", "pick_serial_and_batch_based_on"), } ) ) diff --git a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py index fc71d0cbbd8..802cdafa4f6 100644 --- a/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py +++ b/erpnext/stock/doctype/purchase_receipt/purchase_receipt.py @@ -952,10 +952,8 @@ class PurchaseReceipt(BuyingController): def reserve_stock_for_sales_order(self): if ( self.is_return - or not frappe.db.get_single_value("Stock Settings", "enable_stock_reservation") - or not frappe.db.get_single_value( - "Stock Settings", "auto_reserve_stock_for_sales_order_on_purchase" - ) + or not frappe.get_settings("Stock Settings", "enable_stock_reservation") + or not frappe.get_settings("Stock Settings", "auto_reserve_stock_for_sales_order_on_purchase") ): return @@ -990,7 +988,7 @@ class PurchaseReceipt(BuyingController): ) def reserve_stock_for_production_plan(self): - if self.is_return or not frappe.db.get_single_value("Stock Settings", "enable_stock_reservation"): + if self.is_return or not frappe.get_settings("Stock Settings", "enable_stock_reservation"): return production_plan_references = self.get_production_plan_references() diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index eca75bfb71d..5e671b2b38c 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -84,9 +84,7 @@ class SerialandBatchBundle(Document): # end: auto-generated types def autoname(self): - if frappe.db.get_single_value( - "Stock Settings", "set_serial_and_batch_bundle_naming_based_on_naming_series" - ): + if frappe.get_settings("Stock Settings", "set_serial_and_batch_bundle_naming_based_on_naming_series"): if not self.naming_series: frappe.throw(_("Naming Series is mandatory")) @@ -161,7 +159,7 @@ class SerialandBatchBundle(Document): if self.type_of_transaction == "Outward" or not self.has_serial_no: return - if frappe.db.get_single_value("Stock Settings", "allow_existing_serial_no"): + if frappe.get_settings("Stock Settings", "allow_existing_serial_no"): return if self.voucher_type not in ["Purchase Receipt", "Purchase Invoice", "Stock Entry"]: diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 2f53badb937..ed1596f570c 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -2457,7 +2457,7 @@ class StockEntry(StockController): if not qty: return - use_serial_batch_fields = frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields") + use_serial_batch_fields = frappe.get_settings("Stock Settings", "use_serial_batch_fields") ste_item_details = { "from_warehouse": item.warehouse, @@ -2935,7 +2935,7 @@ def move_sample_to_retention_warehouse(company, items): if isinstance(items, str): items = json.loads(items) - retention_warehouse = frappe.db.get_single_value("Stock Settings", "sample_retention_warehouse") + retention_warehouse = frappe.get_settings("Stock Settings", "sample_retention_warehouse") stock_entry = frappe.new_doc("Stock Entry") stock_entry.company = company stock_entry.purpose = "Material Transfer" @@ -2986,7 +2986,7 @@ def make_stock_in_entry(source_name, target_doc=None): target.stock_entry_type = "Material Transfer" target.set_missing_values() - if not frappe.db.get_single_value("Stock Settings", "use_serial_batch_fields"): + if not frappe.get_settings("Stock Settings", "use_serial_batch_fields"): target.make_serial_and_batch_bundle_for_transfer() def update_item(source_doc, target_doc, source_parent): @@ -3215,7 +3215,7 @@ def validate_sample_quantity(item_code, sample_quantity, qty, batch_no=None): frappe.throw( _("Sample quantity {0} cannot be more than received quantity {1}").format(sample_quantity, qty) ) - retention_warehouse = frappe.db.get_single_value("Stock Settings", "sample_retention_warehouse") + retention_warehouse = frappe.get_settings("Stock Settings", "sample_retention_warehouse") retainted_qty = 0 if batch_no: retainted_qty = get_batch_qty(batch_no, retention_warehouse, item_code) diff --git a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py index 1b1e3bd3e4d..5709af5bf5f 100644 --- a/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py +++ b/erpnext/stock/doctype/stock_ledger_entry/stock_ledger_entry.py @@ -299,7 +299,7 @@ class StockLedgerEntry(Document): is_group_warehouse(self.warehouse) def validate_with_last_transaction_posting_time(self): - authorized_role = frappe.db.get_single_value( + authorized_role = frappe.get_settings( "Stock Settings", "role_allowed_to_create_edit_back_dated_transactions" ) if authorized_role: diff --git a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py index 81047bd6d09..07c02a0f86c 100644 --- a/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py +++ b/erpnext/stock/doctype/stock_reservation_entry/stock_reservation_entry.py @@ -162,7 +162,7 @@ class StockReservationEntry(Document): not self.from_voucher_type and (self.get("_action") == "submit") and (self.has_serial_no or self.has_batch_no) - and cint(frappe.db.get_single_value("Stock Settings", "auto_reserve_serial_and_batch")) + and cint(frappe.get_settings("Stock Settings", "auto_reserve_serial_and_batch")) ): from erpnext.stock.doctype.batch.batch import get_available_batches from erpnext.stock.doctype.serial_no.serial_no import get_serial_nos_for_outward @@ -176,7 +176,7 @@ class StockReservationEntry(Document): "warehouse": self.warehouse, "qty": abs(self.reserved_qty) or 0, "based_on": based_on - or frappe.db.get_single_value("Stock Settings", "pick_serial_and_batch_based_on"), + or frappe.get_settings("Stock Settings", "pick_serial_and_batch_based_on"), } ) @@ -219,9 +219,7 @@ class StockReservationEntry(Document): return if self.reservation_based_on == "Serial and Batch": - allow_partial_reservation = frappe.db.get_single_value( - "Stock Settings", "allow_partial_reservation" - ) + allow_partial_reservation = frappe.get_settings("Stock Settings", "allow_partial_reservation") available_serial_nos = [] if self.has_serial_no: @@ -570,7 +568,7 @@ class StockReservationEntry(Document): def validate_stock_reservation_settings(voucher: object) -> None: """Raises an exception if `Stock Reservation` is not enabled or `Voucher Type` is not allowed.""" - if not frappe.db.get_single_value("Stock Settings", "enable_stock_reservation"): + if not frappe.get_settings("Stock Settings", "enable_stock_reservation"): msg = _("Please enable {0} in the {1}.").format( frappe.bold(_("Stock Reservation")), frappe.bold(_("Stock Settings")), @@ -1347,7 +1345,7 @@ def create_stock_reservation_entries_for_so_items( validate_stock_reservation_settings(sales_order) - allow_partial_reservation = frappe.db.get_single_value("Stock Settings", "allow_partial_reservation") + allow_partial_reservation = frappe.get_settings("Stock Settings", "allow_partial_reservation") items = [] if items_details: diff --git a/erpnext/stock/get_item_details.py b/erpnext/stock/get_item_details.py index e8119f0c6bc..a5168a5176e 100644 --- a/erpnext/stock/get_item_details.py +++ b/erpnext/stock/get_item_details.py @@ -136,7 +136,7 @@ def get_item_details( out.update(data) if ( - frappe.db.get_single_value("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward") + frappe.get_settings("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward") and not ctx.get("serial_and_batch_bundle") and (ctx.get("use_serial_batch_fields") or ctx.get("doctype") == "POS Invoice") ): @@ -201,7 +201,7 @@ def update_stock(ctx, out, doc=None): { "item_code": ctx.item_code, "warehouse": ctx.warehouse, - "based_on": frappe.db.get_single_value("Stock Settings", "pick_serial_and_batch_based_on"), + "based_on": frappe.get_settings("Stock Settings", "pick_serial_and_batch_based_on"), } ) @@ -591,7 +591,7 @@ def get_item_warehouse_(ctx: ItemDetailsCtx, item, overwrite_warehouse, defaults warehouse = ctx.warehouse if not warehouse: - default_warehouse = frappe.db.get_single_value("Stock Settings", "default_warehouse") + default_warehouse = frappe.get_settings("Stock Settings", "default_warehouse") if frappe.db.get_value("Warehouse", default_warehouse, "company") == ctx.company: return default_warehouse diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index f06706ee21e..778accad396 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -151,14 +151,12 @@ class SerialBatchBundle: if ( self.item_details.has_batch_no and not self.item_details.batch_number_series - and not frappe.db.get_single_value("Stock Settings", "naming_series_prefix") + and not frappe.get_settings("Stock Settings", "naming_series_prefix") ): msg += f". If you want auto pick batch bundle, then kindly set Batch Number Series in Item {self.item_code}" elif self.sle.actual_qty < 0: - if not frappe.db.get_single_value( - "Stock Settings", "auto_create_serial_and_batch_bundle_for_outward" - ): + if not frappe.get_settings("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward"): msg += ". If you want auto pick serial/batch bundle, then kindly enable 'Auto Create Serial and Batch Bundle' in Stock Settings." if msg: @@ -187,7 +185,7 @@ class SerialBatchBundle: if self.sle.actual_qty < 0 and self.is_material_transfer(): values_to_update["valuation_rate"] = flt(sn_doc.avg_rate) - if not frappe.db.get_single_value( + if not frappe.get_settings( "Stock Settings", "do_not_update_serial_batch_on_creation_of_auto_bundle" ): if sn_doc.has_serial_no: @@ -253,9 +251,7 @@ class SerialBatchBundle: and ( self.item_details.create_new_batch or ( - frappe.db.get_single_value( - "Stock Settings", "auto_create_serial_and_batch_bundle_for_outward" - ) + frappe.get_settings("Stock Settings", "auto_create_serial_and_batch_bundle_for_outward") and self.sle.actual_qty < 0 ) ) @@ -724,7 +720,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): self.batchwise_valuation_batches = [] self.non_batchwise_valuation_batches = [] - if get_valuation_method(self.sle.item_code) == "Moving Average" and frappe.db.get_single_value( + if get_valuation_method(self.sle.item_code) == "Moving Average" and frappe.get_settings( "Stock Settings", "do_not_use_batchwise_valuation" ): self.non_batchwise_valuation_batches = self.batches @@ -1029,7 +1025,7 @@ class SerialBatchCreation: "item_code": self.item_code, "warehouse": self.warehouse, "qty": abs(self.actual_qty) if self.actual_qty else 0, - "based_on": frappe.db.get_single_value("Stock Settings", "pick_serial_and_batch_based_on"), + "based_on": frappe.get_settings("Stock Settings", "pick_serial_and_batch_based_on"), } ) diff --git a/erpnext/stock/stock_balance.py b/erpnext/stock/stock_balance.py index 45777172808..135b9097c12 100644 --- a/erpnext/stock/stock_balance.py +++ b/erpnext/stock/stock_balance.py @@ -15,7 +15,7 @@ def repost(only_actual=False, allow_negative_stock=False, allow_zero_rate=False, frappe.db.auto_commit_on_many_writes = 1 if allow_negative_stock: - existing_allow_negative_stock = frappe.db.get_single_value("Stock Settings", "allow_negative_stock") + existing_allow_negative_stock = frappe.get_settings("Stock Settings", "allow_negative_stock") frappe.db.set_single_value("Stock Settings", "allow_negative_stock", 1) item_warehouses = frappe.db.sql( diff --git a/erpnext/stock/utils.py b/erpnext/stock/utils.py index ab8f7a7d2dd..b85956a35fa 100644 --- a/erpnext/stock/utils.py +++ b/erpnext/stock/utils.py @@ -252,7 +252,7 @@ def get_incoming_rate(args, raise_error_if_no_rate=True): "Item", args.get("item_code"), ["has_serial_no", "has_batch_no"], as_dict=1 ) - use_moving_avg_for_batch = frappe.db.get_single_value("Stock Settings", "do_not_use_batchwise_valuation") + use_moving_avg_for_batch = frappe.get_settings("Stock Settings", "do_not_use_batchwise_valuation") if isinstance(args, dict): args = frappe._dict(args)