Merge pull request #51958 from mihir-kandoi/force-serial-batch-stock-reco

This commit is contained in:
Mihir Kandoi
2026-01-21 16:23:18 +05:30
committed by GitHub
2 changed files with 15 additions and 1 deletions

View File

@@ -665,6 +665,16 @@ class StockReconciliation(StockController):
validate_is_stock_item, validate_is_stock_item,
) )
def validate_serial_batch_items():
has_batch_no, has_serial_no = frappe.get_value(
"Item", item_code, ["has_batch_no", "has_serial_no"]
)
if row.use_serial_batch_fields and self.purpose == "Stock Reconciliation":
if has_batch_no and not row.batch_no:
raise frappe.ValidationError(_("Please enter Batch No"))
if has_serial_no and not row.serial_no:
raise frappe.ValidationError(_("Please enter Serial No"))
# using try except to catch all validation msgs and display together # using try except to catch all validation msgs and display together
try: try:
@@ -673,12 +683,13 @@ class StockReconciliation(StockController):
# end of life and stock item # end of life and stock item
validate_end_of_life(item_code, item.end_of_life, item.disabled) validate_end_of_life(item_code, item.end_of_life, item.disabled)
validate_is_stock_item(item_code, item.is_stock_item) validate_is_stock_item(item_code, item.is_stock_item)
validate_serial_batch_items()
# docstatus should be < 2 # docstatus should be < 2
validate_cancelled_item(item_code, item.docstatus) validate_cancelled_item(item_code, item.docstatus)
except Exception as e: except Exception as e:
self.validation_messages.append(_("Row #") + " " + ("%d: " % (row.idx)) + cstr(e)) self.validation_messages.append(_("Row #") + ("%d: " % (row.idx)) + cstr(e))
def validate_reserved_stock(self) -> None: def validate_reserved_stock(self) -> None:
"""Raises an exception if there is any reserved stock for the items in the Stock Reconciliation.""" """Raises an exception if there is any reserved stock for the items in the Stock Reconciliation."""

View File

@@ -1449,6 +1449,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin):
qty=10, qty=10,
rate=100, rate=100,
use_serial_batch_fields=1, use_serial_batch_fields=1,
purpose="Opening Stock",
) )
sr.reload() sr.reload()
@@ -1591,6 +1592,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin):
qty=10, qty=10,
rate=80, rate=80,
use_serial_batch_fields=1, use_serial_batch_fields=1,
purpose="Opening Stock",
) )
batch_no = get_batch_from_bundle(reco.items[0].serial_and_batch_bundle) batch_no = get_batch_from_bundle(reco.items[0].serial_and_batch_bundle)
@@ -1675,6 +1677,7 @@ class TestStockReconciliation(IntegrationTestCase, StockTestMixin):
qty=10, qty=10,
rate=100, rate=100,
use_serial_batch_fields=1, use_serial_batch_fields=1,
purpose="Opening Stock",
) )
sr.reload() sr.reload()