Skip to content

Commit 91199ea

Browse files
mihir-kandoimergify[bot]
authored andcommitted
fix: force user to enter batch or serial for serial/batch items
(cherry picked from commit 7170a1b)
1 parent e23ba0e commit 91199ea

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

erpnext/stock/doctype/stock_reconciliation/stock_reconciliation.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,6 +666,16 @@ def validate_item(self, item_code, row):
666666
validate_is_stock_item,
667667
)
668668

669+
def validate_serial_batch_items():
670+
has_batch_no, has_serial_no = frappe.get_value(
671+
"Item", item_code, ["has_batch_no", "has_serial_no"]
672+
)
673+
if row.use_serial_batch_fields:
674+
if has_batch_no and not row.batch_no:
675+
raise frappe.ValidationError(_("Please enter Batch No"))
676+
if has_serial_no and not row.serial_no:
677+
raise frappe.ValidationError(_("Please enter Serial No"))
678+
669679
# using try except to catch all validation msgs and display together
670680

671681
try:
@@ -674,12 +684,13 @@ def validate_item(self, item_code, row):
674684
# end of life and stock item
675685
validate_end_of_life(item_code, item.end_of_life, item.disabled)
676686
validate_is_stock_item(item_code, item.is_stock_item)
687+
validate_serial_batch_items()
677688

678689
# docstatus should be < 2
679690
validate_cancelled_item(item_code, item.docstatus)
680691

681692
except Exception as e:
682-
self.validation_messages.append(_("Row #") + " " + ("%d: " % (row.idx)) + cstr(e))
693+
self.validation_messages.append(_("Row #") + ("%d: " % (row.idx)) + cstr(e))
683694

684695
def validate_reserved_stock(self) -> None:
685696
"""Raises an exception if there is any reserved stock for the items in the Stock Reconciliation."""

0 commit comments

Comments
 (0)