From 0fb6062dbcacd6213a64e53b78a3957d4b598838 Mon Sep 17 00:00:00 2001 From: Ankush Menat Date: Mon, 9 May 2022 11:13:31 +0530 Subject: [PATCH] fix: sort before picking next stock reco --- .../stock_reconciliation/test_stock_reconciliation.py | 3 +++ erpnext/stock/stock_ledger.py | 7 +++---- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py index 1e59aae9a8dc..a1ac9a764406 100644 --- a/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/test_stock_reconciliation.py @@ -31,6 +31,7 @@ def setUpClass(cls): def tearDown(self): frappe.local.future_sle = {} + frappe.flags.pop("dont_execute_stock_reposts", None) def test_reco_for_fifo(self): self._test_reco_sle_gle("FIFO") @@ -315,6 +316,8 @@ def test_backdated_stock_reco_qty_reposting(self): item_code = make_item().name warehouse = "_Test Warehouse - _TC" + frappe.flags.dont_execute_stock_reposts = True + pr1 = make_purchase_receipt( item_code=item_code, warehouse=warehouse, qty=10, rate=100, posting_date=add_days(nowdate(), -3) ) diff --git a/erpnext/stock/stock_ledger.py b/erpnext/stock/stock_ledger.py index 5a270d1ec0b8..4789b52d50e5 100644 --- a/erpnext/stock/stock_ledger.py +++ b/erpnext/stock/stock_ledger.py @@ -1317,7 +1317,7 @@ def update_qty_in_future_sle(args, allow_negative_stock=False): datetime_limit_condition = get_datetime_limit_condition(detail) frappe.db.sql( - """ + f""" update `tabStock Ledger Entry` set qty_after_transaction = qty_after_transaction + {qty_shift} where @@ -1328,9 +1328,7 @@ def update_qty_in_future_sle(args, allow_negative_stock=False): and timestamp(posting_date, time_format(posting_time, %(time_format)s)) > timestamp(%(posting_date)s, time_format(%(posting_time)s, %(time_format)s)) {datetime_limit_condition} - """.format( - qty_shift=qty_shift, datetime_limit_condition=datetime_limit_condition - ), + """, args, ) @@ -1381,6 +1379,7 @@ def get_next_stock_reco(args): and creation > %(creation)s ) ) + order by timestamp(posting_date, posting_time) asc, creation asc limit 1 """, args,