fix: Recreate Stock Ledgers issue

(cherry picked from commit 229a4cef45)
This commit is contained in:
Rohit Waghchaure
2025-04-09 12:37:02 +05:30
committed by Mergify
parent 860aba47ef
commit b819e0a61b
4 changed files with 13 additions and 9 deletions

View File

@@ -558,7 +558,7 @@ class SellingController(StockController):
self.doctype, self.name, d.item_code, self.return_against, item_row=d
)
def update_stock_ledger(self):
def update_stock_ledger(self, allow_negative_stock=False):
self.update_reserved_qty()
sl_entries = []
@@ -588,7 +588,7 @@ class SellingController(StockController):
):
sl_entries.append(self.get_sle_for_source_warehouse(d))
self.make_sl_entries(sl_entries)
self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock)
def get_sle_for_source_warehouse(self, item_row):
serial_and_batch_bundle = (

View File

@@ -260,10 +260,10 @@ class RepostItemValuation(Document):
"""Recreate Stock Ledger Entries for the transaction."""
if self.based_on == "Transaction" and self.recreate_stock_ledgers:
doc = frappe.get_doc(self.voucher_type, self.voucher_no)
doc.docstatus = 2
doc.update_stock_ledger(allow_negative_stock=True, via_landed_cost_voucher=True)
doc.db_set("docstatus", 2)
doc.update_stock_ledger(allow_negative_stock=True)
doc.docstatus = 1
doc.db_set("docstatus", 1)
doc.update_stock_ledger(allow_negative_stock=True)

View File

@@ -1347,7 +1347,7 @@ class StockEntry(StockController):
)
)
def update_stock_ledger(self):
def update_stock_ledger(self, allow_negative_stock=False):
sl_entries = []
finished_item_row = self.get_finished_item_row()
@@ -1361,7 +1361,7 @@ class StockEntry(StockController):
if self.docstatus == 2:
sl_entries.reverse()
self.make_sl_entries(sl_entries)
self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock)
def get_finished_item_row(self):
finished_item_row = None

View File

@@ -663,7 +663,7 @@ class StockReconciliation(StockController):
title=_("Stock Reservation"),
)
def update_stock_ledger(self):
def update_stock_ledger(self, allow_negative_stock=False):
"""find difference between current and expected entries
and create stock ledger entries based on the difference"""
from erpnext.stock.stock_ledger import get_previous_sle
@@ -719,7 +719,11 @@ class StockReconciliation(StockController):
sl_entries.append(self.get_sle_for_items(row))
if sl_entries:
allow_negative_stock = cint(frappe.db.get_single_value("Stock Settings", "allow_negative_stock"))
if not allow_negative_stock:
allow_negative_stock = cint(
frappe.db.get_single_value("Stock Settings", "allow_negative_stock")
)
self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock)
def make_adjustment_entry(self, row, sl_entries):