Merge pull request #46965 from rohitwaghchaure/fixed-reposting-error-recreate-ledgers

fix: Recreate Stock Ledgers issue
This commit is contained in:
rohitwaghchaure
2025-04-10 11:42:51 +05:30
committed by GitHub
4 changed files with 13 additions and 9 deletions

View File

@@ -555,7 +555,7 @@ class SellingController(StockController):
self.doctype, self.name, d.item_code, self.return_against, item_row=d 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() self.update_reserved_qty()
sl_entries = [] sl_entries = []
@@ -585,7 +585,7 @@ class SellingController(StockController):
): ):
sl_entries.append(self.get_sle_for_source_warehouse(d)) 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): def get_sle_for_source_warehouse(self, item_row):
serial_and_batch_bundle = ( serial_and_batch_bundle = (

View File

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

View File

@@ -1368,7 +1368,7 @@ class StockEntry(StockController):
) )
) )
def update_stock_ledger(self): def update_stock_ledger(self, allow_negative_stock=False):
sl_entries = [] sl_entries = []
finished_item_row = self.get_finished_item_row() finished_item_row = self.get_finished_item_row()
@@ -1382,7 +1382,7 @@ class StockEntry(StockController):
if self.docstatus == 2: if self.docstatus == 2:
sl_entries.reverse() 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): def get_finished_item_row(self):
finished_item_row = None finished_item_row = None

View File

@@ -663,7 +663,7 @@ class StockReconciliation(StockController):
title=_("Stock Reservation"), title=_("Stock Reservation"),
) )
def update_stock_ledger(self): def update_stock_ledger(self, allow_negative_stock=False):
"""find difference between current and expected entries """find difference between current and expected entries
and create stock ledger entries based on the difference""" and create stock ledger entries based on the difference"""
from erpnext.stock.stock_ledger import get_previous_sle 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)) sl_entries.append(self.get_sle_for_items(row))
if sl_entries: 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) self.make_sl_entries(sl_entries, allow_negative_stock=allow_negative_stock)
def make_adjustment_entry(self, row, sl_entries): def make_adjustment_entry(self, row, sl_entries):