From 2f98941cfa7506abb293d9927133ed9faccae81f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=BCrker=20Tunal=C4=B1?= Date: Sun, 6 Apr 2025 12:25:42 +0300 Subject: [PATCH] perf: Stock entry cancel is slow Some queries still use "timestamp" function instead of "posting_datetime". In my instance single stock entry cancel ends with request timeout. Using "posting_datetime" field directly improves the situation. cont: https://github.com/frappe/erpnext/pull/46293 --- erpnext/controllers/stock_controller.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/erpnext/controllers/stock_controller.py b/erpnext/controllers/stock_controller.py index f59ba1e103b..89bfaf9e4c6 100644 --- a/erpnext/controllers/stock_controller.py +++ b/erpnext/controllers/stock_controller.py @@ -1634,6 +1634,8 @@ def is_reposting_pending(): def future_sle_exists(args, sl_entries=None, allow_force_reposting=True): + from erpnext.stock.utils import get_combine_datetime + if allow_force_reposting and frappe.db.get_single_value( "Stock Reposting Settings", "do_reposting_for_each_stock_transaction" ): @@ -1655,14 +1657,15 @@ def future_sle_exists(args, sl_entries=None, allow_force_reposting=True): or_conditions = get_conditions_to_validate_future_sle(sl_entries) + args["posting_datetime"] = get_combine_datetime(args["posting_date"], args["posting_time"]) + data = frappe.db.sql( """ select item_code, warehouse, count(name) as total_row - from `tabStock Ledger Entry` force index (item_warehouse) + from `tabStock Ledger Entry` where ({}) - and timestamp(posting_date, posting_time) - >= timestamp(%(posting_date)s, %(posting_time)s) + and posting_datetime >= %(posting_datetime)s and voucher_no != %(voucher_no)s and is_cancelled = 0 GROUP BY -- GitLab