Merge pull request #47899 from frappe/cruft

perf: remove misc random cruft
This commit is contained in:
Ankush Menat
2025-06-05 22:48:07 +05:30
committed by GitHub
8 changed files with 31 additions and 28 deletions

View File

@@ -145,7 +145,7 @@ class Budget(Document):
def validate_expense_against_budget(args, expense_amount=0):
args = frappe._dict(args)
if not frappe.get_all("Budget", limit=1):
if not frappe.db.count("Budget", cache=True):
return
if args.get("company") and not args.fiscal_year:

View File

@@ -154,3 +154,7 @@ class CostCenterAllocation(Document):
).format(d.cost_center),
InvalidChildCostCenter,
)
def clear_cache(self):
frappe.clear_cache(doctype="Cost Center")
return super().clear_cache()

View File

@@ -28,7 +28,7 @@ def get_pricing_rules(args, doc=None):
pricing_rules = []
values = {}
if not frappe.db.exists("Pricing Rule", {"disable": 0, args.transaction_type: 1}):
if not frappe.db.count("Pricing Rule", cache=True):
return
for apply_on in ["Item Code", "Item Group", "Brand"]:

View File

@@ -8,6 +8,7 @@ import frappe
from frappe import _
from frappe.model.meta import get_field_precision
from frappe.utils import cint, flt, formatdate, get_link_to_form, getdate, now
from frappe.utils.caching import request_cache
from frappe.utils.dashboard import cache_source
import erpnext
@@ -222,6 +223,7 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None, from_r
return new_gl_map
@request_cache
def get_cost_center_allocation_data(company, posting_date, cost_center):
cost_center_allocation = frappe.db.get_value(
"Cost Center Allocation",
@@ -231,7 +233,7 @@ def get_cost_center_allocation_data(company, posting_date, cost_center):
"valid_from": ("<=", posting_date),
"main_cost_center": cost_center,
},
pluck="name",
pluck=True,
order_by="valid_from desc",
)

View File

@@ -236,7 +236,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
filters.pop("supplier", None)
description_cond = ""
if frappe.db.count(doctype, cache=True) < 50000:
if frappe.db.estimate_count(doctype) < 50000:
# scan description only if items are less than 50000
description_cond = "or tabItem.description LIKE %(txt)s"

View File

@@ -21,7 +21,11 @@ class SellingController(StockController):
def onload(self):
super().onload()
if self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice", "Quotation"):
if (
self.doctype in ("Sales Order", "Delivery Note", "Sales Invoice", "Quotation")
and self.docstatus.is_draft()
and not hasattr(self, "_action")
):
for item in self.get("items") + (self.get("packed_items") or []):
company = self.company

View File

@@ -364,28 +364,21 @@ def get_evaluated_inventory_dimension(doc, sl_dict, parent_doc=None):
return filter_dimensions
@request_cache
def get_document_wise_inventory_dimensions(doctype) -> dict:
if not hasattr(frappe.local, "document_wise_inventory_dimensions"):
frappe.local.document_wise_inventory_dimensions = {}
if not frappe.local.document_wise_inventory_dimensions.get(doctype):
dimensions = frappe.get_all(
"Inventory Dimension",
fields=[
"name",
"source_fieldname",
"condition",
"target_fieldname",
"type_of_transaction",
"fetch_from_parent",
],
filters={"disabled": 0},
or_filters={"document_type": doctype, "apply_to_all_doctypes": 1},
)
frappe.local.document_wise_inventory_dimensions[doctype] = dimensions
return frappe.local.document_wise_inventory_dimensions[doctype]
return frappe.get_all(
"Inventory Dimension",
fields=[
"name",
"source_fieldname",
"condition",
"target_fieldname",
"type_of_transaction",
"fetch_from_parent",
],
filters={"disabled": 0},
or_filters={"document_type": doctype, "apply_to_all_doctypes": 1},
)
@frappe.whitelist()

View File

@@ -87,7 +87,7 @@ class TestInventoryDimension(IntegrationTestCase):
self.assertFalse(custom_field)
def test_inventory_dimension(self):
frappe.local.document_wise_inventory_dimensions = {}
frappe.clear_cache(doctype="Inventory Dimension")
warehouse = "Shelf Warehouse - _TC"
item_code = "_Test Item"
@@ -159,7 +159,7 @@ class TestInventoryDimension(IntegrationTestCase):
self.assertRaises(DoNotChangeError, inv_dim1.save)
def test_inventory_dimension_for_purchase_receipt_and_delivery_note(self):
frappe.local.document_wise_inventory_dimensions = {}
frappe.clear_cache(doctype="Inventory Dimension")
inv_dimension = create_inventory_dimension(
reference_document="Rack", dimension_name="Rack", apply_to_all_doctypes=1