mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-26 16:34:46 +00:00
Merge pull request #47899 from frappe/cruft
perf: remove misc random cruft
This commit is contained in:
@@ -145,7 +145,7 @@ class Budget(Document):
|
|||||||
|
|
||||||
def validate_expense_against_budget(args, expense_amount=0):
|
def validate_expense_against_budget(args, expense_amount=0):
|
||||||
args = frappe._dict(args)
|
args = frappe._dict(args)
|
||||||
if not frappe.get_all("Budget", limit=1):
|
if not frappe.db.count("Budget", cache=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
if args.get("company") and not args.fiscal_year:
|
if args.get("company") and not args.fiscal_year:
|
||||||
|
|||||||
@@ -154,3 +154,7 @@ class CostCenterAllocation(Document):
|
|||||||
).format(d.cost_center),
|
).format(d.cost_center),
|
||||||
InvalidChildCostCenter,
|
InvalidChildCostCenter,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def clear_cache(self):
|
||||||
|
frappe.clear_cache(doctype="Cost Center")
|
||||||
|
return super().clear_cache()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ def get_pricing_rules(args, doc=None):
|
|||||||
pricing_rules = []
|
pricing_rules = []
|
||||||
values = {}
|
values = {}
|
||||||
|
|
||||||
if not frappe.db.exists("Pricing Rule", {"disable": 0, args.transaction_type: 1}):
|
if not frappe.db.count("Pricing Rule", cache=True):
|
||||||
return
|
return
|
||||||
|
|
||||||
for apply_on in ["Item Code", "Item Group", "Brand"]:
|
for apply_on in ["Item Code", "Item Group", "Brand"]:
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import frappe
|
|||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.meta import get_field_precision
|
from frappe.model.meta import get_field_precision
|
||||||
from frappe.utils import cint, flt, formatdate, get_link_to_form, getdate, now
|
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
|
from frappe.utils.dashboard import cache_source
|
||||||
|
|
||||||
import erpnext
|
import erpnext
|
||||||
@@ -222,6 +223,7 @@ def distribute_gl_based_on_cost_center_allocation(gl_map, precision=None, from_r
|
|||||||
return new_gl_map
|
return new_gl_map
|
||||||
|
|
||||||
|
|
||||||
|
@request_cache
|
||||||
def get_cost_center_allocation_data(company, posting_date, cost_center):
|
def get_cost_center_allocation_data(company, posting_date, cost_center):
|
||||||
cost_center_allocation = frappe.db.get_value(
|
cost_center_allocation = frappe.db.get_value(
|
||||||
"Cost Center Allocation",
|
"Cost Center Allocation",
|
||||||
@@ -231,7 +233,7 @@ def get_cost_center_allocation_data(company, posting_date, cost_center):
|
|||||||
"valid_from": ("<=", posting_date),
|
"valid_from": ("<=", posting_date),
|
||||||
"main_cost_center": cost_center,
|
"main_cost_center": cost_center,
|
||||||
},
|
},
|
||||||
pluck="name",
|
pluck=True,
|
||||||
order_by="valid_from desc",
|
order_by="valid_from desc",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -236,7 +236,7 @@ def item_query(doctype, txt, searchfield, start, page_len, filters, as_dict=Fals
|
|||||||
filters.pop("supplier", None)
|
filters.pop("supplier", None)
|
||||||
|
|
||||||
description_cond = ""
|
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
|
# scan description only if items are less than 50000
|
||||||
description_cond = "or tabItem.description LIKE %(txt)s"
|
description_cond = "or tabItem.description LIKE %(txt)s"
|
||||||
|
|
||||||
|
|||||||
@@ -21,7 +21,11 @@ class SellingController(StockController):
|
|||||||
|
|
||||||
def onload(self):
|
def onload(self):
|
||||||
super().onload()
|
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 []):
|
for item in self.get("items") + (self.get("packed_items") or []):
|
||||||
company = self.company
|
company = self.company
|
||||||
|
|
||||||
|
|||||||
@@ -364,28 +364,21 @@ def get_evaluated_inventory_dimension(doc, sl_dict, parent_doc=None):
|
|||||||
return filter_dimensions
|
return filter_dimensions
|
||||||
|
|
||||||
|
|
||||||
|
@request_cache
|
||||||
def get_document_wise_inventory_dimensions(doctype) -> dict:
|
def get_document_wise_inventory_dimensions(doctype) -> dict:
|
||||||
if not hasattr(frappe.local, "document_wise_inventory_dimensions"):
|
return frappe.get_all(
|
||||||
frappe.local.document_wise_inventory_dimensions = {}
|
"Inventory Dimension",
|
||||||
|
fields=[
|
||||||
if not frappe.local.document_wise_inventory_dimensions.get(doctype):
|
"name",
|
||||||
dimensions = frappe.get_all(
|
"source_fieldname",
|
||||||
"Inventory Dimension",
|
"condition",
|
||||||
fields=[
|
"target_fieldname",
|
||||||
"name",
|
"type_of_transaction",
|
||||||
"source_fieldname",
|
"fetch_from_parent",
|
||||||
"condition",
|
],
|
||||||
"target_fieldname",
|
filters={"disabled": 0},
|
||||||
"type_of_transaction",
|
or_filters={"document_type": doctype, "apply_to_all_doctypes": 1},
|
||||||
"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]
|
|
||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ class TestInventoryDimension(IntegrationTestCase):
|
|||||||
self.assertFalse(custom_field)
|
self.assertFalse(custom_field)
|
||||||
|
|
||||||
def test_inventory_dimension(self):
|
def test_inventory_dimension(self):
|
||||||
frappe.local.document_wise_inventory_dimensions = {}
|
frappe.clear_cache(doctype="Inventory Dimension")
|
||||||
|
|
||||||
warehouse = "Shelf Warehouse - _TC"
|
warehouse = "Shelf Warehouse - _TC"
|
||||||
item_code = "_Test Item"
|
item_code = "_Test Item"
|
||||||
@@ -159,7 +159,7 @@ class TestInventoryDimension(IntegrationTestCase):
|
|||||||
self.assertRaises(DoNotChangeError, inv_dim1.save)
|
self.assertRaises(DoNotChangeError, inv_dim1.save)
|
||||||
|
|
||||||
def test_inventory_dimension_for_purchase_receipt_and_delivery_note(self):
|
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(
|
inv_dimension = create_inventory_dimension(
|
||||||
reference_document="Rack", dimension_name="Rack", apply_to_all_doctypes=1
|
reference_document="Rack", dimension_name="Rack", apply_to_all_doctypes=1
|
||||||
|
|||||||
Reference in New Issue
Block a user