Skip to content

Commit 8092d58

Browse files
fix: do not validate qc for scrap item (backport frappe#44844) (frappe#44853)
fix: do not validate qc for scrap item (frappe#44844) (cherry picked from commit a2c2b8b) Co-authored-by: rohitwaghchaure <[email protected]>
1 parent 3f3df7e commit 8092d58

File tree

2 files changed

+77
-0
lines changed

2 files changed

+77
-0
lines changed

erpnext/controllers/stock_controller.py

+3
Original file line numberDiff line numberDiff line change
@@ -999,6 +999,9 @@ def validate_inspection(self):
999999
elif self.doctype == "Stock Entry" and row.t_warehouse:
10001000
qi_required = True # inward stock needs inspection
10011001

1002+
if row.get("is_scrap_item"):
1003+
continue
1004+
10021005
if qi_required: # validate row only if inspection is required on item level
10031006
self.validate_qi_presence(row)
10041007
if self.docstatus == 1:

erpnext/stock/doctype/stock_entry/test_stock_entry.py

+74
Original file line numberDiff line numberDiff line change
@@ -970,6 +970,80 @@ def test_nagative_stock_for_batch(self):
970970

971971
self.assertRaises(frappe.ValidationError, ste.submit)
972972

973+
def test_quality_check_for_scrap_item(self):
974+
from erpnext.manufacturing.doctype.work_order.work_order import (
975+
make_stock_entry as _make_stock_entry,
976+
)
977+
978+
scrap_item = "_Test Scrap Item 1"
979+
make_item(scrap_item, {"is_stock_item": 1, "is_purchase_item": 0})
980+
981+
bom_name = frappe.db.get_value("BOM Scrap Item", {"docstatus": 1}, "parent")
982+
production_item = frappe.db.get_value("BOM", bom_name, "item")
983+
984+
work_order = frappe.new_doc("Work Order")
985+
work_order.production_item = production_item
986+
work_order.update(
987+
{
988+
"company": "_Test Company",
989+
"fg_warehouse": "_Test Warehouse 1 - _TC",
990+
"production_item": production_item,
991+
"bom_no": bom_name,
992+
"qty": 1.0,
993+
"stock_uom": frappe.db.get_value("Item", production_item, "stock_uom"),
994+
"skip_transfer": 1,
995+
}
996+
)
997+
998+
work_order.get_items_and_operations_from_bom()
999+
work_order.submit()
1000+
1001+
stock_entry = frappe.get_doc(_make_stock_entry(work_order.name, "Manufacture", 1))
1002+
for row in stock_entry.items:
1003+
if row.s_warehouse:
1004+
make_stock_entry(
1005+
item_code=row.item_code,
1006+
target=row.s_warehouse,
1007+
qty=row.qty,
1008+
basic_rate=row.basic_rate or 100,
1009+
)
1010+
1011+
if row.is_scrap_item:
1012+
row.item_code = scrap_item
1013+
row.uom = frappe.db.get_value("Item", scrap_item, "stock_uom")
1014+
row.stock_uom = frappe.db.get_value("Item", scrap_item, "stock_uom")
1015+
1016+
stock_entry.inspection_required = 1
1017+
stock_entry.save()
1018+
1019+
self.assertTrue([row.item_code for row in stock_entry.items if row.is_scrap_item])
1020+
1021+
for row in stock_entry.items:
1022+
if not row.is_scrap_item:
1023+
qc = frappe.get_doc(
1024+
{
1025+
"doctype": "Quality Inspection",
1026+
"reference_name": stock_entry.name,
1027+
"inspected_by": "Administrator",
1028+
"reference_type": "Stock Entry",
1029+
"inspection_type": "In Process",
1030+
"status": "Accepted",
1031+
"sample_size": 1,
1032+
"item_code": row.item_code,
1033+
}
1034+
)
1035+
1036+
qc_name = qc.submit()
1037+
row.quality_inspection = qc_name
1038+
1039+
stock_entry.reload()
1040+
stock_entry.submit()
1041+
for row in stock_entry.items:
1042+
if row.is_scrap_item:
1043+
self.assertFalse(row.quality_inspection)
1044+
else:
1045+
self.assertTrue(row.quality_inspection)
1046+
9731047
def test_quality_check(self):
9741048
item_code = "_Test Item For QC"
9751049
if not frappe.db.exists("Item", item_code):

0 commit comments

Comments
 (0)