Skip to content

Commit e92af10

Browse files
fix: slow stock transactions (frappe#45025)
1 parent 8aa3157 commit e92af10

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

erpnext/stock/stock_balance.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ def get_balance_qty_from_sle(item_code, warehouse):
8080
balance_qty = frappe.db.sql(
8181
"""select qty_after_transaction from `tabStock Ledger Entry`
8282
where item_code=%s and warehouse=%s and is_cancelled=0
83-
order by posting_date desc, posting_time desc, creation desc
83+
order by posting_datetime desc, creation desc
8484
limit 1""",
8585
(item_code, warehouse),
8686
)

erpnext/stock/stock_ledger.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
15711571
and (
15721572
posting_datetime {operator} %(posting_datetime)s
15731573
)
1574-
order by posting_date desc, posting_time desc, creation desc
1574+
order by posting_datetime desc, creation desc
15751575
limit 1
15761576
for update""",
15771577
{
@@ -1665,7 +1665,7 @@ def get_stock_ledger_entries(
16651665
where item_code = %(item_code)s
16661666
and is_cancelled = 0
16671667
{conditions}
1668-
order by posting_date {order}, posting_time {order}, creation {order}
1668+
order by posting_datetime {order}, creation {order}
16691669
{limit} {for_update}""".format(
16701670
conditions=conditions,
16711671
limit=limit or "",
@@ -1787,7 +1787,7 @@ def get_valuation_rate(
17871787
AND valuation_rate >= 0
17881788
AND is_cancelled = 0
17891789
AND NOT (voucher_no = %s AND voucher_type = %s)
1790-
order by posting_date desc, posting_time desc, name desc limit 1""",
1790+
order by posting_datetime desc, creation desc limit 1""",
17911791
(item_code, warehouse, voucher_no, voucher_type),
17921792
):
17931793
return flt(last_valuation_rate[0][0])
@@ -2038,7 +2038,7 @@ def get_future_sle_with_negative_qty(sle_args):
20382038
and posting_datetime >= %(posting_datetime)s
20392039
and is_cancelled = 0
20402040
and qty_after_transaction < 0
2041-
order by posting_date asc, posting_time asc
2041+
order by posting_datetime asc, creation asc
20422042
limit 1
20432043
""",
20442044
sle_args,
@@ -2052,14 +2052,14 @@ def get_future_sle_with_negative_batch_qty(sle_args):
20522052
with batch_ledger as (
20532053
select
20542054
posting_date, posting_time, posting_datetime, voucher_type, voucher_no,
2055-
sum(actual_qty) over (order by posting_date, posting_time, creation) as cumulative_total
2055+
sum(actual_qty) over (order by posting_datetime, creation) as cumulative_total
20562056
from `tabStock Ledger Entry`
20572057
where
20582058
item_code = %(item_code)s
20592059
and warehouse = %(warehouse)s
20602060
and batch_no=%(batch_no)s
20612061
and is_cancelled = 0
2062-
order by posting_date, posting_time, creation
2062+
order by posting_datetime, creation
20632063
)
20642064
select * from batch_ledger
20652065
where

0 commit comments

Comments
 (0)