From a186b1266d9f451025e5043cd73c886e7034c284 Mon Sep 17 00:00:00 2001 From: Rohit Waghchaure Date: Sun, 27 Jul 2025 18:45:23 +0530 Subject: [PATCH] fix: prevent concurrency issues --- erpnext/stock/deprecated_serial_batch.py | 4 ++++ erpnext/stock/serial_batch_bundle.py | 1 + 2 files changed, 5 insertions(+) diff --git a/erpnext/stock/deprecated_serial_batch.py b/erpnext/stock/deprecated_serial_batch.py index 0611511ba0e..7f233906a6e 100644 --- a/erpnext/stock/deprecated_serial_batch.py +++ b/erpnext/stock/deprecated_serial_batch.py @@ -160,6 +160,7 @@ class DeprecatedBatchNoValuation: & (sle.batch_no.isnotnull()) & (sle.is_cancelled == 0) ) + .for_update() .groupby(sle.batch_no) ) @@ -266,6 +267,7 @@ class DeprecatedBatchNoValuation: & (sle.is_cancelled == 0) & (sle.batch_no.isin(self.non_batchwise_valuation_batches)) ) + .for_update() .where(timestamp_condition) .groupby(sle.batch_no) ) @@ -312,6 +314,7 @@ class DeprecatedBatchNoValuation: .where(timestamp_condition) .orderby(sle.posting_datetime, order=Order.desc) .orderby(sle.creation, order=Order.desc) + .for_update() .limit(1) ) @@ -369,6 +372,7 @@ class DeprecatedBatchNoValuation: & (bundle.type_of_transaction.isin(["Inward", "Outward"])) & (bundle_child.batch_no.isin(self.non_batchwise_valuation_batches)) ) + .for_update() .where(timestamp_condition) .groupby(bundle_child.batch_no) ) diff --git a/erpnext/stock/serial_batch_bundle.py b/erpnext/stock/serial_batch_bundle.py index b578ceea4c0..6fff8722e80 100644 --- a/erpnext/stock/serial_batch_bundle.py +++ b/erpnext/stock/serial_batch_bundle.py @@ -755,6 +755,7 @@ class BatchNoValuation(DeprecatedBatchNoValuation): & (parent.is_cancelled == 0) & (parent.type_of_transaction.isin(["Inward", "Outward"])) ) + .for_update() .groupby(child.batch_no) )