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:
commit
630258f493
@ -575,7 +575,7 @@ class TestPurchaseReceipt(unittest.TestCase):
|
|||||||
|
|
||||||
se = make_stock_entry(item_code=item_code, target="_Test Warehouse - _TC", qty=1,
|
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)
|
serial_no=serial_no, basic_rate=100, do_not_submit=True)
|
||||||
self.assertRaises(SerialNoDuplicateError, se.submit)
|
se.submit()
|
||||||
|
|
||||||
dn.cancel()
|
dn.cancel()
|
||||||
pr1.cancel()
|
pr1.cancel()
|
||||||
|
|||||||
@ -6,7 +6,7 @@ import frappe
|
|||||||
import json
|
import json
|
||||||
|
|
||||||
from frappe.model.naming import make_autoname
|
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 erpnext.stock.get_item_details import get_reserved_qty_for_so
|
||||||
|
|
||||||
from frappe import _, ValidationError
|
from frappe import _, ValidationError
|
||||||
@ -241,7 +241,7 @@ def validate_serial_no(sle, item_det):
|
|||||||
for serial_no in serial_nos:
|
for serial_no in serial_nos:
|
||||||
if frappe.db.exists("Serial No", serial_no):
|
if frappe.db.exists("Serial No", serial_no):
|
||||||
sr = frappe.db.get_value("Serial No", serial_no, ["name", "item_code", "batch_no", "sales_order",
|
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)
|
"purchase_document_no", "company"], as_dict=1)
|
||||||
|
|
||||||
if sr.item_code!=sle.item_code:
|
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,
|
frappe.throw(_("Serial No {0} does not belong to Item {1}").format(serial_no,
|
||||||
sle.item_code), SerialNoItemError)
|
sle.item_code), SerialNoItemError)
|
||||||
|
|
||||||
if cint(sle.actual_qty) > 0 and has_duplicate_serial_no(sr, sle):
|
if cint(sle.actual_qty) > 0 and has_serial_no_exists(sr, sle):
|
||||||
frappe.throw(_("Serial No {0} has already been received").format(serial_no),
|
doc_name = frappe.bold(get_link_to_form(sr.purchase_document_type, sr.purchase_document_no))
|
||||||
SerialNoDuplicateError)
|
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']
|
if (sr.delivery_document_no and sle.voucher_type not in ['Stock Entry', 'Stock Reconciliation']
|
||||||
and sle.voucher_type == sr.delivery_document_type):
|
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""")
|
frappe.throw(_("""{0} Serial No {1} cannot be delivered""")
|
||||||
.format(msg, sr.name))
|
.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
|
if (sn.warehouse and not sle.skip_serial_no_validaiton
|
||||||
and sle.voucher_type != 'Stock Reconciliation'):
|
and sle.voucher_type != 'Stock Reconciliation'):
|
||||||
return True
|
return True
|
||||||
@ -358,12 +359,13 @@ def has_duplicate_serial_no(sn, sle):
|
|||||||
|
|
||||||
status = False
|
status = False
|
||||||
if sn.purchase_document_no:
|
if sn.purchase_document_no:
|
||||||
if sle.voucher_type in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"] and \
|
if (sle.voucher_type in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"] and
|
||||||
sn.delivery_document_type not in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"]:
|
sn.delivery_document_type not in ['Purchase Receipt', 'Stock Entry', "Purchase Invoice"]):
|
||||||
status = True
|
status = True
|
||||||
|
|
||||||
if status and sle.voucher_type == 'Stock Entry' and \
|
# If status is receipt then system will allow to in-ward the delivered serial no
|
||||||
frappe.db.get_value('Stock Entry', sle.voucher_no, 'purpose') != 'Material Receipt':
|
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
|
status = False
|
||||||
|
|
||||||
return status
|
return status
|
||||||
@ -419,7 +421,7 @@ def auto_make_serial_nos(args):
|
|||||||
if is_new:
|
if is_new:
|
||||||
created_numbers.append(sr.name)
|
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
|
# Setting up tranlated title field for all cases
|
||||||
singular_title = _("Serial Number Created")
|
singular_title = _("Serial Number Created")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user