fix: negative stock error for batch (backport #43450) (#43454)

fix: negative stock error for batch (#43450)

(cherry picked from commit 912ba7789c)

Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
mergify[bot]
2024-10-01 10:34:48 +05:30
committed by GitHub
parent 5fc5934942
commit 7bf6251c21

View File

@@ -280,7 +280,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
@@ -288,6 +288,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(
{