Skip to content

Commit bb75adb

Browse files
committed
fix: slow stock transactions (backport frappe#45025) (frappe#45027)
fix: slow stock transactions (frappe#45025) (cherry picked from commit e92af10) Co-authored-by: rohitwaghchaure <[email protected]> (cherry picked from commit 85ba96e)
1 parent 3a5959e commit bb75adb

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
@@ -1570,7 +1570,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
15701570
and (
15711571
posting_datetime {operator} %(posting_datetime)s
15721572
)
1573-
order by posting_date desc, posting_time desc, creation desc
1573+
order by posting_datetime desc, creation desc
15741574
limit 1
15751575
for update""",
15761576
{
@@ -1664,7 +1664,7 @@ def get_stock_ledger_entries(
16641664
where item_code = %(item_code)s
16651665
and is_cancelled = 0
16661666
{conditions}
1667-
order by posting_date {order}, posting_time {order}, creation {order}
1667+
order by posting_datetime {order}, creation {order}
16681668
{limit} {for_update}""".format(
16691669
conditions=conditions,
16701670
limit=limit or "",
@@ -1786,7 +1786,7 @@ def get_valuation_rate(
17861786
AND valuation_rate >= 0
17871787
AND is_cancelled = 0
17881788
AND NOT (voucher_no = %s AND voucher_type = %s)
1789-
order by posting_date desc, posting_time desc, name desc limit 1""",
1789+
order by posting_datetime desc, creation desc limit 1""",
17901790
(item_code, warehouse, voucher_no, voucher_type),
17911791
):
17921792
return flt(last_valuation_rate[0][0])
@@ -2037,7 +2037,7 @@ def get_future_sle_with_negative_qty(sle_args):
20372037
and posting_datetime >= %(posting_datetime)s
20382038
and is_cancelled = 0
20392039
and qty_after_transaction < 0
2040-
order by posting_date asc, posting_time asc
2040+
order by posting_datetime asc, creation asc
20412041
limit 1
20422042
""",
20432043
sle_args,
@@ -2051,14 +2051,14 @@ def get_future_sle_with_negative_batch_qty(sle_args):
20512051
with batch_ledger as (
20522052
select
20532053
posting_date, posting_time, posting_datetime, voucher_type, voucher_no,
2054-
sum(actual_qty) over (order by posting_date, posting_time, creation) as cumulative_total
2054+
sum(actual_qty) over (order by posting_datetime, creation) as cumulative_total
20552055
from `tabStock Ledger Entry`
20562056
where
20572057
item_code = %(item_code)s
20582058
and warehouse = %(warehouse)s
20592059
and batch_no=%(batch_no)s
20602060
and is_cancelled = 0
2061-
order by posting_date, posting_time, creation
2061+
order by posting_datetime, creation
20622062
)
20632063
select * from batch_ledger
20642064
where

0 commit comments

Comments
 (0)