Skip to content

Commit

Permalink
fix: stock reservation for sales invoice
Browse files Browse the repository at this point in the history
  • Loading branch information
rohitwaghchaure committed Feb 12, 2025
1 parent 162d1ba commit 2d22301
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
7 changes: 5 additions & 2 deletions erpnext/controllers/selling_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,9 @@ def validate_items(self):
def update_stock_reservation_entries(self) -> None:
"""Updates Delivered Qty in Stock Reservation Entries."""

if not frappe.db.get_single_value("Stock Settings", "enable_stock_reservation"):
return

# Don't update Delivered Qty on Return.
if self.is_return:
return
Expand Down Expand Up @@ -831,7 +834,7 @@ def update_stock_reservation_entries(self) -> None:
sre_doc = frappe.get_doc("Stock Reservation Entry", sre)

qty_can_be_deliver = 0
if sre_doc.reservation_based_on == "Serial and Batch":
if sre_doc.reservation_based_on == "Serial and Batch" and item.serial_and_batch_bundle:
sbb = frappe.get_doc("Serial and Batch Bundle", item.serial_and_batch_bundle)
if sre_doc.has_serial_no:
delivered_serial_nos = [d.serial_no for d in sbb.entries]
Expand Down Expand Up @@ -900,7 +903,7 @@ def update_stock_reservation_entries(self) -> None:
sre_doc = frappe.get_doc("Stock Reservation Entry", sre)

qty_can_be_undelivered = 0
if sre_doc.reservation_based_on == "Serial and Batch":
if sre_doc.reservation_based_on == "Serial and Batch" and item.serial_and_batch_bundle:
sbb = frappe.get_doc("Serial and Batch Bundle", item.serial_and_batch_bundle)
if sre_doc.has_serial_no:
serial_nos_to_undelivered = [d.serial_no for d in sbb.entries]
Expand Down
2 changes: 2 additions & 0 deletions erpnext/selling/doctype/sales_order/test_sales_order.py
Original file line number Diff line number Diff line change
Expand Up @@ -2232,6 +2232,8 @@ def test_warehouse_mapping_based_on_stock_reservation(self):
si.submit()
sre_doc.reload()
self.assertTrue(sre_doc.status == "Delivered")
doc = frappe.get_doc("Stock Settings")
doc.db_set("enable_stock_reservation", 0)


def automatically_fetch_payment_terms(enable=1):
Expand Down

0 comments on commit 2d22301

Please sign in to comment.