From ff442cd8e7611d62d5f187376d3dc6160fd91992 Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Fri, 22 May 2026 11:34:43 +0000 Subject: [PATCH] fix(stock): apply posting datetime filters while fetching available batches (backport #54976) (#55184) fix(stock): apply posting datetime filters while fetching available batches Co-authored-by: Mihir Kandoi --- erpnext/controllers/queries.py | 15 +++++++++++++++ .../public/js/utils/serial_no_batch_selector.js | 2 ++ 2 files changed, 17 insertions(+) diff --git a/erpnext/controllers/queries.py b/erpnext/controllers/queries.py index dbfa6e7f9fb..dd48a65e5e9 100644 --- a/erpnext/controllers/queries.py +++ b/erpnext/controllers/queries.py @@ -17,6 +17,7 @@ from pypika import Order import erpnext from erpnext.accounts.utils import build_qb_match_conditions from erpnext.stock.get_item_details import _get_item_tax_template +from erpnext.stock.utils import get_combine_datetime # searches for active employees @@ -476,6 +477,13 @@ def get_batches_from_stock_ledger_entries(searchfields, txt, filters, start=0, p .limit(page_len) ) + if not filters.get("is_inward"): + if filters.get("posting_date") and filters.get("posting_time"): + query = query.where( + stock_ledger_entry.posting_datetime + <= get_combine_datetime(filters.posting_date, filters.posting_time) + ) + if not filters.get("include_expired_batches"): query = query.where((batch_table.expiry_date >= expiry_date) | (batch_table.expiry_date.isnull())) @@ -529,6 +537,13 @@ def get_batches_from_serial_and_batch_bundle(searchfields, txt, filters, start=0 .limit(page_len) ) + if not filters.get("is_inward"): + if filters.get("posting_date") and filters.get("posting_time"): + bundle_query = bundle_query.where( + stock_ledger_entry.posting_datetime + <= get_combine_datetime(filters.posting_date, filters.posting_time) + ) + if not filters.get("include_expired_batches"): bundle_query = bundle_query.where( (batch_table.expiry_date >= expiry_date) | (batch_table.expiry_date.isnull()) diff --git a/erpnext/public/js/utils/serial_no_batch_selector.js b/erpnext/public/js/utils/serial_no_batch_selector.js index 002842cad2d..91cda58718c 100644 --- a/erpnext/public/js/utils/serial_no_batch_selector.js +++ b/erpnext/public/js/utils/serial_no_batch_selector.js @@ -472,6 +472,8 @@ erpnext.SerialBatchPackageSelector = class SerialNoBatchBundleUpdate { warehouse: this.item.s_warehouse || this.item.t_warehouse || this.item.warehouse, is_inward: is_inward, + posting_date: this.frm.doc.posting_date, + posting_time: this.frm.doc.posting_time, include_expired_batches: include_expired_batches, }, };