diff --git a/erpnext/controllers/selling_controller.py b/erpnext/controllers/selling_controller.py index 8ba8f06c65f..15526f85e34 100644 --- a/erpnext/controllers/selling_controller.py +++ b/erpnext/controllers/selling_controller.py @@ -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 = ( 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 880acb65dc3..ecbb10b6cb5 100644 --- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py +++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py @@ -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) diff --git a/erpnext/stock/doctype/stock_entry/stock_entry.py b/erpnext/stock/doctype/stock_entry/stock_entry.py index 52655c9ac03..efa263a7573 100644 --- a/erpnext/stock/doctype/stock_entry/stock_entry.py +++ b/erpnext/stock/doctype/stock_entry/stock_entry.py @@ -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 diff --git a/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py b/erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py index 46f9f9dcf1b..32c4a743999 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):