mirror of
https://github.com/frappe/erpnext.git
synced 2026-02-18 17:15:04 +00:00
fix: add validation for existing Serial No Manufactured/Received again (#35534)
* feat: add new field `Allow existing Serial No` in `Stock Settings` * fix: add validation for existing Serial No to be Manufactured/Received again
This commit is contained in:
@@ -304,6 +304,9 @@ def validate_serial_no(sle, item_det):
|
||||
_("Duplicate Serial No entered for Item {0}").format(sle.item_code), SerialNoDuplicateError
|
||||
)
|
||||
|
||||
allow_existing_serial_no = cint(
|
||||
frappe.get_cached_value("Stock Settings", "None", "allow_existing_serial_no")
|
||||
)
|
||||
for serial_no in serial_nos:
|
||||
if frappe.db.exists("Serial No", serial_no):
|
||||
sr = frappe.db.get_value(
|
||||
@@ -332,6 +335,23 @@ def validate_serial_no(sle, item_det):
|
||||
SerialNoItemError,
|
||||
)
|
||||
|
||||
if not allow_existing_serial_no and sle.voucher_type in [
|
||||
"Stock Entry",
|
||||
"Purchase Receipt",
|
||||
"Purchase Invoice",
|
||||
]:
|
||||
msg = ""
|
||||
|
||||
if sle.voucher_type == "Stock Entry":
|
||||
se_purpose = frappe.db.get_value("Stock Entry", sle.voucher_no, "purpose")
|
||||
if se_purpose in ["Manufacture", "Material Receipt"]:
|
||||
msg = f"Cannot create a {sle.voucher_type} ({se_purpose}) for the Item {frappe.bold(sle.item_code)} with the existing Serial No {frappe.bold(serial_no)}."
|
||||
else:
|
||||
msg = f"Cannot create a {sle.voucher_type} for the Item {frappe.bold(sle.item_code)} with the existing Serial No {frappe.bold(serial_no)}."
|
||||
|
||||
if msg:
|
||||
frappe.throw(_(msg), SerialNoDuplicateError)
|
||||
|
||||
if cint(sle.actual_qty) > 0 and has_serial_no_exists(sr, sle):
|
||||
doc_name = frappe.bold(get_link_to_form(sr.purchase_document_type, sr.purchase_document_no))
|
||||
frappe.throw(
|
||||
|
||||
@@ -35,6 +35,7 @@
|
||||
"section_break_7",
|
||||
"automatically_set_serial_nos_based_on_fifo",
|
||||
"set_qty_in_transactions_based_on_serial_no_input",
|
||||
"allow_existing_serial_no",
|
||||
"column_break_10",
|
||||
"disable_serial_no_and_batch_selector",
|
||||
"use_naming_series",
|
||||
@@ -340,6 +341,12 @@
|
||||
{
|
||||
"fieldname": "column_break_121",
|
||||
"fieldtype": "Column Break"
|
||||
},
|
||||
{
|
||||
"default": "1",
|
||||
"fieldname": "allow_existing_serial_no",
|
||||
"fieldtype": "Check",
|
||||
"label": "Allow existing Serial No to be Manufactured/Received again"
|
||||
}
|
||||
],
|
||||
"icon": "icon-cog",
|
||||
@@ -347,7 +354,7 @@
|
||||
"index_web_pages_for_search": 1,
|
||||
"issingle": 1,
|
||||
"links": [],
|
||||
"modified": "2023-05-29 15:09:54.959411",
|
||||
"modified": "2023-05-31 14:15:14.145048",
|
||||
"modified_by": "Administrator",
|
||||
"module": "Stock",
|
||||
"name": "Stock Settings",
|
||||
|
||||
Reference in New Issue
Block a user