diff --git a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py index 932e5dec8cbc17082e3daf6b51b4fc8a6c7c3fdc..bf069b8f7f7e17212b63ec07909165a6558c7240 100644 --- a/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py +++ b/erpnext/stock/doctype/serial_and_batch_bundle/serial_and_batch_bundle.py @@ -276,7 +276,7 @@ class SerialandBatchBundle(Document): ) def validate_negative_batch(self, batch_no, available_qty): - if available_qty < 0: + if available_qty < 0 and not self.is_stock_reco_for_valuation_adjustment(available_qty): msg = f"""Batch No {bold(batch_no)} of an Item {bold(self.item_code)} has negative stock of quantity {bold(available_qty)} in the @@ -284,6 +284,18 @@ class SerialandBatchBundle(Document): frappe.throw(_(msg), BatchNegativeStockError) + def is_stock_reco_for_valuation_adjustment(self, available_qty): + if ( + self.voucher_type == "Stock Reconciliation" + and self.type_of_transaction == "Outward" + and self.voucher_detail_no + and abs(frappe.db.get_value("Stock Reconciliation Item", self.voucher_detail_no, "qty")) + == abs(available_qty) + ): + return True + + return False + def get_sle_for_outward_transaction(self): sle = frappe._dict( {