fix: Stock Reconciliation Insufficient Stock Error (#37494)

* fix: Stock Reconciliation Insufficient Stock Error

* fix: linter

* test: add test case for Stock Reco Batch Item
This commit is contained in:
s-aga-r
2023-10-14 16:53:29 +05:30
committed by GitHub
parent bae6c5bf5f
commit 9406ddbff0
2 changed files with 77 additions and 19 deletions

View File

@@ -1617,27 +1617,33 @@ def is_negative_with_precision(neg_sle, is_batch=False):
return qty_deficit < 0 and abs(qty_deficit) > 0.0001
def get_future_sle_with_negative_qty(args):
return frappe.db.sql(
"""
select
qty_after_transaction, posting_date, posting_time,
voucher_type, voucher_no
from `tabStock Ledger Entry`
where
item_code = %(item_code)s
and warehouse = %(warehouse)s
and voucher_no != %(voucher_no)s
and timestamp(posting_date, posting_time) >= timestamp(%(posting_date)s, %(posting_time)s)
and is_cancelled = 0
and qty_after_transaction < 0
order by timestamp(posting_date, posting_time) asc
limit 1
""",
args,
as_dict=1,
def get_future_sle_with_negative_qty(sle):
SLE = frappe.qb.DocType("Stock Ledger Entry")
query = (
frappe.qb.from_(SLE)
.select(
SLE.qty_after_transaction, SLE.posting_date, SLE.posting_time, SLE.voucher_type, SLE.voucher_no
)
.where(
(SLE.item_code == sle.item_code)
& (SLE.warehouse == sle.warehouse)
& (SLE.voucher_no != sle.voucher_no)
& (
CombineDatetime(SLE.posting_date, SLE.posting_time)
>= CombineDatetime(sle.posting_date, sle.posting_time)
)
& (SLE.is_cancelled == 0)
& (SLE.qty_after_transaction < 0)
)
.orderby(CombineDatetime(SLE.posting_date, SLE.posting_time))
.limit(1)
)
if sle.voucher_type == "Stock Reconciliation" and sle.batch_no:
query = query.where(SLE.batch_no == sle.batch_no)
return query.run(as_dict=True)
def get_future_sle_with_negative_batch_qty(args):
return frappe.db.sql(