fix: same posting date and time, creation causing incorrect balance qty (backport #42904) (#42919)

* fix: same posting date and time, creation causing incorrect balance qty (#42904)

fix: same posting date and time, creation causing incorrect balance quantity
(cherry picked from commit 27364b7e6b)

# Conflicts:
#	erpnext/stock/doctype/purchase_receipt/test_purchase_receipt.py
#	erpnext/stock/stock_ledger.py

* chore: fix conflicts

* chore: fix conflicts

---------

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-08-27 14:33:56 +05:30
committed by GitHub
parent 73eab91631
commit c0b5f7c8eb
3 changed files with 75 additions and 9 deletions

View File

@@ -1253,7 +1253,7 @@ def get_previous_sle_of_current_voucher(args, operator="<", exclude_current_vouc
and (
posting_datetime {operator} %(posting_datetime)s
)
order by posting_datetime desc, creation desc
order by posting_date desc, posting_time desc, creation desc
limit 1
for update""",
{
@@ -1347,7 +1347,7 @@ def get_stock_ledger_entries(
where item_code = %(item_code)s
and is_cancelled = 0
{conditions}
order by posting_datetime {order}, creation {order}
order by posting_date {order}, posting_time {order}, creation {order}
{limit} {for_update}""".format(
conditions=conditions,
limit=limit or "",
@@ -1452,7 +1452,7 @@ def get_valuation_rate(
AND valuation_rate >= 0
AND is_cancelled = 0
AND NOT (voucher_no = %s AND voucher_type = %s)
order by posting_datetime desc, name desc limit 1""",
order by posting_date desc, posting_time desc, name desc limit 1""",
(item_code, warehouse, voucher_no, voucher_type),
)
@@ -1701,7 +1701,8 @@ def get_future_sle_with_negative_qty(sle):
& (SLE.is_cancelled == 0)
& (SLE.qty_after_transaction < 0)
)
.orderby(SLE.posting_datetime)
.orderby(SLE.posting_date)
.orderby(SLE.posting_time)
.limit(1)
)
@@ -1717,14 +1718,14 @@ def get_future_sle_with_negative_batch_qty(args):
with batch_ledger as (
select
posting_date, posting_time, posting_datetime, voucher_type, voucher_no,
sum(actual_qty) over (order by posting_datetime, creation) as cumulative_total
sum(actual_qty) over (order by posting_date, posting_time, creation) as cumulative_total
from `tabStock Ledger Entry`
where
item_code = %(item_code)s
and warehouse = %(warehouse)s
and batch_no=%(batch_no)s
and is_cancelled = 0
order by posting_datetime, creation
order by posting_date, posting_time, creation
)
select * from batch_ledger
where