diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 85a74f52087..1644160cf75 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -555,7 +555,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 = [] @@ -585,7 +585,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 = ( diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py index 3e2fcfff040..6e92d33131c 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -255,10 +255,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) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 46a5358f2b1..081b988e78e 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -1368,7 +1368,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() @@ -1382,7 +1382,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 diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index d91a22631d8..5ea3a457c0b 100644 --- a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py +++ b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py @@ -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):