Merge pull request #24164 from rohitwaghchaure/do-not-manufacture-same-serial-no-two-develop

fix: do not manufacture same serial no multiple times
This commit is contained in:
rohitwaghchaure 2020-12-24 17:46:26 +05:30 committed by GitHub
commit 630258f493
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 12 deletions

View File

@ -575,7 +575,7 @@ class TestPurchaseReceipt(unittest.TestCase):
se = make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1,
serial_no=serial_no, basic_rate=100, do_not_submit=True)
self.assertRaises(SerialNoDuplicateError, se.submit)
se.submit()
dn.cancel()
pr1.cancel()

View File

@ -6,7 +6,7 @@ import frappe
import json
from frappe.model.naming import make_autoname
from frappe.utils import cint, cstr, flt, add_days, nowdate, getdate
from frappe.utils import cint, cstr, flt, add_days, nowdate, getdate, get_link_to_form
from erpnext.stock.get_item_details import get_reserved_qty_for_so
from frappe import _, ValidationError
@ -241,7 +241,7 @@ def validate_serial_no(sle, item_det):
for serial_no in serial_nos:
if frappe.db.exists("Serial No", serial_no):
sr = frappe.db.get_value("Serial No", serial_no, ["name", "item_code", "batch_no", "sales_order",
"delivery_document_no", "delivery_document_type", "warehouse",
"delivery_document_no", "delivery_document_type", "warehouse", "purchase_document_type",
"purchase_document_no", "company"], as_dict=1)
if sr.item_code!=sle.item_code:
@ -249,9 +249,10 @@ def validate_serial_no(sle, item_det):
frappe.throw(_("Serial No {0} does not belong to Item {1}").format(serial_no,
sle.item_code), SerialNoItemError)
if cint(sle.actual_qty) > 0 and has_duplicate_serial_no(sr, sle):
frappe.throw(_("Serial No {0} has already been received").format(serial_no),
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(_("Serial No {0} has already been received in the {1} #{2}")
.format(frappe.bold(serial_no), sr.purchase_document_type, doc_name), SerialNoDuplicateError)
if (sr.delivery_document_no and sle.voucher_type not in ['Stock Entry', 'Stock Reconciliation']
and sle.voucher_type == sr.delivery_document_type):
@ -348,7 +349,7 @@ def validate_so_serial_no(sr, sales_order):
frappe.throw(_("""{0} Serial No {1} cannot be delivered""")
.format(msg, sr.name))
def has_duplicate_serial_no(sn, sle):
def has_serial_no_exists(sn, sle):
if (sn.warehouse and not sle.skip_serial_no_validaiton
and sle.voucher_type != 'Stock Reconciliation'):
return True
@ -358,12 +359,13 @@ def has_duplicate_serial_no(sn, sle):
status = False
if sn.purchase_document_no:
if sle.voucher_type in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"] and \
sn.delivery_document_type not in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"]:
if (sle.voucher_type in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"] and
sn.delivery_document_type not in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"]):
status = True
if status and sle.voucher_type == 'Stock Entry' and \
frappe.db.get_value('Stock Entry', sle.voucher_no, 'purpose') != 'Material Receipt':
# If status is receipt then system will allow to in-ward the delivered serial no
if (status and sle.voucher_type == "Stock Entry" and frappe.db.get_value("Stock Entry",
sle.voucher_no, "purpose") in ("Material Receipt", "Material Transfer")):
status = False
return status
@ -419,7 +421,7 @@ def auto_make_serial_nos(args):
if is_new:
created_numbers.append(sr.name)
form_links = list(map(lambda d: frappe.utils.get_link_to_form('Serial No', d), created_numbers))
form_links = list(map(lambda d: get_link_to_form('Serial No', d), created_numbers))
# Setting up tranlated title field for all cases
singular_title = _("Serial Number Created")