From 9870dd26f717dea89cacfa9bfbdb8fa760312867 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Wed, 4 Jun 2025 15:55:15 +0530 Subject: [PATCH] perf: avoid querying cost center allocation repeatedly --- .../doctype/cost_center_allocation/cost_center_allocation.py | 4 ++++ erpnext/accounts/general_ledger.py | 2 ++ 2 files changed, 6 insertions(+) diff --git a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py index 34b2ec68743..52a92acd55e 100644 --- a/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py +++ b/erpnext/accounts/doctype/cost_center_allocation/cost_center_allocation.py @@ -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() diff --git a/erpnext/accounts/general_ledger.py b/erpnext/accounts/general_ledger.py index edf8c2e3581..c30560b998d 100644 --- a/erpnext/accounts/general_ledger.py +++ b/erpnext/accounts/general_ledger.py @@ -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",